The Gun Game and how to play

For this project I chose to take a pantomime game I used to play when I was a kid and bring it to life through code and animation.

The Gun Game plays much like rock paper scissors but with some key differences. Each round you and a friend will decide simultaneously between three choices, reload, block, or shoot. Reload will give you one bullet. Shooting will remove one bullet, and blocking will protect you from an incomming bullet.

If both players shoot both lose a bullet and you move on to the next round. Both players will start with zero bullets and have a maximum of six bullets.  To win the game you must shoot your opponent while their reloading.

 

Student Work

Temple University

Instructor: Jenny Kowalski

Tools: JavaScript, HTML, CSS, Photoshop

The wild west theme was inspired by the way me and my friends would act when we played the game. We would hold our hands on our hip and draw our finger guns as if we were real cowboys shooting pistols. For that reason it only made sense to make the playable character a cowboy. The opponent is depicted as a robot because they are an NPC and their moves are entirely dictated by the code being run in the computer.

The aesthetics and animations were driven by an 8-bit style reminiscent of old arcade games. Theres a reason why this style was so common at one point and its because of how easy it is to code.

The Code

This was my first time coding in JavaScript so it is fair to say initially I didint know where to start. The functionality of the game was important to me because I really wanted it to feel like you were actually playing the game.

So to start out I made a chart that mapped out every input and possible outcome. That way I could reference the chart as I was trying different ideas and laying out the foundation making sure that every moving part was accounted for.

After the trial and error phase I found what worked best for processing the inputs and having them effect the outcome of the game were boolean variables. Booleans are a binary variable that basically tell if something is true or false when the code runs. The boolean would then be followed by a command which are known as If Then Statements. A simplified example of this would be, if (the cowboy chooses shoot) then (play the shoot animation). 

This process had a few extra steps for the robot because I had to have the script generate its inputs. I did that by using a random number generator that would determine its choice and then using more booleans to assign rules for specific situations so the robot would behave logically. This allowed for the opponent in the game to be unpredictable at times but also stop the AI from making decisions that wouldn’t make any sense, like shooting when they have no ammo.