ICM week 2
For this week’s project I decided to make a spider swatting simulator.
I manually drew the spider with P5 using variables for the shapes’ X and Y positions to allow modifications and movements of the spider to be made by changing just two variables (spiderX, spiderY). For the swatter, instead of drawing it manually, I imported an image and made its position mirror the mouse position (with slight modification to make it more centered). I used a random function to make the spider appear at a different spot every time the sketch is run; a random function is also used to move the spider position in a different direction in every draw loop so the spider is always moving.
The biggest challenge was figuring out the interaction for hitting the spider with the swatter. Ideally I wanted to make it like a video game where the spider turns into a dead spider once it got hit, and the game automatically resets. I knew there were functions which reads the mouse input and I know I can use conditional statements to specify an action to take place when mouse is clicked at the spider’s location, but I had no idea how to use one of those functions to reset the sketch.
Not knowing how to trigger the reset, I decided to first add an image of a splatter of slime to represent a dead spider for when mouse is pressed in the area of the spider. When I added the splatter, it moves with the spider after appearing, and it disappears if the mouse is no longer pressed. I speculate that this might be solved with reordering the code for the splatter but before i explore further I found another coding train video where Dan resets a sketch with a button by re-writing the canvas and other codes from the setup function at the button of the sketch; I tried doing the same, and after solving some formatting issues, I was able to get the sketch to reset (draw new canvas with new randomized spider location) when mouse is pressed in the vicinity of the spider.
The current version of the sketch is definitely functional, but I think an improved version of the sketch will show a splatter of slime (dead spider) for a second or so when the mouse clicks the spider before resetting to a new game. I have no idea how to make the slime appear for a bit before resetting and I’m also not sure how I can make the slime appear in the spider’s position without moving around with the spider (maybe remove the spider shape and make the splatter appear at the spider shape’s last position somehow?).