A Breakout game implementation built with Flutter and Flame. Breakout is a classic arcade game where players control a paddle to bounce a ball and break bricks at the top of the screen. This project leverages the power of Flutter for cross-platform development and the Flame game engine for smooth 2D game mechanics.
- Classic Breakout gameplay mechanics
- Built with Flutter for cross-platform support (iOS, Android, Web, Desktop)
- Powered by Flame game engine for efficient 2D rendering
- Responsive paddle controls
- Brick-breaking physics
A simple Breakout-style game built with Flutter and the Flame game engine.
This repository is a small game project used as a learning/demo app and a thin game framework for experimenting with Flame's component model and Flutter overlays.
- Flutter + Flame game engine
- Fixed virtual resolution (camera) for predictable layout across devices
ValueNotifier-driven score UI with Flutter overlays for start/win/lose
Prerequisites: Flutter SDK (see https://docs.flutter.dev/get-started/install).
Run locally:
flutter pub get
flutter run -d <device>Build (examples):
flutter build apk --release # Android
flutter build ios # iOS (requires macOS + Xcode)Useful checks:
flutter analyze
flutter test # no tests yet; add under /test- Entry:
lib/main.dart— instantiatesGameApp. - App shell & overlays:
lib/src/widgets/game_app.dart— wraps aGameWidgetand wiresoverlayBuilderMapkeyed byPlayState.name(seelib/src/brick_breaker.dart). - Game core:
lib/src/brick_breaker.dart—class BrickBreaker extends FlameGame.- Manages game state via
PlayStateenum, spawns/removes components, and exposesValueNotifier<int> scoreused by the UI.
- Manages game state via
- Config/constants:
lib/src/config.dart— centralized sizes, colors, and tuning constants (e.g.gameWidth,gameHeight,brickColors,difficultyModifier). - Components:
lib/src/components/(exports inlib/src/components/components.dart) —Ball,Bat,Brick,PlayArea. - Widgets:
lib/src/widgets/— UI overlays (overlay_screen.dart) andScoreCard(score_card.dart) which listens toBrickBreaker.score.
Design notes:
- The game uses a fixed-resolution
CameraComponent.withFixedResolution(...)so the entire game layout is expressed in the virtual coordinates defined inconfig.dart. When adding visuals or collision sizes, prefer those constants to keep the layout consistent across devices. - Components are added/removed using
world.add(...)andworld.removeAll(world.children.query<T>()). - Overlays are toggled by setting
brickBreaker.playState = PlayState.<state>— the enum names are used directly as overlay keys inGameWidget.overlayBuilderMap.
-
Add a new game component:
- Create
lib/src/components/<your_component>.dart. - Export it from
lib/src/components/components.dart. - Spawn it from
BrickBreaker(e.g., inonLoad()orstartGame()):world.add(YourComponent(...));
- Create
-
Add a new overlay screen:
- Create a widget under
lib/src/widgets/(e.g.my_overlay.dart). - Add it to
overlayBuilderMapinGameWidgetinsidelib/src/widgets/game_app.dartusingPlayState.<yourState>.nameas the key. - Toggle via
game.playState = PlayState.<yourState>.
- Create a widget under
-
Update score UI:
BrickBreaker.scoreis aValueNotifier<int>; mutate withscore.value++and theScoreCard(ValueListenableBuilder) will update automatically.
There are no unit tests right now. Recommended minimal steps when adding tests:
- Put tests in
/testand use the standard Flutter test harness. - Run
flutter testlocally and add a CI job that runsflutter analyzeandflutter test.
- Key packages (see
pubspec.yaml):flame,flutter_animate,google_fonts. - Linting:
flutter_lints(configured viaanalysis_options.yaml). Runflutter analyzeand follow the project's lints.
Conventions discovered in the codebase:
- Keep layout and game tuning in
lib/src/config.dart. - Use
world.children.query<T>()to find/remove components rather than storing direct lists of spawned objects. - Use enum
PlayStatenames as overlay keys. Avoid string literals for overlay keys.
lib/
main.dart # App entry
src/
brick_breaker.dart # FlameGame subclass — main game logic
config.dart # Constants and layout/tuning values
components/
ball.dart
bat.dart
brick.dart
play_area.dart
components.dart # re-exports
widgets/
game_app.dart # Material app + GameWidget + overlays
overlay_screen.dart
score_card.dart
- If you'd like, I can:
- add a minimal
/testexample and runflutter test; - add a GitHub Actions workflow to run
flutter analyzeandflutter teston PRs; - provide a short code example that adds a custom component and wires an overlay.
- add a minimal
Please tell me which of those you'd like next, or any content you'd like added to this README.