On screen snake7/13/2023 ![]() ![]() ![]() If that is true, it stores the new direction as "Z". This "If" statement will check to make sure that you pressed an arrow key and you aren't trying to reverse your direction. Z is the direction that the snake is heading, based on keycodes.Ĭonstant repeats until you press Delete, Clear, or until the game sets θ to 45. This is a loop that puts random blocks on the screen.ĭraws walls and sets the initial direction to the right (26). The integer part of it is the score, and the decimal is the counter to how long your tail grows when you eat food. It starts in one spot then jumps randomly when eaten.Ĭ is the score and counter for the food. "A" is the 'X' and 'Y' coordinates for the head of the snake. The integer is it's 'X' coordinate, and the decimal the 'Y' coordinate divided by 100. This list is the coordinates of your snake pieces. This once again sets the graph screen to the right settings. This screen is a lot better than the one I personally wrote for mine, which consists of "BLARGH!". Note: It will not reset your graph screen, so it's dimensions and settings will remain the same. The output right before the stop keeps the "Done" from appearing at the end. This piece runs the start animation and is the main menu. Pt-Off(iPart( LSNAKE(dim( LSNAKE,-100fPart( LSNAKE(dim( LSNAKE,2 At any point the animation is skipped by pressing any key, and it jumps right to the game. This causes the snake to travel in an "S" pattern across the screen. This is the part that has the snake change direction after each amount of time passes. Instead of writing the animation seperate, I copied part of the actual game and simply timed changing the direction by simulating user input. This part is essentialy my game stripped down to only three movement directions and the display. "Z" is the direction it is traveling (26 = right, 24 = left, 25 = up). The integer part of "A" is the 'X' coordinate, and the decimal the 'Y' coordinate. This sets the starting values for the direction the snake travels, where it starts, and user input. This section sets the screen so that each pixel has an integer equivalent (0 to 94,-62 to 0). This section makes sure nothing like graphs or axes show up on the screen so your lovely image isn't interrupted by, say, Y=log(X) tearing across your screen. The opening animation is a subprogram called at the start of the game. This used three main programs, prgmGSNAKEA (the opening animation), prgmGSNAKE (the actual game), and prgmGSNAKER (the food respawn sequence). ![]() Θ (you can use whatever variables you want, but these are what are used in our example code below) This includes randomly generated brick things and a wrapped screen. You eat the food and avoid running into your tail. Add the new head to the beginning of snake bodyĬonst has_eaten_food = snake.x = foodX & snake.y = foodY ĭocument.getElementById('score').This is a standardish snake game. The number of coordinates in the object will be equal to the length of the snake. Thus, to create a horizontal snake in the middle of the canvas, at (200, 200), we list the co-ordinate of each body part of the snake. Now, for the snake! We need to specify the initial location of our snake on the canvas by representing the snake as an array of coordinates. ![]()
0 Comments
Leave a Reply. |