top of page

Week 4: Simple Snake Game

https://editor.p5js.org/sherryliulxy/sketches/t2-DBWlLi

 

This week, to practice the for loop. The first thing I thought about is to make a snake game. 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

But my snake game is very easy, the snake cannot eat itself and cannot die when cash to the wall.  The mouse is the snake, it will eat the food by mouse, and when you finish eating all the foods on the screen, you click the mouse it will have more foods come out. 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

At first, I made a loop for the random foods on the screen. I made them shaking and flying.​

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Then, I was trying to add an if function for the snake and make it eat the foods. But I did not know how to do it. An ITPer called Ge Chang helped me to write the function for the snake to eat the foods first, and the mousePressed function to add the food. 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I am still not familiar with JavaScript and sometimes do not know how to write the function. I think it is very important to discuss with people who are already using it for a long time. You can always learn something from them. 

bottom of page