Concept
Phew! That was one hell of a ride for sure. For my midterm project, I have created a shooting game, with a forestry theme. The name (Man Vs Tree) is inspired by the Netflix show (Man Vs Bee) starred by the famous Mr.Bean lol. Basically the project started off as an idea of creating a whole ecosystem of different enemies to our environment and catalysts to global warming. However as challenges grew and came in different forms, I finally decided to implement the current theme, which is simple yet meaningful. Man Vs Tree is about a player, which is an apple tree, protecting its forest against loggers by attacking them with apples. As more enemies die, they spawn power-ups as ozone health. The enemy loggers shoot dynamites and axes at the tree, and once all lives are finished, the tree dies and the game is lost.
Code
The coding for the game was indeed a great hustle. A lot of time was spent in thinking about the mechanics of different aspects such as collisions, arrays, level implementation, speed optimization, and many more concepts. Even more time was spent testing the game and making sure there were as few bugs as possible and that all the logic implemented was working as it was supposed to. Below is a snippet of the game class, showing the display method of the game class.
display_game() { //condition for displaying actual gameplay when game has started if (this.gameStarted && this.gameOver == false && this.gameWon == false) { image(this.bg_img, 0, 0, 600, 600); this.player.display(); //loop for displaying all enemies in enemy array for (let i = 0; i < this.enemies.length; i++) { this.enemies[i].display(); } //loop for displaying all projectiles in enemyprojectiles array for (let i = 0; i < this.enemyProjectiles.length; i++) { this.enemyProjectiles[i].display(); //logic for player and enemyprojectile collision detection, player then takes damage if (this.enemyProjectiles[i].used == false && this.enemyProjectiles[i].collision(this.player)) { this.player.hit(10); } } //loops through enemyprojectiles array and pops any projectiles which have already collided for (let i = 0; i < this.enemyProjectiles.length; i++) { if (this.enemyProjectiles[i].used == true) { this.enemyProjectiles.splice(i, 1); break; } } //loops through enemy array and pops any enemies with health less than zero for (let i = 0; i < this.enemies.length; i++) { if (this.enemies[i].health <= 0) { this.enemies.splice(i, 1); break; //logic for score reduction if enemy reaches beyond screen height, and pops enemy from array } else if (this.enemies[i].y > 650) { this.enemies.splice(i, 1); this.score -= 10; break; } } //loops through playerprojectiles array and displays them for (let i = 0; i < this.playerProjectiles.length; i++) { this.playerProjectiles[i].display(); //detects collision btn playerprojectiles and enemies, then enemy takes damage for (let j = 0; j < this.enemies.length; j++) { //Check if the projectile collides with any enemy if ( this.playerProjectiles[i].used == false && this.playerProjectiles[i].collision(this.enemies[j]) ) { this.enemies[j].hit(10); } } } //loops through ozone powerups array, displays them, and detects collision with player for (let i = 0; i < this.ozone.length; i++) { this.ozone[i].display(); if ( this.ozone[i].used == false && this.ozone[i].collision(this.player) ) { this.ozone[i].give_health(); } } //pops ozone powerup from array once collected by player for (let i = 0; i < this.ozone.length; i++) { if (this.ozone[i].used == true) { this.ozone.splice(i, 1); break; } } this.show_score(); //logic controlling time in the game if (frameCount % 60 == 0) { this.timer += 1; }
Reflections / Improvements
Overall , I am proud of myself and the general implementation of the code. However, of course there could further improvements that could be made such as having variety of enemies, more visual effects such as floods maybe or rain. Codewise, there was quite some hardcoding which could’ve been implemented more elegantly, and made the game more efficient and easy to understand. Watching that progress starting from scratch to coming across those bugs that you would spend hours, sometimes days on, and seeing the final version of the game gives me great joy, one I can not describe.