A Snake Game in JavaScript


Interesting…

This Could Be Better

The code below implements a simple “Snake” game in JavaScript. To see it in action, copy it into an .html file and open that file in a web browser that runs JavaScript. Or, for an online version, visit https://thiscouldbebetter.neocities.org/snakegame.html.

Use the A and D keys to turn the snake left and right. Collect the red “food” squares to increase the length of the snake, and thus the score. The game ends if the head of the snake runs into the outside wall of the playfield or part of the snake’s body.

Snake

<html>
<body>
 // main function main() { var level0 = new Level ( new Coords(32, 32) // sizeInCells ); Globals.Instance.initialize ( 200, // millisecondsPerTimerTick new Coords(128, 128), // viewSizeInPixels level0 ); } // classes function Coords(x, y) { this.x = x; this.y = y; } { Coords.prototype.add = function(other) { this.x += other.x; this.y += other.y; return this…

View original post 87 more words

Leave a comment