This commit is contained in:
2026-01-20 08:36:55 -06:00
parent 6e78e8f9c2
commit 187879a7c6
8 changed files with 26 additions and 26 deletions

View File

@@ -12,11 +12,11 @@ var startingPos = use('pieces').startingPosition;
var rules = use('rules');
/*──── build board ───────────────────────────────────────────────────*/
var grid = new Grid(8, 8);
var grid = Grid(8, 8);
grid.width = 8; // (the ctor didn't store them)
grid.height = 8;
var mover = new MovementSystem(grid, rules);
var mover = MovementSystem(grid, rules);
startingPos(grid);
/*──── networking and game state ─────────────────────────────────────*/

View File

@@ -1,17 +1,19 @@
function grid(w, h) {
this.width = w;
this.height = h;
var newgrid = meme(grid_prototype)
newgrid.width = w;
newgrid.height = h;
// create a height×width array of empty lists
this.cells = array(h);
newgrid.cells = array(h);
for (var y = 0; y < h; y++) {
this.cells[y] = array(w);
newgrid.cells[y] = array(w);
for (var x = 0; x < w; x++) {
this.cells[y][x] = []; // each cell holds its own list
newgrid.cells[y][x] = []; // each cell holds its own list
}
}
return newgrid
}
grid.prototype = {
var grid_prototype = {
// return the array at (x,y)
cell(x, y) {
return this.cells[y][x];
@@ -66,4 +68,6 @@ grid.prototype = {
}
return out;
}
};
}
return grid

View File

@@ -1,10 +1,13 @@
var MovementSystem = function(grid, rules) {
this.grid = grid;
this.rules = rules || {}; // expects { canMove: fn }
this.turn = 'white';
function MovementSystem(grid, rules) {
var newmover = meme(MovementSystem_prototype)
newmover.grid = grid;
newmover.rules = rules || {}; // expects { canMove: fn }
newmover.turn = 'white';
return newmover
}
MovementSystem.prototype.tryMove = function (piece, to) {
var MovementSystem_prototype = {
tryMove: function (piece, to) {
if (piece.colour != this.turn) return false;
// normalise to into our hybrid coord
@@ -27,6 +30,6 @@ MovementSystem.prototype.tryMove = function (piece, to) {
this.turn = (this.turn == 'white') ? 'black' : 'white';
return true;
};
}
return { MovementSystem: MovementSystem };
return MovementSystem

View File

@@ -154,9 +154,7 @@ function load_from_cloud() {
var data = steam.cloud.cloud_read("savegame.json");
if (data) {
// Convert ArrayBuffer to string
var decoder = new TextDecoder();
var json_str = decoder.decode(data);
var json_str = text(data)
return JSON.parse(json_str);
}

View File

@@ -297,7 +297,7 @@ graphics.texture = function texture(path) {
var idx = number(frameIndex)
if (idx == null) return cached
// Wrap the index
idx = idx % cached.frames.length
idx = idx % length(cached.frames)
return cached.frames[idx].image
}
// If cached is a single Image, any frame index just returns the image
@@ -322,7 +322,7 @@ graphics.texture = function texture(path) {
var idx = number(frameIndex)
if (isNaN(idx)) return cached
// Wrap the index
idx = idx % cached.frames.length
idx = idx % length(cached.frames)
return cached.frames[idx].image
}
// Just animation name for single animation - return the animation

View File

@@ -49,7 +49,6 @@ var transform = use('transform');
var camera = {
size: [500,500],
transform: new transform,
fov:50,
near_z: 0,
far_z: 1000,

View File

@@ -14,7 +14,6 @@ render.initialize({
var camera = {
size: [500,500],
transform: new transform,
fov:50,
near_z: 0,
far_z: 1000,

View File

@@ -15,7 +15,6 @@ var draw = use('draw2d')
var camera = {
size: [500,500],
transform: new transform,
fov:50,
near_z: 0,
far_z: 1000,
@@ -27,7 +26,6 @@ var camera = {
var hudcam = {
size: [500,500],
transform: new transform,
fov:50,
near_z: 0,
far_z: 1000,
@@ -51,7 +49,6 @@ function loop()
{
var now = os.now()
pos.x += dt*100
camera.transform.pos = pos
render.clear([22/255,120/255,194/255,255/255])
render.camera(camera)