[ICM] Week 6: Arrays and Objects (Catch the Roach)

Link to sketch: LINK

I used my interactive cloud code from last week’s assignment as a base for instances of an object moving left to right. For this assignment, I replaced the clouds with roaches and turned it into a clicker game. When we first moved into my new (current) Astoria apartment about a couple months ago, we had a bit of a roach problem. One of my roommates is very squeamish around roaches and this game was inspired by him. Usually if he ran into one, I would go in and either chase it or clean up the corpse.

I used pixel graphics found from online search, which was imported using preload() from an assets folder. When a new roach is “born”, its width, height, type (there are 3 different breeds of roaches in this game), and speed are randomly generated, though within specified ranges.

 

For this game, I had two different arrays storing information. There was the Bugs[] array that kept track of the bug objects on the screen and another array typesOfBugs that stored the image data for the three bug graphics. Bugs[] was parsed through every draw() cycle. For each bug on the screen, it’d show on screen, move to its next respective x and y position, remove itself if it has gone past the screen, and check for mouse interaction. typesOfBugs[] was much simpler in that it was simply used so that the roach image could be randomly generated depending on index (ex: random(0,2) for a three image array).

For the mouse interaction, checkClicked() is a Bug class specific function that checks if the mouse click was within bounds of its respective image. I added moE (margin of error) to make the game more playable. Otherwise, it’d feel like the user was clicking the bug, but not getting the squish. The higher the moE, the easier the game would be. Next, I added a points system so that the smallest bugs gave the most points, and then the small-ish or fast bugs gave slightly higher points.

Lastly, I added a health bar to create some stakes. Whenever a roach passed through the canvas without being clicked, the health bar would deplete. When fully depleted, the health bar and points would reset. The game still keeps track of total bugs squished though, just for pure player satisfaction.