Partner: Amber Wang
What motivated us to do the midterm project was to solve a daily problem of who should go down and pick the food delivery. Everytime I ordered food on Elema or Sherpas with my friends, nobody actually wants to go to pick the food delivery. In order to solve this life problem, Amber and I wanted to design a game which not only could involve two players in competeing against each other, but also could solve the problem in an entertaining way. Most importantly, it should take two players as short of timeas possible to play the game, in case of keeping the deliverman waiting for a long time.
Generally, we referred to two simple video games. The first one if a game called PlaneWar on Wechat. In this game, player (the plane at the botton of the screen) is required to shoot other enemy planes. The more planes you can shoot, the higher grade you would get. At the same time, you should avoid crashing other planes as well. It is an interesting game for challenging a player’s agility. Here is a picture about the PlaneWar.
The other reference is a game named Block Run on 4399.com. As you can see from the picture following, this game is designed for the player (the red column) to dodge other grey columns. There are several chances for you to stay alive when failing to dodge greay columns.
With the help of two references, we decided to make a game called Dodgeplane. Before coding, we first stretched the idea on a paper. There are two players, which are attacker and defender. The screen would be seperated as two parts. The defender is on the upper part and the attacker is on the lower part. Both of them can move up, down, left and right on their own part. The attacker can send missiles to shoot the defender. In 60 seconds, if missiles hit the defender, the attacker would win. Otherwise, if the defender can sucessfully dodge missiles, the defender would win. Players can use “w”, “a”, “s”, “d” to make the defender move up, left, down, right and they can use the keyboard of UP, LEFT, DOWN, RIGHT to control the movement of the attacker. However, we decided to use joysticks to control the movement of planes at last. Comparing with crowding in front of a computer, joystickes would make the game more interactive and interesting.
In order to improve work efficiency, I was in charged of the Processing part and Amber focued on the Arduino part (which mainly includes attaching joysticks to the game).
In the begining, I drew two ellispses to represent two airplanes. Amber would photoshop two pictures of planes to replace the ellipses when I finished coding. With the help of Jiwon, I started with coding the defender and the attacker. Since planes can move in four directions, I set x, y of the defender and the attacker as variables. I used keyPressed function so that I could use keyboards to control the planes. I also print the keyCode I used so that I could find clearly whether the keyPressed function worked.
The most challenging part for me was to code the missile. There is no restrictive condition for the attacker to send missiles, and the player can send as many missiles as he wants. The player could send missiles through pushing the space bar. Jiwon taugt how to use boolean to set the missiles. There were two variables, boolean shoot and boolean setStart. Initially, they are equal to “false”. When the player pushed space bar, they are equal to “true”. Under the circumstance of “true”, a missile would move forward and its position would go back to the initial position when it is out of the screen. However, in this way, the attacker cannot constantly send missiles. If the attacker send missiles before former ones reach the end of the screen, the former would turn back to the starting position. Here is a video about the problem of missiles.
Professor Antonius helped me to improve the code of missiles by adding an important part–resetting the missile. That is to say, only when a missile reaches the end of the screen, can the position of the missile be reset. As a result, the attacker cannot send another missile until the former one reaches the end of the screen. Missiles that has already been sent will keeping moving and would not be drove back by pushing the space bar. Here is a video about the imoroved version of missiles.
It is after I took the class of Arraylist that I truly figured out how to code the missiles. Marcela’s examples helped me a lot to learn Arraylist. There were 14 examples from Array to Arraylist, from drawing random line to drawing random circles, from random fixed circles to circles with random speed. It took me a whole afternoon to understand the examples. By changing some values of codes, I managed to figure out what exactly every function works. Moreover, Marcela recommended a Youtube Tutorial which educative as well as funny. Although some coding in the video is outdated, the general logic remains unchanged.
For the missiles, I used Arraylist, the class function including display function and move function. The starting position of missile is the same as that of the attacker so that missiles can fly away from where the attacker is. In the move function, the x of missiles would not change while the y of missiles would decreases at a speed of 2. When referring to examples of Arraylist, I used mousePressed to add new missiles. But I found that once I pressed the mouse, there would be missiles continuously sent out even if I released the mouse button. Therefore, I used mouseClicked instead, which means, the moment you click the mouse, a missile would be sent out. By decreasing the size of missiles, I managed to control the amount of missiles I want to send accurately.
Another tricky part was to set that when a missile hits the defender, the attacker will win the game is over. I set time as a variable and the time would decrease by subtracting mills. When the difference between y2 (y of the defender) and y (y of the missile) is 0, the screen will show a picture that with “YOU LOSE” on the upper side and “YOU WIN” on the lower side. However, since I used Arraylist as a function to code missiles, the y of missiles would keep decreasing. That is to say, there is only a moment that y2-y=0. And it is so fast that the picture cannot showed on the screen. With the help of Avan, I used dist, the absolute value of distance, to express the distance between the defender and the missile.
Thanks to the “Tree Model” Professor Antonius taught me, I could organize my codes clearly. For example, I would first write p1.move(); as a title in the draw function. And under a new Tab “Move”, I would add the move function of plane 1 separately. Organizing code in this way could effectively helps me to avoid missing } and makes it more convenient for me to improve my codes.
5. Physical Surrounding
We tried to improve the physical surrounding of the game to make it more interactive. Since it is not comfortable to hold the joysticks we found in lab, we attached two rubber hemispheres to them. The rubber hemispheres could fit into people’s hands very well. this way, players would find it easier and more convenient to use the joysticks.
6. Dodgeplane is Born!
After we finished out project, some of my classmates tried the game. Most of them found that it is an unfair game. Since there is no limit to the amount of missiles, attacker can easily kill the defender. Lack of time to improve the project, I merely shortened the time the game lasts to 20 seconds. So far, there has been no player of defender that could hold on more than 15 seconds. If we had more time, we would have improved the project by limiting the missiles the attacker can send at one time. For example, the attacker can only send five missiles at one time. After the fifth missile reaches the end of the screen, can the attacker send another round of missiles.
I really appreciate the help of professors and teaching fellow. I would not have made Dodgeplane come into being without their assistance. The midterm project was a valuable opportunity for me to integrate codes I learned before and use them in a practical way. At the same time, I earned a strong sense of achievement from the project. In this process, I sometimes felt very depressive because of failing to write the codes as I expected. Thanks to the support of Marcela, I gradually understand that the process of learning is more important than a final result. The purpose is not only to make a game, but also to learn how to code, how to interact and enjoying the process of coding.