all repos — uStrat @ adaa55d3d507e7d4c69229a0dd4c61adaa346d73

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

debugged attack/equipment code; all is good
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQJDBAABCAAtFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAl0C95cPHG5pbGl4QG5p
bGZtLmNjAAoJEDt/vCIUTmOYeAMP/0nNaDvmBIqOgyKTNoXkFvohxU6mQFyMYN2g
DkU26r08iCroKgqI9u++6yhYCa/pTMRhz56UeMDO49bx4CAdZGz+KlleQdIJyvP8
SqUCr4riDRhrYutPcWzim8KIKHmw/Lz0d9SeWPXPkCc+dZJFR4+f/3mMXj0DLSXc
G+EygO7qeqyWvwFhDIsZUY9VUfzoiIDznRAi2pxD2nPXATBIddO4WDKzFec6RWa8
5oG0laBcqpjkgc9/yi3UxU5jCDuqi7u46qEyvBDeoFbEo3mHoHes0nu+KdUhTM0d
1MGdhvHrQ95vQko4uJuVm0CZM0D/dH16ZyVYvM+fjPJaj2SUIBDND/r5de8cBXCV
2UuNa88OAe4hIXcmWZowVHTYhO4aexxaMykKur9aWCnHGsRlSO21zGs2/lVDVBP0
VodfI3aIZ00p8YoUL3Tmvzw2c0+7A2bjAztSSy2jj81tpj8k3+/jKztpZ6JhYV8h
nhIfQUFijPjASP9yijrjh/rFzS5IMfbwJoIuHfVdSBhKnU3t9gQLZTToW6Lzkxg/
cVAU8wcQgcovttT5TC49pEfGcRihsZjcV3dYJiXowzoJE0Vi5rAunrSRqpE0yeCB
agjlba17Im4jGe6nbHHAHY1jDTq54qqq7SyJgyL+7lko4zxG1LxZnGzF1yvXF/w3
TqGRzjE8
=JHnW
-----END PGP SIGNATURE-----
commit

adaa55d3d507e7d4c69229a0dd4c61adaa346d73

parent

9967a8938dae7795296c0ae7aa1692e3452b3ff7

8 files changed, 162 insertions(+), 31 deletions(-)

jump to
M Attack.jsAttack.js

@@ -8,6 +8,10 @@ attack.gfx = {};

attack.gfx.overlay = new Image() attack.gfx.overlay.src = "assets/ui/attackOverlay.png"; attack.gfx.explosion = new Image() +attack.gfx.explosion.src = "assets/fx/explosion.png"; + +attack.animCounter = 0; +attack.frame = 0; attack.init = function() {

@@ -33,6 +37,35 @@ var origin = {};

var i, j; origin.x = mapCursor.x - 2; origin.y = mapCursor.y - 2; + this.animCounter++; + for (i = 0; i < 5; i++) + { + for (j = 0; j < 5; j++) + { + if (pattern[i][j] != 0) + { + screen.drawImage(this.gfx.explosion, this.frame*16, 0, 16, 16, 16*(origin.x + i - camera.x), 16*(origin.y + j - camera.y), 16, 16); + if (this.animCounter == 3 && this.frame == 2) + { + damageStruct(origin.x + i, origin.y + j); + damageUnit(origin.x + i, origin.y + j); + map.degradeCell(map.data[origin.x + i][origin.y + j]); + } + } + } + } + if (this.animCounter == 3) + { + this.frame++; + this.animCounter = 0; + } + if (this.frame == 3) + { + this.frame = 0; + this.animCounter = 0; + this.src.hasAttacked = true; + gameState.flow = "attackEnd"; + } } attack.listen = function()

@@ -192,4 +225,5 @@ }

} } } -}+} +
M Engine.jsEngine.js

@@ -76,6 +76,7 @@ if (tm.energy >= totalE) tm.energy = totalE;

for (i = 0; i < tm.units.length; i++) { tm.units[i].hasMoved = false; + tm.units[i].hasAttacked = false; } }

@@ -128,6 +129,25 @@ attack.drawPattern();

mapCursor.draw(); } +function attackAnim() +{ + map.draw(); + attack.go(); +} + +function attackEnd() +{ + switch (gameState.phase) + { + case "cpu": + gameState.flow = "cpuManageUnits"; + break; + case "p1": + gameState.flow = "freeLook"; + break; + } +} + function loop() { thisFrame = new Date();

@@ -159,8 +179,13 @@ case "moveAnim":

moveAnim(); break; case "attackSelect": + attackSelect(); + break; case "attackAnim": - attackSelect(); + attackAnim(); + break; + case "attackEnd": + attackEnd(); break; }
M Equipment.jsEquipment.js

