From ecfc3032704baeec70551bb366c6ee02f5cf828c Mon Sep 17 00:00:00 2001 From: Viktor Lidholt Date: Tue, 16 Feb 2016 18:25:04 -0800 Subject: [PATCH 1/2] Correctly calculates gravity in particle systems --- packages/flutter_sprites/lib/src/particle_system.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter_sprites/lib/src/particle_system.dart b/packages/flutter_sprites/lib/src/particle_system.dart index ee40e7f065f..3b8fb40aac3 100644 --- a/packages/flutter_sprites/lib/src/particle_system.dart +++ b/packages/flutter_sprites/lib/src/particle_system.dart @@ -252,7 +252,7 @@ class ParticleSystem extends Node { particle.dir += accel; } else if (gravity[0] != 0.0 || gravity[1] != 0) { // gravity - Vector2 accel = gravity.scale(dt); + Vector2 accel = new Vector2.copy(gravity).scale(dt); particle.dir += accel; } From 9576ce4399ac03f16d8e6f22743cdd5214a8d4b3 Mon Sep 17 00:00:00 2001 From: Viktor Lidholt Date: Tue, 16 Feb 2016 18:25:48 -0800 Subject: [PATCH 2/2] Adds dialog for completed exercise in Fitness demo --- .../lib/demo/fitness_demo.dart | 87 +++++++++++++++++++ examples/material_gallery/pubspec.yaml | 2 +- 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/examples/material_gallery/lib/demo/fitness_demo.dart b/examples/material_gallery/lib/demo/fitness_demo.dart index e2e12ecfeaf..d34f4c3e7af 100644 --- a/examples/material_gallery/lib/demo/fitness_demo.dart +++ b/examples/material_gallery/lib/demo/fitness_demo.dart @@ -8,6 +8,7 @@ import 'dart:ui' as ui; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_sprites/flutter_sprites.dart'; +import 'package:vector_math/vector_math_64.dart' as vec; ImageMap _images; SpriteSheet _sprites; @@ -173,6 +174,25 @@ class _FitnessDemoContentsState extends State<_FitnessDemoContents> { void endWorkout() { setState(() { workoutAnimation.stop(); + + if (count >= 3) { + showDialog( + context: context, + child: new Stack(children: [ + new _Fireworks(), + new Dialog( + title: new Text("Awesome workout"), + content: new Text("You have completed $count jumping jacks. Good going!"), + actions: [ + new FlatButton( + child: new Text("SWEET"), + onPressed: () { Navigator.pop(context); } + ) + ] + ) + ]) + ); + } }); } } @@ -489,3 +509,70 @@ class _JumpingJackPart extends Sprite { } } } + +class _Fireworks extends StatefulComponent { + _Fireworks({ Key key }) : super(key: key); + + _FireworksState createState() => new _FireworksState(); +} + +class _FireworksState extends State<_Fireworks> { + void initState() { + super.initState(); + fireworks = new _FireworksNode(); + } + + _FireworksNode fireworks; + + Widget build(BuildContext context) { + return new SpriteWidget(fireworks); + } +} + +class _FireworksNode extends NodeWithSize { + _FireworksNode() : super(const Size(1024.0, 1024.0)); + double _countDown = 0.0; + + void update(double dt) { + if (_countDown <= 0.0) { + _addExplosion(); + _countDown = randomDouble(); + } + + _countDown -= dt; + } + + Color _randomExplosionColor() { + double rand = randomDouble(); + if (rand < 0.25) + return Colors.pink[200]; + else if (rand < 0.5) + return Colors.lightBlue[200]; + else if (rand < 0.75) + return Colors.purple[200]; + else + return Colors.cyan[200]; + } + + void _addExplosion() { + Color startColor = _randomExplosionColor(); + Color endColor = startColor.withAlpha(0); + + ParticleSystem system = new ParticleSystem( + _sprites['particle-0.png'], + numParticlesToEmit: 100, + emissionRate: 1000.0, + rotateToMovement: true, + startRotation: 90.0, + endRotation: 90.0, + speed: 100.0, + speedVar: 50.0, + startSize: 1.0, + startSizeVar: 0.5, + gravity: new vec.Vector2(0.0, 30.0), + colorSequence: new ColorSequence.fromStartAndEndColor(startColor, endColor) + ); + system.position = new Point(randomDouble() * 1024.0, randomDouble() * 1024.0); + addChild(system); + } +} diff --git a/examples/material_gallery/pubspec.yaml b/examples/material_gallery/pubspec.yaml index 00bf3f72eb2..7928aa25ca2 100644 --- a/examples/material_gallery/pubspec.yaml +++ b/examples/material_gallery/pubspec.yaml @@ -6,4 +6,4 @@ dependencies: path: ../../packages/flutter flutter_sprites: path: ../../packages/flutter_sprites - flutter_gallery_assets: '0.0.7' + flutter_gallery_assets: '0.0.9'