fix syntax

This commit is contained in:
2026-02-17 09:15:15 -06:00
parent f310c18b84
commit 4e1b63fd0e
52 changed files with 2169 additions and 1754 deletions

View File

@@ -13,7 +13,7 @@ var cellSize = 20
var gridW = floor(config.width / cellSize)
var gridH = floor(config.height / cellSize)
var snake, direction, nextDirection, apple
var snake = null, direction = null, nextDirection = null, apple = null
var moveInterval = 0.1
var moveTimer = 0
var gameState = "playing"
@@ -36,7 +36,8 @@ function resetGame() {
function spawnApple() {
apple = {x:floor(random.random()*gridW), y:floor(random.random()*gridH)}
// Re-spawn if apple lands on snake
for (var i=0; i<length(snake); i++)
var i = 0;
for (i=0; i<length(snake); i++)
if (snake[i].x == apple.x && snake[i].y == apple.y) { spawnApple(); return }
}
@@ -63,7 +64,8 @@ this.update = function(dt) {
wrap(head)
// Check collision with body
for (var i=0; i<length(snake); i++) {
var i = 0;
for (i=0; i<length(snake); i++) {
if (snake[i].x == head.x && snake[i].y == head.y) {
gameState = "gameover"
return
@@ -81,10 +83,13 @@ this.update = function(dt) {
this.hud = function() {
// Optional clear screen
draw.rectangle({x:0, y:0, width:config.width, height:config.height}, [0,0,0,1])
// Draw snake
for (var i=0; i<length(snake); i++) {
var s = snake[i]
var i = 0;
var s = null;
var msg = null;
for (i=0; i<length(snake); i++) {
s = snake[i]
draw.rectangle({x:s.x*cellSize, y:s.y*cellSize, width:cellSize, height:cellSize}, color.green)
}
@@ -92,7 +97,7 @@ this.hud = function() {
draw.rectangle({x:apple.x*cellSize, y:apple.y*cellSize, width:cellSize, height:cellSize}, color.red)
if (gameState == "gameover") {
var msg = "GAME OVER! Press SPACE to restart."
msg = "GAME OVER! Press SPACE to restart."
draw.text(msg, {x:0, y:config.height*0.5-10, width:config.width, height:20}, null, 0, color.white)
}
}