This commit is contained in:
2026-01-16 20:56:16 -06:00
parent 9f6435ece9
commit 22962bbd63
33 changed files with 643 additions and 315 deletions

View File

@@ -10,8 +10,8 @@ var random = use('random')
prosperon.camera.transform.pos = [0,0]
var cellSize = 20
var gridW = number.floor(config.width / cellSize)
var gridH = number.floor(config.height / cellSize)
var gridW = floor(config.width / cellSize)
var gridH = floor(config.height / cellSize)
var snake, direction, nextDirection, apple
var moveInterval = 0.1
@@ -19,8 +19,8 @@ var moveTimer = 0
var gameState = "playing"
function resetGame() {
var cx = number.floor(gridW / 2)
var cy = number.floor(gridH / 2)
var cx = floor(gridW / 2)
var cy = floor(gridH / 2)
snake = [
{x: cx, y: cy},
{x: cx-1, y: cy},
@@ -34,7 +34,7 @@ function resetGame() {
}
function spawnApple() {
apple = {x:number.floor(random.random()*gridW), y:number.floor(random.random()*gridH)}
apple = {x:floor(random.random()*gridW), y:floor(random.random()*gridH)}
// Re-spawn if apple lands on snake
for (var i=0; i<snake.length; i++)
if (snake[i].x == apple.x && snake[i].y == apple.y) { spawnApple(); return }