basket_ball_game
A customizable basketball shooting game widget built with the Flame engine. Drop a full 3-minute basketball arcade game anywhere in your Flutter app with a single widget.
Features
- Swipe to aim and shoot with a trajectory preview
- Animated power bar — hold longer for more speed
- Animated player character with arm follow and throw animation
- Customizable game duration and play limits
- Score counter with popup feedback on each basket
- Callbacks for score changes and game over events
- Fully self-contained — no setup beyond adding the dependency
Installation
Add to your pubspec.yaml:
dependencies:
basket_ball_game: ^1.0.2
Usage
import 'package:basket_ball_game/basket_ball_game.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
runApp(const MaterialApp(
home: Scaffold(
body: SafeArea(
child: BasketballGameWidget(
gameDuration: 180, // Duration in seconds
maxPlays: 3, // Number of balls/plays allowed
onScoreChanged: (score) {
print('Current score: $score');
},
onGameOver: (finalScore) {
print('Game Over! Final score: $finalScore');
},
),
),
),
));
}
The widget fills all available space. Wrap it in a SizedBox or Expanded to constrain it.
How to play
- Swipe up from the bottom half of the screen to start aiming.
- Drag left/right to steer the shot direction.
- Release to shoot — the longer you hold, the more power.
- Score as many baskets as you can before the timer runs out or you use all plays.
License
MIT — see LICENSE.
Libraries
- basket_ball_game
- A customizable basketball shooting game widget built with Flame.
- basketball_game
- basketball_game_widget
- components/aim_indicator
- components/ball_component
- components/floor_component
- components/hoop_component
- components/hud_component
- components/player_component
- components/power_bar_component
- components/score_popup_component
- main
- overlays/game_over_overlay