Inspiration
Introduction During the pandemic, I picked up playing video games again in years. While playing Ryse I wondered if I could combine playing with working out to stay more fit. There are a few systems out there that you can move and play, but most are expensive and require special equipment. But all we really need to do is just keep track of the body movement with the webcam and create a way to translate those movements into something a computer will understand. There are a few amazing videos on YouTube that try writing code to play games with body gestures. I wanted to add to them and hopefully add to the quality of the games. Check out how the game looks:
What it does
How the Game Works The first game I attempted was a “boxing” game, where I could punch something that appeared on the screen and get points for it:
First, with OpenCV and MediaPipe and a tutorial from Nicholas Renotte, I set up some code that uses my webcam and keeps track of my body movement. Then I had to add something to punch on a screen. This page had some neat code on how to add two images together. I wanted to punch something evil-looking so with the help of Dal-E I created a villain.
Now I just had to calculate the distance between either of my hands that are tracked by mediapipe and the evil face. When that distance was sufficiently small enough then impact occurred, I got a point, and the evil face reset. I added a punching sound to it to make the game more engaging.
Sometimes villains punch back. After a while testing this game, I found that just punching a face gets a bit repetitive. So once in a while villain's glove appears on the screen headed toward your face and you have to duck away from it. Here I was able to move the glove and increase its size on the screen. At this point, we keep track of the player’s head and when they duck down or to the side the glove misses and the fight resets. If you don't duck fast enough points are reduced.
Now we set it all in a loop for one round or 60 seconds. Let's see how many points we can get. You can quit by pressing Q. Time and points are tracked on the top of the screen. at the end of the round, you can start another round by pressing r on the keyboard.
I added the link to Github where you can find the code for this game. I will be building other games using this method so please follow me if you want to see other games. Also, I’ve used this method to play almost any game where your body gestures become the controller. Check out the original implementation for Ryse here.
Log in or sign up for Devpost to join the conversation.