Skip to content

Commit

Permalink
Game over logic added
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahSomething committed Dec 24, 2023
1 parent e2a0296 commit 4c65939
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/my_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,7 +60,7 @@ class MyGame extends FlameGame with TapCallbacks, HasCollisionDetection {
super.onTapDown(event);
}

generateCircleComponent() {
void _generateCircleComponent() {
world.add(
RotatingCircle(
position: Vector2(0, 0),
Expand All @@ -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();
}
}
1 change: 1 addition & 0 deletions lib/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4c65939

Please sign in to comment.