rm new
This commit is contained in:
@@ -12,11 +12,11 @@ var startingPos = use('pieces').startingPosition;
|
|||||||
var rules = use('rules');
|
var rules = use('rules');
|
||||||
|
|
||||||
/*──── build board ───────────────────────────────────────────────────*/
|
/*──── build board ───────────────────────────────────────────────────*/
|
||||||
var grid = new Grid(8, 8);
|
var grid = Grid(8, 8);
|
||||||
grid.width = 8; // (the ctor didn't store them)
|
grid.width = 8; // (the ctor didn't store them)
|
||||||
grid.height = 8;
|
grid.height = 8;
|
||||||
|
|
||||||
var mover = new MovementSystem(grid, rules);
|
var mover = MovementSystem(grid, rules);
|
||||||
startingPos(grid);
|
startingPos(grid);
|
||||||
|
|
||||||
/*──── networking and game state ─────────────────────────────────────*/
|
/*──── networking and game state ─────────────────────────────────────*/
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
function grid(w, h) {
|
function grid(w, h) {
|
||||||
this.width = w;
|
var newgrid = meme(grid_prototype)
|
||||||
this.height = h;
|
newgrid.width = w;
|
||||||
|
newgrid.height = h;
|
||||||
// create a height×width array of empty lists
|
// create a height×width array of empty lists
|
||||||
this.cells = array(h);
|
newgrid.cells = array(h);
|
||||||
for (var y = 0; y < h; y++) {
|
for (var y = 0; y < h; y++) {
|
||||||
this.cells[y] = array(w);
|
newgrid.cells[y] = array(w);
|
||||||
for (var x = 0; x < w; x++) {
|
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)
|
// return the array at (x,y)
|
||||||
cell(x, y) {
|
cell(x, y) {
|
||||||
return this.cells[y][x];
|
return this.cells[y][x];
|
||||||
@@ -66,4 +68,6 @@ grid.prototype = {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
return grid
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
var MovementSystem = function(grid, rules) {
|
function MovementSystem(grid, rules) {
|
||||||
this.grid = grid;
|
var newmover = meme(MovementSystem_prototype)
|
||||||
this.rules = rules || {}; // expects { canMove: fn }
|
newmover.grid = grid;
|
||||||
this.turn = 'white';
|
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;
|
if (piece.colour != this.turn) return false;
|
||||||
|
|
||||||
// normalise ‘to’ into our hybrid coord
|
// normalise ‘to’ into our hybrid coord
|
||||||
@@ -27,6 +30,6 @@ MovementSystem.prototype.tryMove = function (piece, to) {
|
|||||||
|
|
||||||
this.turn = (this.turn == 'white') ? 'black' : 'white';
|
this.turn = (this.turn == 'white') ? 'black' : 'white';
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
return { MovementSystem: MovementSystem };
|
return MovementSystem
|
||||||
|
|||||||
@@ -154,9 +154,7 @@ function load_from_cloud() {
|
|||||||
|
|
||||||
var data = steam.cloud.cloud_read("savegame.json");
|
var data = steam.cloud.cloud_read("savegame.json");
|
||||||
if (data) {
|
if (data) {
|
||||||
// Convert ArrayBuffer to string
|
var json_str = text(data)
|
||||||
var decoder = new TextDecoder();
|
|
||||||
var json_str = decoder.decode(data);
|
|
||||||
return JSON.parse(json_str);
|
return JSON.parse(json_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ graphics.texture = function texture(path) {
|
|||||||
var idx = number(frameIndex)
|
var idx = number(frameIndex)
|
||||||
if (idx == null) return cached
|
if (idx == null) return cached
|
||||||
// Wrap the index
|
// Wrap the index
|
||||||
idx = idx % cached.frames.length
|
idx = idx % length(cached.frames)
|
||||||
return cached.frames[idx].image
|
return cached.frames[idx].image
|
||||||
}
|
}
|
||||||
// If cached is a single Image, any frame index just returns the 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)
|
var idx = number(frameIndex)
|
||||||
if (isNaN(idx)) return cached
|
if (isNaN(idx)) return cached
|
||||||
// Wrap the index
|
// Wrap the index
|
||||||
idx = idx % cached.frames.length
|
idx = idx % length(cached.frames)
|
||||||
return cached.frames[idx].image
|
return cached.frames[idx].image
|
||||||
}
|
}
|
||||||
// Just animation name for single animation - return the animation
|
// Just animation name for single animation - return the animation
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ var transform = use('transform');
|
|||||||
|
|
||||||
var camera = {
|
var camera = {
|
||||||
size: [500,500],
|
size: [500,500],
|
||||||
transform: new transform,
|
|
||||||
fov:50,
|
fov:50,
|
||||||
near_z: 0,
|
near_z: 0,
|
||||||
far_z: 1000,
|
far_z: 1000,
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ render.initialize({
|
|||||||
|
|
||||||
var camera = {
|
var camera = {
|
||||||
size: [500,500],
|
size: [500,500],
|
||||||
transform: new transform,
|
|
||||||
fov:50,
|
fov:50,
|
||||||
near_z: 0,
|
near_z: 0,
|
||||||
far_z: 1000,
|
far_z: 1000,
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ var draw = use('draw2d')
|
|||||||
|
|
||||||
var camera = {
|
var camera = {
|
||||||
size: [500,500],
|
size: [500,500],
|
||||||
transform: new transform,
|
|
||||||
fov:50,
|
fov:50,
|
||||||
near_z: 0,
|
near_z: 0,
|
||||||
far_z: 1000,
|
far_z: 1000,
|
||||||
@@ -27,7 +26,6 @@ var camera = {
|
|||||||
|
|
||||||
var hudcam = {
|
var hudcam = {
|
||||||
size: [500,500],
|
size: [500,500],
|
||||||
transform: new transform,
|
|
||||||
fov:50,
|
fov:50,
|
||||||
near_z: 0,
|
near_z: 0,
|
||||||
far_z: 1000,
|
far_z: 1000,
|
||||||
@@ -51,7 +49,6 @@ function loop()
|
|||||||
{
|
{
|
||||||
var now = os.now()
|
var now = os.now()
|
||||||
pos.x += dt*100
|
pos.x += dt*100
|
||||||
camera.transform.pos = pos
|
|
||||||
render.clear([22/255,120/255,194/255,255/255])
|
render.clear([22/255,120/255,194/255,255/255])
|
||||||
render.camera(camera)
|
render.camera(camera)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user