In this lesson we will be adding a food property to the fish class, and displaying a food bar indicating how full the Fish is.
We'll also be deleting Fish whose food supply has run out.
fishArray
Add a line here that subtracts 2 from the Fish's food
if (this.food <= 0) { }
Put this in the Fish's move() function.
move()
index.js
draw
It may look confusing so I've written what this code says in English beneath it:
Any Fish that is not dead will pass through the filter. Meaning all dead fish will be removed from the array
You may want to temporarily make them lose a lot of food each time they move, just to test a bit faster
maxFood
I used the size of the fish to place the rectangle
This represents the full size of the food percentage bar
Account
MVCode Clubs
Created By
jamie
Course:
Evolving Fish Pond
Access Level
premium
Teach coding to your students with MVCode Teach
MVCode offers an integrated product designed to teach coding to students.
Learn more about MVCode Teach