A simple 2D arcade-style game built with C# and Windows Forms where you control a car, dodge falling obstacles, and rack up points for as long as you can survive.
- Steer your car left and right across the road to avoid oncoming obstacles falling from the top of the screen.
- Every obstacle you dodge adds to your score, and points also tick up automatically the longer you survive.
- Colliding with an obstacle costs you health. Lose all your health and it's game over.
- The game gets progressively harder over time — obstacles spawn more frequently as your score climbs.
| Action | Input |
|---|---|
| Move left | ← Left Arrow key, or Left button |
| Move right | → Right Arrow key, or Right button |
| Start / Restart | Start button |
- Game loop: A
Timerticks every 40ms (~25 FPS), updating obstacle positions, checking collisions, and repainting the game area. - Difficulty scaling: Every 200 points, the interval between obstacle spawns decreases (down to a minimum), making the game faster and harder.
- Scoring: 1 point per game tick, plus a bonus for every obstacle successfully avoided.
- Health: Starts at 100 and drops by 25 on each collision; the game ends at 0.
CarAvoidGame/
├── CarAvoidGame.sln # Visual Studio solution
└── CarAvoidGame/
├── Program.cs # Application entry point
├── MainForm.cs # Form logic: input, rendering, game loop wiring
├── MainForm.Designer.cs # UI layout (buttons, panel, progress bar, timer)
├── Domain/
│ ├── GameEngine.cs # Core game state and update logic
│ ├── GameObject.cs # Base class for positioned/bounded game entities
│ ├── Car.cs # Player car: movement and boundary clamping
│ ├── Obstacle.cs # Falling obstacle: position and fall speed
│ └── GameConstants.cs # Tunable game parameters (speeds, sizes, scoring)
└── Images/
├── road.png # Background
├── car.png # Player car sprite
└── cone.png # Obstacle sprite
The project follows a simple separation of concerns:
Domain/contains pure game logic (no UI dependencies) — the game engine, car, and obstacles.MainFormhandles rendering, keyboard/button input, and wiring the game loop to the UI.
- Windows OS
- .NET Framework 4.7.2 (or later, backward-compatible)
- Visual Studio 2019/2022 (or any IDE/toolchain that supports .NET Framework WinForms projects)
- Clone the repository:
git clone https://github.com/aiymvr/CarAvoidGame.git
- Open
CarAvoidGame.slnin Visual Studio. - Build and run the project (
F5orCtrl+F5). - Click Start in the game window to begin playing.
All key gameplay parameters live in GameConstants.cs, including:
- Car/obstacle dimensions and speed
- Obstacle spawn rate and difficulty ramp-up
- Scoring values
Tweak these values to make the game easier, harder, or faster-paced.
No license file is currently included in this repository. Add one (e.g., MIT) if you intend for others to reuse this code.