Our Game
We set out to create a fun and engaging take on a classic driving game. The objective of the game is to control the side to side motion of car racing down a road and avoid the obstacles that scatter the road ahead. Your score is the number of obstacles you avoid before you hit one, ending the game. Our first iteration was controlled by the keyboard’s arrow keys then for our second iteration we used a hand recognition algorithm for user input to the game, allowing the player to control the car with their hand movements.
First Iteration - Arrow Key Controlled
In the first iteration of our game the controller got user input from key presses on the arrow keys. We implemented the game using the PyGame environment which streamlined and simplified the movement of objects in the game window and collision detection. By starting with the arrow control we were able to develop our model, view, controller architecture and test with simple inputs. The game has 3 key visual objects: the road, the rocks (obstacles), and the car. The cars position is updated only by user input and it’s position is limited by the edges of the window. The road is made up of two objects which move downward at a steadily increasing speed as the game progresses and leapfrog back to the top so road appears to move by infinitely. Lastly, the rocks are randomly placed to a random horizontal position and vertical position above the start of window.
Second Iteration - Controlled by Hand Motion
The second iteration of our game used OpenCV and MediaPipe to access the webcam and return the position of the players hand. This new control method was fed into the controller instead of arrow key inputs. In the video below you can see the game in action:
As you can see the game is run from the command line opening a webcam feed window as well as the game window.
How to Run Game
To play our game you can access our repository here where detailed directions can be found for downloading the modules and running the game. After installing all of the packages, run python3 play_game_hand_control.py
for the hand control version and python3 play_game_key_control.py
for the key control version.
Creators
Aaron Blust & Trevor Zou
Olin College of Engineering 2024
References
Checkout MediaPipe Hands and other open-source ML detection models: https://google.github.io/mediapipe/
Murtaza’s Workshop - Robotics and AI. (2021, March 25). Hand Tracking 30 FPS using CPU, OpenCV Python (2021), Computer Vision [Video]. Youtube. https://www.youtube.com/watch?v=NZde8Xt78Iw&t=613s