LCOV - code coverage report
Current view: top level - lib/src/particles - accelerated_particle.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 14 0.0 %
Date: 2021-08-10 15:50:53 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:ui';
       2             : 
       3             : import '../../extensions.dart';
       4             : import '../components/mixins/single_child_particle.dart';
       5             : import 'curved_particle.dart';
       6             : import 'particle.dart';
       7             : 
       8             : /// A particle that serves as a container for basic acceleration physics.
       9             : ///
      10             : /// [speed] is logical px per second.
      11             : ///
      12             : /// ```dart
      13             : /// AcceleratedParticle(
      14             : ///   speed: Vector2(0, 100), // is 100 logical px/s down.
      15             : ///   acceleration: Vector2(-40, 0) // will accelerate to the left at rate of 40 px/s
      16             : /// )
      17             : /// ```
      18             : class AcceleratedParticle extends CurvedParticle with SingleChildParticle {
      19             :   @override
      20             :   Particle child;
      21             : 
      22             :   final Vector2 acceleration;
      23             :   Vector2 speed;
      24             :   Vector2 position;
      25             : 
      26           0 :   AcceleratedParticle({
      27             :     required this.child,
      28             :     Vector2? acceleration,
      29             :     Vector2? speed,
      30             :     Vector2? position,
      31             :     double? lifespan,
      32           0 :   })  : acceleration = acceleration ?? Vector2.zero(),
      33           0 :         position = position ?? Vector2.zero(),
      34           0 :         speed = speed ?? Vector2.zero(),
      35           0 :         super(lifespan: lifespan);
      36             : 
      37           0 :   @override
      38             :   void render(Canvas canvas) {
      39           0 :     canvas.save();
      40           0 :     canvas.translateVector(position);
      41           0 :     super.render(canvas);
      42           0 :     canvas.restore();
      43             :   }
      44             : 
      45           0 :   @override
      46             :   void update(double dt) {
      47           0 :     speed += acceleration * dt;
      48           0 :     position += speed * dt - (acceleration * dt * dt) / 2;
      49           0 :     super.update(dt);
      50             :   }
      51             : }

Generated by: LCOV version 1.15