For my final project, I wanted to recreate one of my favorites all time games that I had played since an early age. the snake game was a very popular game in the 90s and it is still today.
by using multiple functions and conditional statements. I created a simulation that will allow a rectangular shape move around the canvas edges simulating the snake.
after creating my set up function with a canvas of (600,500) I will then create some variables and give them value that will allow my boolean method to take action when creating my snake functions. such as movements.
next I will add my array method that will help me display text in my canvas with my name. The “for” loop goes through our arrays using the index set from 0. also I set the parameter and size by string index.
after that I will create my rectangle shape with the variables I created early this shape will move as the snake I am trying to accomplish. Also I will draw an ellipse that will be please on the top right corner looking like a target for my snake.
this will be my construction boolean statement that will allow my rectangular shape to move from side to side shifting directions when hitting the corners. it is very important to right this if statements as it can’t damages our code. using the true or false method I stated by telling my square to go the right and stop when the square is bigger than the width it will stop and then I will change the speed of X to 0 and give the Y a speed of 5 changing the direction to the upper Y axis, the I wrote a statement that will stop my square when it hits the 200 Y axis and returning to the left by giving Y speed 0 and X speed 5, then I wrote a statement that when the x & are > than 1 will change the direction to the right living me with the last function that is if the square Y = 530 the square will stop. giving the illusion that the snake eat the fruit (ellipse).
last but not least my random function that will multiply the square giving me the illusion to where the snake already passed, the red, green and blue colors are set to 255.
this will be the result. the colors will be the snake trail, where it has pass and and the ellipse will be the target or where the snake is trying to go.