diff --git a/lib/my_game.dart b/lib/my_game.dart index 4ffbe5e..64fad01 100644 --- a/lib/my_game.dart +++ b/lib/my_game.dart @@ -30,14 +30,17 @@ class MyGame extends FlameGame with TapCallbacks, HasCollisionDetection { @override void onMount() { //debugMode = true; + _initializeGame(); + super.onMount(); + } + + _initializeGame() { player = Player(position: Vector2(0, 250)); - //camera.follow(player); ground = Ground(position: Vector2(0, 400)); world.add(ground); world.add(player); - generateCircleComponent(); - - super.onMount(); + camera.moveTo(Vector2.zero()); + _generateCircleComponent(); } @override @@ -57,7 +60,7 @@ class MyGame extends FlameGame with TapCallbacks, HasCollisionDetection { super.onTapDown(event); } - generateCircleComponent() { + void _generateCircleComponent() { world.add( RotatingCircle( position: Vector2(0, 0), @@ -67,4 +70,11 @@ class MyGame extends FlameGame with TapCallbacks, HasCollisionDetection { final colorSwitcher = ColorSwitcher(position: Vector2(0, 200)); world.add(colorSwitcher); } + + void gameOver() { + for (var component in world.children) { + component.removeFromParent(); + } + _initializeGame(); + } } diff --git a/lib/player.dart b/lib/player.dart index bce5c8a..fd02d4d 100644 --- a/lib/player.dart +++ b/lib/player.dart @@ -28,6 +28,7 @@ class Player extends PositionComponent } else if (other is CircleArc) { if (other.color != _color) { debugPrint("Game Over"); + gameRef.gameOver(); } } super.onCollision(intersectionPoints, other);