Your First Flutter Flame Game

Mar 6 2024 · Dart 3, Flutter 3.10.1, Android Studio 2021.3.1 or higher, Visual Studo Code 1.7.4 or higher

Part 3: Collision Detection & Overlays

15. Attack Saucers

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 14. Understand Collision Between Components Next episode: 16. Break Down Meteorites

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Let’s summarize what you learned in the last lesson:

Demo

Now, let’s see it in action one more time by adding collisions to Saucer.

Saucer

Let’s start by adding some collisions to Saucer.

with CollisionCallbacks, HasGameRef<MeteormaniaGame> {
add(RectangleHitbox());
@override
void onCollision(Set<Vector2> intersectionPoints, PositionComponent other) {
  if (other is Bullet) {
    removeFromParent();
  }
  super.onCollision(intersectionPoints, other);
}

Bullet

Now it’s time to do the same thing for Bullet.

with CollisionCallbacks, HasGameRef<MeteormaniaGame> {
add(RectangleHitbox());
@override
void onCollision(Set<Vector2> intersectionPoints, PositionComponent other) {
  if (other is Saucer) {
    
  }

  super.onCollision(intersectionPoints, other);
}
game.bonusEnemyHit();
removeFromParent();

MeteormaniaGame

It’s time to implement bonusEnemyHit function. Create a new function with the corresponding name.

void bonusEnemyHit() {
}
FlameAudio.play('sfx/explosion.mp3');
manager.addPoints(5);