Flutter Casual Games Toolkit

repository·main·Indexed 21 days ago

https://github.com/flutter/games

Official code for the Flutter Casual Games Toolkit, featuring gaming templates and samples. It provides structured starting points for building various game types, including 2D platformers, card games, and endless runners. The repository includes a `sample_downloader` tool for easy project access and demonstrates specific functionalities such as ads integration and multiplayer capabilities using Firebase Cloud Firestore.

Tokens
14.6K
Snippets
53
Records
68
Agent score
72%

What's inside flutter-games

  1. Understand the repository organization

    main

    The flutter/games repository is organized into two main categories to help you find the right starting point for your project:

    1. Templates: Simple starting points providing a project structure for different game types (e.g., basic, card, or endless_runner). These are designed to be built upon.
    2. Samples: More advanced projects intended to demonstrate specific functionalities like ads integration or multiplayer capabilities.

    Directory Structure

    .
    ├── templates
    │   ├── basic
    │   ├── card
    │   └── endless_runner
    └── samples
        ├── ads
        ├── multiplayer
        └── ...
  2. Manage game settings and persistence

    main
    The settings page is accessible from the main menu and via a gear button in the play session. Settings are persisted locally using the shared_preferences package. To modify which preferences are saved or how they are handled, edit the files in lib/settings/persistence.
  3. Understand the code organization

    main

    The project uses a feature-first organization. Core gameplay logic should be implemented in lib/play_session/.

    Key directories include:

    • lib/audio/: Audio management logic.
    • lib/main_menu/: Main menu screens.
    • lib/settings/: Settings and persistence.
    • lib/style/: Theming and styling.
    • lib/game_internals/: Core game mechanics.

    State management is intentionally low-level to avoid dependencies on code generation (like build_runner), but you are encouraged to replace it with your preferred paradigm.

  4. Code organization in the template

    main

    The project uses a loose, shallow, feature-first directory structure in lib/. Core gameplay logic is located in lib/flame_game/. Other features are organized by name (e.g., audio, main_menu, settings). State management is intentionally low-level to avoid dependencies on code generation like build_runner during initial development.

    lib
    ├── app_lifecycle
    ├── audio
    ├── flame_game
    ├── level_selection
    ├── main_menu
    ├── player_progress
    ├── settings
    ├── style
    └── main.dart
    └── router.dart
  5. Build the game for production

    main

    The template supports building for iOS, Android, Web, and Desktop.

    • iOS: Builds an IPA and opens the archive in Xcode.
    • Android: Builds an app bundle and opens the release folder.
    • Web: Requires the peanut package. It builds using the canvaskit renderer and can be configured to push directly to GitHub Pages.
    • Desktop: Follow standard Flutter platform integration instructions for Windows, Linux, or macOS.
    # iOS
    flutter build ipa && open build/ios/archive/Runner.xcarchive
    
    # Android
    flutter build appbundle && open build/app/outputs/bundle/release
    
    # Web (requires peanut package)
    flutter pub global run peanut \
    --web-renderer canvaskit \
    --extra-args "--base-href=/name_of_your_github_repo/" \
    && git push origin --set-upstream gh-pages
  6. Install and use the sample_downloader tool

    main

    The easiest way to access templates and samples is by using the sample_downloader tool. This tool allows you to download specific projects from this repository without cloning the entire repository manually.

    Prerequisites

    Installation Steps

    1. Activate the tool globally using Dart:
      dart pub global activate sample_downloader
    2. Run the tool from any directory and follow the interactive instructions:
      sample_downloader
    dart pub global activate sample_downloader
    sample_downloader
  7. Install the Card game template

    main
    You can obtain this sample by cloning the full repository or by using the sample_downloader tool. To use the downloader, ensure the Flutter SDK is installed, then activate the tool via dart pub global activate sample_downloader and run sample_downloader from any directory.
    dart pub global activate sample_downloader
    sample_downloader
  8. Update the app launcher icon

    main

    To change the icon, update assets/icon-adaptive-foreground.png and assets/icon.png. Then, run the flutter_launcher_icons tool. You can further configure the icon appearance in the flutter_icons: section of your pubspec.yaml.

    dart run flutter_launcher_icons:main
  9. Download the Endless Runner Template

    main
    You can download the template by cloning the repository or by using the sample_downloader command-line tool. To use the tool, first activate it globally via dart pub global activate sample_downloader, then run sample_downloader from any directory and follow the prompts.
    dart pub global activate sample_downloader
    sample_downloader