Coffee & Code: Building Mario Power-Ups and Debugging Hitboxes in Flutter

Coffee & Code: Building Mario Power-Ups and Debugging Hitboxes in Flutter

Back to my Super Mario Bros. Flutter game, tackling Mario's power-up transformation and the hitbox sizing challenges that come with it.


Sample Image
Cappuccino from Mercantile Coffee & Feed in Houston, TX.

Back on the Super Mario Bros. game to add some new, much needed features.

This time around, I am focused on giving Mario the ability to power up. If you are not familiar with the game, once the super hero digests a magic mushroom, he either become Super Mario, or Fire Mario, with greater power potential.

Sample Image
Video Demo

I’m running into bit of a problem with the transformation however.

Sample Image
ChatGPT results for Hitboxes.

Currently, the boundary box, or hitbox that surrounds Mario isn’t representative of his actual dimensions.

Sample Image
Flame documentation on Hitboxes.
/// Current power types for Mario.
enum MarioType {
  mario,
  superMario,
}

This means the hitbox can’t properly detect Mario’s collisions with the ground when he’s of a greater size.

/// Update form type and size of Mario.
void _transform({required bool upgrade}) {
  if (upgrade) {
    switch (_marioType) {
      case MarioType.mario:
        size = Vector2 (Globals.tileSize, Globals.tileSize * 2);
        _marioType = MarioType.superMario;
        break;
      case MarioType.superMario:
        // TODO: Transform to fiery mario.
        break;
    }
  } else {
    switch (_marioType) {
      case MarioType.mario:
        // TODO: Die.
        break;
      case MarioType.superMario:
        size = Vector2(Globals.tileSize, Globals.tileSize);
        _marioType = MarioType.mario;
        break;
    }
  }
}

Some serious research is required…


Related posts
Coffee & Code — Fixing Collision Detection in Super Mario Bros Flutter

Coffee & Code — Fixing Collision Detection in Super Mario Bros Flutter

Read more
Coffee & Code - Crafting Mario-style Game Blocks with OOP

Coffee & Code - Crafting Mario-style Game Blocks with OOP

Read more
Coffee & Code - Building Mario Animations with Flutter and Flame Engine

Coffee & Code - Building Mario Animations with Flutter and Flame Engine

Read more
Coffee & Code - Gift Grab Power-Ups & App Store Improvements

Coffee & Code - Gift Grab Power-Ups & App Store Improvements

Read more