A thrilling 2D car racing game built with Flutter and Flame engine. Navigate through traffic, avoid obstacles, and achieve the highest score!Detail Medium article:
Want to play game?:
-
Responsive Controls: Use arrow keys to move left and right
-
Dynamic Obstacles: Randomly generated enemy cars and obstacleshttps://carerace-1d32c.web.app/#/
-
Score System: Track your performance with an integrated scoring system
-
Multiple Car Models: Choose from various car sprites (Tesla, BMW, Ferrari, Lamborghini, etc.)Introduction:
-
Parallax Background: Smooth scrolling road background for immersive gameplay
-
Cross-Platform: Runs on Web, Android, iOS, Windows, macOS, and LinuxFlame is like a secret weapon for creating games in Flutter. It's a game engine built specifically for Flutter apps, and it simplifies the process of building 2D games. With Flame, you can easily handle game loops, rendering graphics, and handling user input. It's like having a cheat code that makes game development in Flutter faster and more fun.
Game Structure and Game Loop:
Game Structure:
-
Flutter SDK (>=3.0.1)
-
Dart SDK (>=3.0.1)Think of a game as a well-organized party. Just like a party has different elements such as guests, decorations, and activities, a game also has its own components. In a game, you have things like characters, objects, backgrounds, and rules that define how the game works. These components work together to create an enjoyable experience for the players.
-
A code editor (VS Code, Android Studio, etc.)
Game Loop:
The game loop is like the heartbeat of a game. It's a continuous process that keeps everything in the game running smoothly. Imagine you're playing a game where you control a car. The game loop ensures that the car keeps moving, the obstacles keep coming, and everything happens in sync.
- Clone the repository:
git clone https://github.com/yourusername/flutter-car-racing-game.git**LinkeDin:** https://www.linkedin.com/in/amit-singh-023055193
cd flutter-car-racing-game**StackOverflow:** https://stackoverflow.com/users/13051247/amit-singh
```**Github:** https://github.com/amitsingh6391
2. Install dependencies:
```bash
flutter pub get- Run the game:
flutter runFor web specifically:
flutter run -d chrome- Start Game: Click "Play" on the main menu
- Movement: Use arrow keys (←/→) to move your car left and right
- Objective: Avoid colliding with enemy cars and obstacles
- Scoring: Your score increases as you survive longer
- Game Over: Collision ends the game - try to beat your high score!
- Flutter - UI framework
- Flame - 2D game engine for Flutter
- Google Fonts - Custom typography
- Flame Audio - Sound effects and music
lib/
├── game/
│ ├── background.dart # Parallax scrolling background
│ ├── car_race.dart # Main game class
│ ├── managers/
│ │ ├── game_manager.dart # Game state management
│ │ └── object_manager.dart # Enemy spawn management
│ ├── sprites/
│ │ ├── player.dart # Player car logic
│ │ └── competitor.dart # Enemy car logic
│ ├── utils/
│ │ └── color_theme.dart # Game color scheme
│ └── widgets/
│ ├── game_over_overlay.dart
│ ├── main_menu_overlay.dart
│ └── score_display.dart
├── main.dart # App entry point
└── assets/
├── images/game/ # Car and road sprites
└── audio/ # Sound effects
The game includes various car models and road textures:
- Player Cars: Tesla, BMW, Ferrari, Lamborghini, Tata, Tarzen
- Enemy Cars: Multiple enemy car designs
- Backgrounds: Road textures and patterns
- Audio: Engine sounds and game effects
- New Car Models: Add sprites to
assets/images/game/and update the character enum - Sound Effects: Add audio files to
assets/audio/and implement in game logic - New Obstacles: Create new sprite components following the existing pattern
- Game Modes: Extend the GameState enum and implement new game logic
Web:
flutter build webAndroid:
flutter build apkWindows:
flutter build windows- Camera following system disabled in newer Flame versions (functionality preserved)
- Some deprecated warnings in web build (functional, will be updated in future versions)
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Flame community for excellent documentation and examples
- Flutter team for the amazing framework
- All contributors and testers
Play the game here! (Update with your deployment URL)
Developed with ❤️ using Flutter & Flame