For this project, I created a small aquarium scene, where colorful fish swim across the screen. Each fish is an object with its own properties like color, speed, and direction, and they move infinitely using simple math. I used arrays to manage multiple fish at once, and clicking on a fish makes it disappear, while pressing “C” brings all the fish back.
I decided to do this because I wanted to practice the class material but keep it interesting at the same time. Initially, I just had fish swimming in one direction with different speeds but I thought it was too boring so i added different directions and made them more interactive.
One problem I ran into was making fish face the correct direction when swimming left or right, but adding a simple check for xspeed solved it. Overall, this project helped me practice object-oriented programming and arrays while making a fun, interactive visual.
The part of the code that I’m proud of is this part:
move() { if (!this.visible) return; // skip if hidden this.x += this.xspeed; this.y += this.yspeed; let bodyHalf = 30; if (this.x > width + bodyHalf) this.x = -bodyHalf; if (this.x < -bodyHalf) this.x = width + bodyHalf; if (this.y > height + bodyHalf) this.y = -bodyHalf; if (this.y < -bodyHalf) this.y = height + bodyHalf; }
Here, it makes the fish disappear when clicked. It took me some time to figure out where I’d need to press and how not to let the “invisible” fish get in the way.
Something that I would like to improve in the future would be adding more aesthetics to it and making the fish more sophisticated-looking so to say.
But after all, here’s what I got, try to catch them all 😛