Skip to content

ibrahimtech24/Game_car

Repository files navigation

🏎️ Flutter Car Racing GameBuilding a Car Race Game with Flutter and Flame [Part 1]

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:

https://medium.com/@amitsingh506142/building-a-car-race-game-with-flutter-and-flame-part-1-f68e9e779b09

🎮 Game Features

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.

🚀 Getting Started

Game Structure and Game Loop:

Prerequisites

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:

Installation

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.

  1. 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
  1. Run the game:
flutter run

For web specifically:

flutter run -d chrome

🎯 How to Play

  1. Start Game: Click "Play" on the main menu
  2. Movement: Use arrow keys (←/→) to move your car left and right
  3. Objective: Avoid colliding with enemy cars and obstacles
  4. Scoring: Your score increases as you survive longer
  5. Game Over: Collision ends the game - try to beat your high score!

🛠️ Built With

  • Flutter - UI framework
  • Flame - 2D game engine for Flutter
  • Google Fonts - Custom typography
  • Flame Audio - Sound effects and music

📁 Project Structure

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

🎨 Assets

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

🔧 Development

Adding New Features

  1. New Car Models: Add sprites to assets/images/game/ and update the character enum
  2. Sound Effects: Add audio files to assets/audio/ and implement in game logic
  3. New Obstacles: Create new sprite components following the existing pattern
  4. Game Modes: Extend the GameState enum and implement new game logic

Building for Production

Web:

flutter build web

Android:

flutter build apk

Windows:

flutter build windows

🐛 Known Issues

  • Camera following system disabled in newer Flame versions (functionality preserved)
  • Some deprecated warnings in web build (functional, will be updated in future versions)

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Flame community for excellent documentation and examples
  • Flutter team for the amazing framework
  • All contributors and testers

🎮 Play Online

Play the game here! (Update with your deployment URL)


Developed with ❤️ using Flutter & Flame

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published