Exported from Notepad++
// Fun Snake 2 // Snake Constants var SNAKE_DIM = 10; var SNAKE_COLOR = Color.green; // Constants to represent the directions var EAST = 0; var SOUTH = 1; var WEST = 2; var NORTH = 3; var snake; var currentDirection = EAST; function start() { // TODO: create the snake and add it to the canvas setTimer(draw,50); keyDownMethod(keyDown); } function draw() { var dx = 0; var dy = 0; addTail(); if (currentDirection == EAST) { dx = SNAKE_DIM; } //TODO: add the other three directions //TIP: Check the "center" of the position the snake is about to move to. var elem = getElementAt(snake.getX()+SNAKE_DIM/2+dx,snake.getY()+SNAKE_DIM/2+dy); //TODO: If elem contains a snake body, get GAME OVER // For an Example, check out DOCS->Animation->Misc snake.move(dx,dy); } function keyDown(e) { if (e.keyCode == Keyboard.LEFT) { currentDirection = WEST; } // TODO: add the other three directions } function addTail() { //TODO: Add another rectangle at the current // position of the snake to act as the tail // the x and y coordinates of the snake can // be found using snake.getX() and snake.getY() // Refer back to the TRAIL exercise for an example }