Rush Hour is a 2D grid-based driving and delivery simulation game built in C++ using OpenGL/GLUT. Developed as a 2nd-semester Object-Oriented Programming (OOP) project, this game challenges players to navigate a bustling city, manage resources, and earn money by completing jobs before time runs out.
- Dual Roles: Play as either a Taxi Driver (picking up and dropping off passengers) or a Delivery Driver (transporting packages). You can even swap roles mid-game at designated Role Change Stations.
- Resource Management: Keep an eye on your fuel gauge! Every move consumes fuel. Earn money from fares to purchase gas at Fuel Stations.
- Dynamic AI Traffic: The city is alive with other cars navigating the grid autonomously. Avoid collisions to prevent score penalties.
- Obstacles & Hazards: Maneuver around trees and roadblocks. Crashing into them will damage your score.
- Winning & Losing: Reach a score of 100 to win. If your score drops below 0, time runs out (180 seconds), or you run out of fuel, it's Game Over.
- Persistent Leaderboard: High scores are saved locally to
highscores.txt, allowing you to compete against your past runs.
| Key/Input | Action |
|---|---|
| Arrow Keys | Move your vehicle (Up, Down, Left, Right) |
| Spacebar | Interact (Pick up / Drop off passengers or packages) |
| F | Refuel vehicle (Must be near a Fuel Station) |
| P | Open Role Change Menu (Must be near a Role Station) |
| 1 / 2 | Select new role in the Role Change Menu |
| ESC | Cancel action / Exit Game |
| Mouse Click | Navigate Main Menu, Color Selection, and Leaderboard |
This project extensively utilizes core Object-Oriented Programming principles to manage game state and entities:
- Inheritance: A central
GameObjectbase class serves as the parent for all grid entities (Car,Passenger,Obstacle,Target,OtherCar,FuelStation, etc.), promoting high code reuse. - Polymorphism: Utilizing virtual functions (like
draw()andgetFare()) allows the main game loop to render and interact with different objects dynamically via a 2D array of base class pointers (GameObject* grid[25][25]). - Encapsulation: Object states (like the player's fuel, the game's wallet, or passenger fares) are kept private and accessed only through strict getter/setter methods to ensure data integrity.
- State Machine: The
Gameclass uses a constant-based state machine (mainmenustate,playing_State,gameover, etc.) to control rendering and input logic seamlessly.
- Language: C++
- Graphics Library: OpenGL / GLUT (managed via a custom
util.hwrapper) - Compiler: Any standard C++ compiler (g++, MSVC) with OpenGL linking.