@@ -185,21 +185,18 @@ {

if (unit.equipment.grade < unit.equipment.limit) { unit.equipment.grade++; + } + } switch(gameState.phase) { case "p1": teams.p1.energy -= unit.equipment.cost; + resetFlow(); break; case "cpu": teams.cpu.energy -= unit.equipment.cost; break; } - } - } - if (gameState.phase == "p1") - { - gameState.flow = "freeLook"; - } } function hellBomb()
M Map.jsMap.js

@@ -85,9 +85,13 @@ var equipString;

if (!isEmptyObject(currentCell.unit.equipment)) { equipString = currentCell.unit.equipment.name; + if (currentCell.unit.equipment.grade > 0) + { + equipString += " +" + currentCell.unit.equipment.grade + } } - else equipString = "none" - screen.fillText("equipment: " + equipString, 10, 110); + else equipString = "no equipment" + screen.fillText(equipString, 10, 110); } }
M Struct.jsStruct.js

@@ -212,4 +212,30 @@ mapCursor.x = self.x;

mapCursor.y = self.y; } return self; +} + +function damageStruct(x, y) +{ + if (isEmptyObject(map.data[x][y].unit) && !isEmptyObject(map.data[x][y].structure)) + { + map.data[x][y].structure.hp = map.data[x][y].structure.hp - (attack.src.pow + attack.src.equipment.grade); + if (map.data[x][y].structure.hp <= 0) + { + destroyStruct(x,y); + } + } +} + +function destroyStruct(x,y) +{ + var z, w, v; + if (map.data[x][y].struct.name.startsWith("p1")) + { + z = teams.p1; + v = "p1" + } + else { z = teams.cpu; v = "cpu"; } + w = z.structs.indexOf(map.data[x][y].structure) + z.structs.splice(w, 1); + map.data[x][y].struct = {}; }
M Team.jsTeam.js

@@ -35,4 +35,39 @@ case "cpu":

teams.cpu.energy -= item.cost; break; } +} + +function getIndex(player, type, obj) +{ + var x, y, z, i; + switch (player) + { + case "p1": + x = teams.p1; + break; + case "cpu": + x = teams.cpu; + break; + } + switch (type) + { + case "struct": + y = x.structs; + break; + case "unit": + y = x.units; + break; + } + i = 0; + for (z in y) + { + if (obj.x == z.x && obj.y == z.y) + { + return i; + } + i++; + } + // assuming you passed in valid arguments and a real object into this + // function, you should never return -1. + return -1; }
M Touch.jsTouch.js

@@ -1,3 +1,4 @@

+ function doNothing(e) { e.preventDefault();

@@ -91,27 +92,14 @@ releaseDown(e);

releaseRight(e); } -function pressQ(e) -{ - controller.q = true; - gameState.playing = false; - gameState.paused = false; - gameState.over = false; -} - -function releaseQ(e) -{ - controller.q = false; -} - function pressStart(e) { - controller.space = true; + controller.start = true; } function releaseStart(e) { - controller.space = false; + controller.start = false; } function pressW(e)

@@ -160,7 +148,6 @@

document.getElementById("dpad").style.visibility = "visible"; document.getElementById("facebuttons").style.visibility = "visible"; document.getElementById("startButton").style.visibility = "visible"; -document.getElementById("qButton").style.visibility = "visible"; window.dPad = {}; dPad.n = document.getElementById("upButton");

@@ -223,9 +210,5 @@ startButton.addEventListener("touchstart", pressStart);

startButton.addEventListener("touchend", releaseStart); startButton.addEventListener("touchcancel", releaseStart); -window.qButton = document.getElementById("qButton"); -qButton.addEventListener("touchstart", pressQ); -qButton.addEventListener("touchend", releaseQ); -qButton.addEventListener("touchcancel", releaseQ); }
M Unit.jsUnit.js

@@ -11,6 +11,7 @@ this.x = 0;

this.y = 0; this.cost = 30; this.hasMoved = false; + this.hasAttacked = false; this.name = ""; }

@@ -157,7 +158,7 @@ self.agi = 6;

self.cost = 300; self.x = x; self.y = y; - self.name = player + " Blitzwalker"; + self.name = player + " BlitzWalker"; map.data[x][y].unit = self; return self; }

@@ -177,3 +178,29 @@ teams.cpu.energy -= teams.cpu.units[teams.cpu.units.length - 1].cost;

break; } } + +function damageUnit(x,y) +{ + if (!isEmptyObject(map.data[x][y].unit)) + { + map.data[x][y].unit.hp = map.data[x][y].unit.hp - (attack.src.pow + attack.src.equipment.grade); + if (map.data[x][y].unit.hp <= 0) + { + destroyUnit(x,y); + } + } +} + +function destroyUnit(x,y) +{ + var z, w, v; + if (map.data[x][y].unit.name.startsWith("p1")) + { + z = teams.p1; + v = "p1"; + } + else { z = teams.cpu; v = "cpu"; } + w = z.units.indexOf(map.data[x][y].unit); + z.units.splice(w, 1); + map.data[x][y].unit = {}; +}