all repos — uStrat @ b5ad37942002dfb19f2173c64cb203ba7fbcc3d7

simple turn-based strategy game inspired by uCity, Super Robot Wars, C&C, Fire Emblem

fix movement
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmDO0iMACgkQO3+8IhRO
Y5hC+hAAk2uNzQbQlU1AZ1nMJghbDYbl+ET+rGtqomBXwmVPXtjj7eK0Ucsq27Pi
bF2IE/pEjFQcu/aCmSCyu4g3V/jw7SWZmW9Ns9UMCRrAtvQ9qr3X4jpFIRkyfj7E
GMGuzpL/+EgJfonbU5u4s5sk+Y1NKuWxiftxNIhqj5e8pwT7+XfOy2YRhUt3t9eS
HockoIDclTHT11c7Y2Sn25O1yr9yhXOLz2zsoqNHpu0L4c1MeN89pYGsiV3L0Ywr
+TzkArnvIFHUs85HYDoBA5AkOe/pY5vHPv4C2ztfDMjdp+zRN08/wW4s/HdfUtT7
6O5p25FrW1RLvI9XkhTVpt0deLKjAkUw+WjstWEJZemfJ01o+zAajWmJrlqeB1tF
rOn8QfbQqTPD6jyaCpOk2mJAaYgE3csClQ6IGZxquWQSyJDl8z0L6HfGdaPLtE5U
0zIBH9GdpmdtQrzxWkX/8qC42b0eIGgtqBHBLJAwR68RY8uOcAOjte2kpiX64PzX
3tEuIgY/VEudbAhnYjzDrdlNwqRlWP/LnF5TfrwdNmcWH++DG1x1v22iS77gyQgV
G1Cuodd8Fjhb5HHa7jAyuI2iyYXa0s5Sm+kZVgIvoxs64LTZXk6g88HNaRtlcz0w
s5sXCit88mY8zwHkTuNgLD6929qeGPSlu46OZJesr7WIw0yup8g=
=lGDI
-----END PGP SIGNATURE-----
commit

b5ad37942002dfb19f2173c64cb203ba7fbcc3d7

parent

1a0e7e5e1a5b145474e33f81a8bf389ee7decad5

1 files changed, 26 insertions(+), 25 deletions(-)

jump to
M Movement.jsMovement.js

@@ -5,7 +5,7 @@ // animation

window.movement = {}; movement.chain = new Array(); -movement.unit = {}; +movement.unit = null; movement.pool = 0; movement.animCounter = 0; movement.gfx = {};

@@ -23,47 +23,47 @@ }

movement.init = function(u) { - this.unit = u; - this.pool = u.agi; - this.chain.push(new Coords(u.x, u.y)); + movement.unit = u; + movement.pool = u.agi; + movement.chain.push(new Coords(u.x, u.y)); } movement.cancel = function() { - this.unit = {}; - this.pool = 0; - this.chain = new Array(); + movement.unit = null; + movement.pool = 0; + movement.chain = new Array(); gameState.flow = "freeLook"; } movement.listen = function() { var z = null; - var chainEnd = this.chain[this.chain.length - 1]; - this.ticker = new Date(); + var chainEnd = this.chain[movement.chain.length - 1]; + movement.ticker = new Date(); if (controller.z) { while (this.chain.length > 1) { - this.chain.pop(); - this.pool = this.unit.agi; - mapCursor.x = this.chain[0].x; - mapCursor.y = this.chain[0].y; + movement.chain.pop(); + movement.pool = this.unit.agi; + mapCursor.x = movement.chain[0].x; + mapCursor.y = movement.chain[0].y; } } if (controller.x) { - this.cancel(); + movement.cancel(); return; } if (controller.y) { - this.confirm(); + movement.confirm(); return; } - if (this.ticker - this.lastMove >= 200) + if (movement.ticker - movement.lastMove >= 200) { if (controller.up)

@@ -85,18 +85,19 @@ if (controller.right)

{ z = new Coords(chainEnd.x + 1, chainEnd.y); } - this.lastMove = this.ticker; + movement.lastMove = movement.ticker; } if (z !== null) { - if (map.data[z.x][z.y].agiMod <= this.pool && z.x >= 0 && z.x < map.sz && z.y >= 0 && z.y < map.sz && map.data[z.x][z.y].unit === null) + if (map.data[z.x][z.y].agiMod <= movement.pool && z.x >= 0 && z.x < map.sz && z.y >= 0 && z.y < map.sz && map.data[z.x][z.y].unit === null) { - if (this.unit.name != "p1 Battle Angel") + if (movement.unit.name != "p1 Battle Angel") { - this.pool -= map.data[z.x][z.y].agiMod + 1; + movement.pool -= map.data[z.x][z.y].agiMod + 1; } - else { this.pool -= 1; } - this.chain.push(z); + else { movement.pool -= 1; } + movement.chain.push(z); + console.dir(movement.chain); mapCursor.x = z.x; mapCursor.y = z.y; }

@@ -111,7 +112,7 @@ screen.textBaseline = "top";

screen.fillStyle = "white"; for (c = 0; c < this.chain.length; c++) { - screen.drawImage(this.gfx.overlay, 16*(this.chain[c].x - camera.x), 16*(this.chain[c].y - camera.y)); + screen.drawImage(movement.gfx.overlay, 16*(movement.chain[c].x - camera.x), 16*(movement.chain[c].y - camera.y)); } }

@@ -145,9 +146,9 @@ AI.focus++;

gameState.flow = "cpuMoveDone"; } return; } - if (movement.chain.length > 0 && movement.unit.target != undefined) + if (movement.chain.length > 0){ moveToTile(movement.unit, movement.chain[0]); - else{ + }else{ movement.unit.hasMoved = true; movement.unit = null; movement.chain = new Array();