Part X: The Apocalypse

Introduction

This blog post will talk about my final project for the class Nature Of Code, called NY Zombies, in which the player has to kill as many zombies as he can, before dying from the zombie massive zombie horde. One of  my initial goals was to adjust many of the game’s components based on live weather data, but I did not really focus on this aspect since creating and perfecting the game itself took me a lot of time, but it was worth it in my opinion.

Creation Process

The programming part of the code was quite complicated since I had to use many different classes in order to make sure that the game works.

The first class I made is the player class, which controlled all the player related functions. The player’s initial position was the centre of the canvas, while for the player’s texture I used  some textures I found online. Next I had to make sure that player would always face the mouse’s position, in order to make sure aiming is correct and that it looks good. For that reason, after your help I managed to rotate the player in a certain angle, which depends on the mouse’s position. Even though I could create player movement in the player class, I actually did it in the draw function, since it is repeatedly called. This away, every time w, a, s ,d or the arrows are pressed the player moves the appropriate way.

The next basic step, was to make the bullet function. Therefore I had to combine it with the mouseReleased function, since the bullet would be fired every time the user clicks the mouse. Furthermore, I created an empty array that would contain each bullet every time its fired. Furthermore, for the bullets I used simple forces that were guides by the mouses and the players location, in order to move from the player towards the intended direction. It is important to notice that I would splice from the bullet array, any projectile that went out of the canvas, in order to make the game easier from the computer to process.

Furthermore, the hardest class of all were the zombies. Initially, I would make sure that the zombies spawn in random locations from the edge of the canvas and also make sure that they constantly move towards the player. In order to accomplish that, I used a similar technique with the bullet, but also by adding another function inside the class I constantly changed their direction of movement towards the player’s current position. Furthermore, by using similar technique with the player’s rotation, I made sure that the zombies would always face the player, giving the game a quite creepy look. It is important to notice that all the zombies that are spawned are added to the z array and furthermore, I made sure their zombie rate would slowly increase, thus making the game progressively harder, by using the random function as you instructed me.

The next part was collision, which surprisingly was quite easy. In order to achieve collision, I circled through the array of the zombies and for each zombie I would circle through all the bullets. This way, if the distance between a bullet and a zombie is less than 20 pixels, the zombie would be spliced from the array and the bullet would be converted to a blood splatter that would permanently stay on the ground in order to give a gorey filling in the game. Furthermore, I also added a splatter sound, every time a zombie was killed.

The next and last part was the interface. Before the game starts, a black screen with the controls is shows along with the soundtrack from the movie “World War Z” and the game would start every time the player presses enter. Similarly, every time a player dies another interface is shown, showing him his score and allowing him to press ENTER again to go back to the main menu and restart the game.

Feature

Despite the fact that the game is complete, I will soon add more features, such as a leaderboards scoreboard as well as create multiple maps and weather conditions depending on the live weather of different places. At the moment the game currently only shows the current temperature of NYC, by using the open weather API.

Conclusion

In conclusion, I would like to say that I loved working with creative coding and it is a field I would really love to work with in the feature.

Thanks for reading,

Christos

Leave a Reply

Your email address will not be published. Required fields are marked *