
- CHANGE BEST SCORE SNAKE VS BLOCK HOW TO
- CHANGE BEST SCORE SNAKE VS BLOCK UPDATE
However, despite its colourful numbered blocks and stream of ever-expanding dots, it plays quite differently to its inspirations. This is to prevent our snake from reversing, for example when you press the right arrow key when the snake is moving to the left.At first glance, Snake VS Block looks like yet another variation on the BBTAN / Ballz craze that has been sweeping the mobile nation. Notice that we also check if the snake is moving in the opposite direction of the new intended direction. If it does, we change the vertical and horizontal velocity as described earlier. We check if the key pressed matches one of the arrow keys. Thus, to create a horizontal snake in the middle of the canvas (150, 150) we can write the following: let snake = [ To do that, we can represent the snake as an array of coordinates. If you reload snake.html in your browser, you should see a white box with a black border! Good job, we have a canvas that we can use to create our snake game! ? On to the next challenge! Representing our snakeįor our snake game to work, we need to know the location of the snake on the canvas. This covers the entire canvas, starting from the top left corner (0, 0). We then get the canvas “2d” context, which means we will be drawing into 2D space.įinally we draw a 300 x 300 white rectangle with a black border.
CHANGE BEST SCORE SNAKE VS BLOCK UPDATE
Update your code as below.įirst we get the canvas element using the id (gameCanvas) we specified earlier. We can now write some JavaScript code, between the enclosing tags.
If you put the tag befor e the