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

  1. Swipe up from the bottom half of the screen to start aiming.
  2. Drag left/right to steer the shot direction.
  3. Release to shoot — the longer you hold, the more power.
  4. Score as many baskets as you can before the timer runs out or you use all plays.

License

MIT — see LICENSE.