all repos — uStrat @ e130b5b6df964e5cf1ddf75bd25a980ea3d1f478

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

victory and defeat conditions and gameOver screens
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQJDBAABCAAtFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAl1ypNcPHG5pbGl4QG5p
bGZtLmNjAAoJEDt/vCIUTmOYNGsP/jVbu0GWbyBFvkiEDHI4vQJHn+F8rY/9B0uz
1ty7eiypBNWFAJHoqROoZQb0HlEjAZll0R1HLY+Td8PAHpQBN0waCxMUKhJUXaRW
fvhKG9bQdjD+U5Zv+cHon8gZqaNcPKnmiV5n23ttMgTTFe7qbM3zBuLD5X8Usjxp
B33rfFc2FbwhHuhq8oVKyAshdVcxfnhpQ3RjAyGeGqIyXPrAaIkelq2PWMy1x38u
+FfvDUPOcTw7LJGx5HVhARtgunl5O1ABmo812UD6PFDxk9+Fa0GmQG+rsFVghVe7
DwGmqptgeMHm4hl+iYtBiStyqESgzzMc6aWbuCwFaIe27d7ykR4sGc+ZqfO6qIr5
5UYm9i2Cl+5BRF9KE+PUyYcZjSJhFDCqsnoDZm8zvgN5vSimFEJvpeDuhZ83PxS3
Zd+qJR7hqcdt5sA+o2KpAAwkHVU7IacyvCD8PcRtHu7U83PBYI1LbA2AvmP0EcGt
yHudSk7Svlg7nN6xR+GXbDI79yxUpXE86HCkyOOkR8YANbRAuHtF0/B9ynVePBx8
xqFXcd0sxidIjv2G3UGgiR97+Yu9+j/TH7X1JVoxckXJ/XXALisdcj2Nh9Ew5kaI
QUTpAhKj16do7Q/E4IMy3Nvg0C18a2YmRaxDDQmscfHRwwK+QEwQ5Y2e7IaWHnZ9
zj3piYJE
=O0cW
-----END PGP SIGNATURE-----
commit

e130b5b6df964e5cf1ddf75bd25a980ea3d1f478

parent

bd7f6f259bff3b8151fb9ac19eb6092cf3cdf35d

5 files changed, 70 insertions(+), 19 deletions(-)

jump to
M AI.jsAI.js

@@ -73,7 +73,8 @@ A = -1;

j = 99999; for (i = 0; i < teams.cpu.structs.length; i++) { - if (teams.cpu.structs[i].name == "cpu armory") + if (teams.cpu.structs[i].name == "cpu armory" && + isEmptyObject(map.data[teams.cpu.structs[i].x][teams.cpu.structs[i].y].unit)) { k = dist(teams.cpu.structs[i], u); if (k < j)

@@ -138,7 +139,6 @@ break;

} while ((w.agiMod + 1 >= Math.sqrt(dist(movement.chain[movement.chain.length - 1], movement.unit.target))/2 && dist(movement.chain[movement.chain.length - 1], movement.unit.target) >= 10) || !isEmptyObject(w.unit)) { - i++; if (isEmptyObject(w.unit)) { // if agiMod of all panels surrounding unit are equal, just keep original path

@@ -148,7 +148,7 @@ w.agiMod == map.data[x][y + 1].agiMod &&

w.agiMod == map.data[x][y - 1].agiMod) { console.log(" surrounded by high-cost cells, going straight ahead anyway"); - continue; + break; } }

@@ -157,8 +157,7 @@ do

{ console.log(" trying to go another way"); q = z[AI.rand(4)]; - i++; - } while (q == k || q == AI.oppositeDir(last) || i <= 20); + } while (q == k || q == AI.oppositeDir(last)); switch (q) { case 'n':

@@ -335,6 +334,31 @@ }

} } break; + } +} + +AI.manageEqiupment = function() +{ + var i, j, k; + for (i = 0; i < teams.cpu.units.length; i++) + { + j = map.data[teams.cpu.units[i].x][teams.cpu.units[i].y]; + if (!isEmptyObject(j.structure) && j.structure.name == "cpu armory") + { + mapCursor.x = j.x; + mapCursor.y = j.y; + if (teams.cpu.energy >= 80) + { + k = AI.rand(4) + switch (k) + { + case 0: + case 1: + case 2: + case 3: + } + } + } } }
M Attack.jsAttack.js

@@ -64,7 +64,10 @@ {

this.frame = 0; this.animCounter = 0; this.src.hasAttacked = true; - gameState.flow = "attackEnd"; + if (gameState.flow != "youLose" && gameState.flow != "youWin") + { + gameState.flow = "attackEnd"; + } } }
M Engine.jsEngine.js

@@ -1,5 +1,7 @@

window.gameState = {}; window.controller = {}; +window.gameOverWindow = new Image(); +gameOverWindow.src = "assets/ui/gameOverWindow.png"; gameState.paused = false; gameState.playing = false;

@@ -178,17 +180,13 @@ }

function cpuGenTargets() { - var i; - for (i = 0; i < teams.cpu.units.length; i++) + if (isEmptyObject(teams.cpu.units[AI.focus].equipment)) { - if (isEmptyObject(teams.cpu.units[i].equipment)) - { - AI.assignTarget(teams.cpu.units[i], AI.getClosestArmory(teams.cpu.units[i]), "defend"); - } - else - { - AI.assignTarget(teams.cpu.units[i], map.data[16][16]); - } + AI.assignTarget(teams.cpu.units[AI.focus], AI.getClosestArmory(teams.cpu.units[AI.focus]), "defend"); + } + else + { + AI.assignTarget(teams.cpu.units[i], map.data[16][16]); } gameState.flow = "cpuPathGen"; }

@@ -225,7 +223,27 @@ {

AI.focus = 0; endPhase(); } - else gameState.flow = "cpuPathGen"; + else gameState.flow = "cpuGenTargets"; +} + +function loseScreen() +{ + map.draw(); + screen.drawImage(gameOverWindow, 0, 0); + screen.font = "24px console" + screen.textBaseline = "bottom"; + screen.fillStyle = "white"; + screen.fillText("Defeat", 90, 100); +} + +function winScreen() +{ + map.draw(); + screen.drawImage(gameOverWindow, 0, 0); + screen.font = "24px console" + screen.textBaseline = "bottom"; + screen.fillStyle = "white"; + screen.fillText("Victory", 90, 100); } function loop()

@@ -287,6 +305,12 @@ cpuMove();

break; case "cpuMoveDone": cpuMoveDone(); + break; + case "youWin": + winScreen(); + break; + case "youLose": + loseScreen(); break; }
M Struct.jsStruct.js

@@ -237,11 +237,11 @@ else { z = teams.cpu; }

w = z.structs.indexOf(map.data[x][y].structure); if (z.structs[w].name == "p1 HQ") { - gameState.flow == "youLose"; + gameState.flow = "youLose"; } if (z.structs[w].name == "cpu HQ") { - gameState.flow == "youWin"; + gameState.flow = "youWin"; } z.structs.splice(w, 1); map.data[x][y].structure = {};