rm push/pop

This commit is contained in:
2026-02-26 08:13:27 -06:00
parent ef7e3e6449
commit ce6b0ddb3a
31 changed files with 251 additions and 255 deletions

View File

@@ -47,8 +47,8 @@ function add_bunny(x, y) {
anchor_x: 0.5, anchor_y: 0.5,
plane: 'game'
})
push(bunnies, bunny)
push(bunny_sprites, s)
bunnies[] = bunny
bunny_sprites[] = s
}
// Initial bunnies

View File

@@ -29,14 +29,14 @@ function init(grid) {
row = []
for (bx = 0; bx < 8; bx++) {
col = ((bx + by) & 1) ? dark_color : light_color
push(row, shape.rect({
row[] = shape.rect({
pos: {x: bx * S + S / 2, y: by * S + S / 2},
width: S, height: S,
fill: {r: col.r, g: col.g, b: col.b, a: col.a},
plane: 'game', layer: 0
}))
})
}
push(board_shapes, row)
board_shapes[] = row
}
next_id = 0

View File

@@ -49,7 +49,7 @@ function compute_valid_moves(from) {
dest = grid.at(to)
if (length(dest) && dest[0].colour == piece.colour) continue
if (rules.canMove(piece, from, to, grid))
push(validMoves, to)
validMoves[] = to
}
}
}

View File

@@ -77,7 +77,7 @@ function compute_valid_moves(from) {
dest = grid.at(to)
if (length(dest) && dest[0].colour == piece.colour) continue
if (rules.canMove(piece, from, to, grid))
push(validMoves, to)
validMoves[] = to
}
}
}

View File

@@ -32,7 +32,7 @@ var grid_prototype = {
// add an entity into a cell
add(entity, pos) {
var cx = px(pos), cy = py(pos);
push(this.cell(cx, cy), entity);
this.cell(cx, cy)[] = entity;
entity.coord = [cx, cy];
},

View File

@@ -91,7 +91,7 @@ function compute_valid_moves(from) {
dest = grid.at(to)
if (length(dest) && dest[0].colour == piece.colour) continue
if (rules.canMove(piece, from, to, grid))
push(validMoves, to)
validMoves[] = to
}
}
}

View File

@@ -91,12 +91,12 @@ function reset_game() {
var cy = floor(gridH / 2)
var wp = null
for (i = 0; i < 3; i++) {
push(snake_pos, {x: cx - i, y: cy})
snake_pos[] = {x: cx - i, y: cy}
wp = grid_to_world(cx - i, cy)
push(snake_shapes, shape.rect({
snake_shapes[] = shape.rect({
pos: {x: wp.x, y: wp.y}, width: cellSize - 2, height: cellSize - 2,
fill: {r: 0, g: 1, b: 0.3, a: 1}, plane: 'game'
}))
})
}
dir = {x: 1, y: 0}
@@ -166,7 +166,7 @@ core.start({
var old_wp = grid_to_world(snake_pos[0].x, snake_pos[0].y)
var new_wp = grid_to_world(hx, hy)
var new_pos = [{x: hx, y: hy}]
for (i = 0; i < length(snake_pos); i++) push(new_pos, snake_pos[i])
for (i = 0; i < length(snake_pos); i++) new_pos[] = snake_pos[i]
snake_pos = new_pos
var head = shape.rect({
pos: {x: old_wp.x, y: old_wp.y}, width: cellSize - 2, height: cellSize - 2,
@@ -175,7 +175,7 @@ core.start({
// Smooth tween from old position to new position
tw.tween(head.pos).to({x: new_wp.x, y: new_wp.y}, move_interval).ease(ease.linear)
var new_shapes = [head]
for (i = 0; i < length(snake_shapes); i++) push(new_shapes, snake_shapes[i])
for (i = 0; i < length(snake_shapes); i++) new_shapes[] = snake_shapes[i]
snake_shapes = new_shapes
// Eat apple?
@@ -185,9 +185,9 @@ core.start({
spawn_apple()
} else {
// Remove tail
tail = pop(snake_shapes)
tail = snake_shapes[]
tail.destroy()
pop(snake_pos)
snake_pos[]
}
},

View File

@@ -50,16 +50,16 @@ function init_board() {
row = []
srow = []
for (c = 0; c < COLS; c++) {
push(row, null)
push(srow, shape.rect({
row[] = null
srow[] = shape.rect({
pos: {x: c * TILE + TILE / 2, y: r * TILE + TILE / 2},
width: TILE - 1, height: TILE - 1,
fill: {r: 0.5, g: 0.5, b: 0.5, a: 1},
plane: 'game', layer: 0, visible: false
}))
})
}
push(board, row)
push(board_shapes, srow)
board[] = row
board_shapes[] = srow
}
}
@@ -104,10 +104,10 @@ var next_label = text2d({
var next_shapes = []
var ns = 0
for (ns = 0; ns < 4; ns++) {
push(next_shapes, shape.rect({
next_shapes[] = shape.rect({
pos: {x: 0, y: 0}, width: TILE - 1, height: TILE - 1,
fill: {r: 1, g: 1, b: 1, a: 1}, plane: 'game', layer: 2, visible: false
}))
})
}
function random_shape() {
@@ -244,10 +244,10 @@ function place_piece() {
// Create 4 shapes for active piece (layer 1 = on top of board)
var pi = 0
for (pi = 0; pi < 4; pi++) {
push(piece_shapes, shape.rect({
piece_shapes[] = shape.rect({
pos: {x: 0, y: 0}, width: TILE - 1, height: TILE - 1,
fill: {r: 1, g: 1, b: 1, a: 1}, plane: 'game', layer: 1, visible: false
}))
})
}
init_board()