all repos — uStrat @ b91fdb49ec7308d4d8b43e7014dc997a499d848b

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

first commit
Iris Lightshard nilix@nilfm.cc
commit

b91fdb49ec7308d4d8b43e7014dc997a499d848b

72 files changed, 2528 insertions(+), 0 deletions(-)

jump to
A AI.js

@@ -0,0 +1,5 @@

+AI = {}; +AI.main = function() +{ + endPhase(); +}
A Attack.js

@@ -0,0 +1,195 @@

+window.attack = {}; +attack.pattern = {}; +attack.rotations = [ 0 ]; +attack.rotation = 0; +attack.src = {}; + +attack.gfx = {}; +attack.gfx.overlay = new Image() +attack.gfx.overlay.src = "assets/ui/attackOverlay.png"; +attack.gfx.explosion = new Image() + +attack.init = function() +{ + gameState.flow = "attackSelect"; + attack.src = map.data[mapCursor.x][mapCursor.y].unit; + attack.pattern = attack.src.equipment.pattern; +} + +attack.cancel = function() +{ + gameState.flow = "freeLook"; +} + +attack.confirm = function() +{ + gameState.flow = "attackAnim"; +} + +attack.go = function() +{ + var pattern = rotatePattern(this.pattern, this.rotations[this.rotation]); + var origin = {}; + var i, j; + origin.x = mapCursor.x - 2; + origin.y = mapCursor.y - 2; +} + +attack.listen = function() +{ + var backupCursor = + { + x: mapCursor.x, + y: mapCursor.y + }; + + if (controller.up || controller.down || controller.left || controller.right) + { + mapCursor.manage(); + } + if (dist(mapCursor, this.src) > this.src.equipment.range) + { + mapCursor.x = backupCursor.x; + mapCursor.y = backupCursor.y; + } + this.manageRotations(); + if (controller.w) + { + this.rotation++; + if (this.rotation == this.rotations.length) + { + this.rotation = 0; + } + } + if (controller.x) + { + attack.cancel(); + } + if (controller.y) + { + attack.confirm(); + } +} + +attack.manageRotations = function() +{ + if (mapCursor.x < this.src.x) + { + if (xDist(mapCursor, this.src) > yDist(mapCursor, this.src)) + { + this.rotations = [ 1 ]; + } + else if (xDist(mapCursor, this.src) < yDist(mapCursor, this.src)) + { + if (mapCursor.y < this.src.y) + { + this.rotations = [ 0 ]; + } + else { this.rotations = [ 2 ]; } + } + else + { + if (mapCursor.y < this.src.y) + { + this.rotations = [ 0, 1 ]; + } + else { this.rotations = [ 2, 1 ]; } + } + } + if (mapCursor.x > this.src.x) + { + if (xDist(mapCursor, this.src) > yDist(mapCursor, this.src)) + { + this.rotations = [ 3 ]; + } + else if (xDist(mapCursor, this.src) < yDist(mapCursor, this.src)) + { + if (mapCursor.y < this.src.y) + { + this.rotations = [ 0 ]; + } + else { this.rotations = [ 2 ]; } + } + else + { + if (mapCursor.y < this.src.y) + { + this.rotations = [ 0, 3 ]; + } + else { this.rotations = [ 3, 2 ]; } + } + } + if (mapCursor.y < this.src.y) + { + if (xDist(mapCursor, this.src) > yDist(mapCursor, this.src)) + { + if (mapCursor.x > this.src.x) + { + this.rotations = [ 0 ]; + } + else { this.rotations = [ 1 ]; } + } + else if (xDist(mapCursor, this.src) < yDist(mapCursor, this.src)) + { + this.rotations = [ 0 ]; + } + else + { + if (mapCursor.x < this.src.x) + { + this.rotations = [ 0, 1 ]; + } + else { this.rotations = [ 0, 3 ]; } + } + } + if (mapCursor.y > this.src.y) + { + if (xDist(mapCursor, this.src) > yDist(mapCursor, this.src)) + { + if (mapCursor.x > this.src.x) + { + this.rotations = [ 3 ]; + } + else { this.rotations = [ 1 ]; } + } + else if (xDist(mapCursor, this.src) < yDist(mapCursor, this.src)) + { + this.rotations = [ 2 ]; + } + else + { + if ( mapCursor.x > this.src.x) + { + this.rotations = [ 2, 3 ]; + } + else { this.rotations = [ 2, 1 ]; } + } + } + if (this.rotations.length == 1) + { + this.rotation = 0; + } +} + +attack.drawPattern = function() +{ + var pattern = rotatePattern(this.pattern, this.rotations[this.rotation]); + var i, j; + var origin = {} + origin.x = mapCursor.x - 2, + origin.y = mapCursor.y - 2; + console.log(this.rotations); + for (i = 0; i < 5; i++) + { + for (j = 0; j < 5; j++) + { + if (pattern[i][j] != 0) + { + if (mapCursor.x != this.src.x || mapCursor.y != this.src.y) + { + screen.drawImage(this.gfx.overlay, 16*(origin.x + i - camera.x), 16*(origin.y + j - camera.y)); + } + } + } + } +}
A Engine.js

@@ -0,0 +1,170 @@

+window.gameState = {}; +window.controller = {}; + +gameState.paused = false; +gameState.playing = false; +gameState.over = false; +gameState.ruin = 0; +gameState.phase = "p1"; +gameState.flow = "freeLook"; + +gameState.ticker = new Date(); +gameState.frame = new Date(); + +controller.up = false; +controller.down = false; +controller.right = false; +controller.left = false; +controller.start = false; +controller.q = false; +controller.w = false; +controller.x = false; +controller.y = false; +controller.z = false; + +function isEmptyObject(obj) +{ + var name; + for (name in obj) + { + if (obj.hasOwnProperty(name)) + { + return false; + } + } + return true; +} + +function dist(a, b) +{ + return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2)); +} + +function xDist(a, b) +{ + return Math.abs(a.x - b.x); +} + +function yDist(a, b) +{ + return Math.abs(a.y - b.y); +} + +function endPhase() +{ + var i, totalE, tm; + totalE = 0; + switch(gameState.phase) + { + case "p1": + tm = teams.p1; + gameState.phase = "cpu"; + resetFlow(); + break; + case "cpu": + tm = teams.cpu; + gameState.phase = "p1"; + resetFlow(); + break; + } + for (i = 0; i < tm.structs.length; i++) + { + totalE += tm.structs[i].energy; + tm.energy += tm.structs[i].energy*tm.structs[i].rate; + } + if (tm.energy >= totalE) tm.energy = totalE; + for (i = 0; i < tm.units.length; i++) + { + tm.units[i].hasMoved = false; + } +} + +function freeLook() +{ + mapCursor.manage(); + camera.manage(); + map.draw(); + mapCursor.draw(); + hud.draw(); +} + +function navigateMenu() +{ + menuSys.input(); + map.draw(); + mapCursor.draw(); + hud.draw(); + menuSys.draw(); +} + +function moveSelect() +{ + movement.listen(); + camera.manage(); + map.draw(); + movement.showChain(); + mapCursor.draw(); + hud.draw(); +} + +function moveAnim() +{ + movement.go(); + map.draw(); +} + +function miniMap() +{ + minimap.listen(); + map.draw(); + minimap.draw(); +} + +function attackSelect() +{ + attack.listen(); + map.draw(); + attack.drawPattern(); + mapCursor.draw(); +} + +function loop() +{ + thisFrame = new Date(); + if (thisFrame - gameState.frame < 33.34) + { + requestAnimationFrame(loop); + } + else + { + gameState.frame = thisFrame; + switch (gameState.flow) + { + case "freeLook": + freeLook(); + break; + case "miniMap": + miniMap(); + break; + case "mainMenu": + case "buildMenu": + case "fabricateMenu": + case "equipmentMenu": + navigateMenu(); + break; + case "moveUnit": + moveSelect(); + break; + case "moveAnim": + moveAnim(); + break; + case "attackSelect": + case "attackAnim": + attackSelect(); + break; + } + + requestAnimationFrame(loop); + } +} +
A Equipment.js

@@ -0,0 +1,218 @@

+function equipment() +{ + this.pattern = new Array(5); + var i; + for (i = 0; i < 5; i++) + { + this.pattern[i] = new Array(5); + } + this.range = 0; + this.cost = 0; + this.grade = 0; + this.limit = 5; + this.name = ""; +} + +function rotatePattern90deg(p) +{ + var rP, i, j; + + rP = new Array(5); + for (i = 0; i < 5; i++) + { + rP[i] = new Array(5); + + for (j = 0; j < 5; j++) + { + rP[i][j] = p[5 - j - 1][i]; + } + } + return rP; +} + +function rotatePattern(p, r) +{ + switch (r) + { + case 0: + return p; + break; + case 1: + return rotatePattern90deg(p); + break; + case 2: + return rotatePattern90deg(rotatePattern90deg(p)); + break; + case 3: + return rotatePattern90deg(rotatePattern90deg(rotatePattern90deg(p))); + break; + } +} + +function equipOrUpgradeBeamSabreMKI() +{ + var unit = map.data[mapCursor.x][mapCursor.y].unit; + if (unit.equipment.name != "Beam Sabre mkI") + { + unit.equipment = beamSabreMKI(); + } + else + { + 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; + } +} + +function beamSabreMKI() +{ + var self = new equipment(); + self.range = 1; + self.name = "Beam Sabre mkI"; + self.pattern = [[ 0, 0, 0, 0, 0 ], + [ 0, 0, 0, 0, 0 ], + [ 0, 0, 1, 0, 0 ], + [ 0, 0, 0, 0, 0 ], + [ 0, 0, 0, 0, 0 ]]; + console.log(self.pattern); + self.cost = 15; + self.limit = 5; + return self; +} + +function equipOrUpgradeRifleMKI() +{ + var unit = map.data[mapCursor.x][mapCursor.y].unit; + if (unit.equipment.name != "Rifle mkI") + { + unit.equipment = rifleMKI(); + } + else + { + 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; + } +} + +function rifleMKI() +{ + var self = new equipment(); + self.range = 4; + self.name = "Rifle mkI"; + self.pattern = [[ 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0], + [ 0, 0, 1, 0, 0], + [ 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0]]; + self.cost = 12; + self.limit = 4; + return self; +} + +function equipOrUpgradeBeamCannon() +{ + var unit = map.data[mapCursor.x][mapCursor.y].unit; + if (unit.equipment.name != "Beam Cannon") + { + unit.equipment = beamCannon(); + } + else + { + 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; + } +} + +function beamCannon() +{ + var self = new equipment(); + self.range = 5; + self.name = "Beam Cannon"; + self.pattern = [[ 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0], + [ 1, 1, 1, 0, 0], + [ 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0]]; + self.cost = 45; + self.limit = 7; + return self; +} + +function equipOrUpgradeHellBomb() +{ + var unit = map.data[mapCursor.x][mapCursor.y].unit; + if (unit.equipment.name != "Hell Bomb") + { + unit.equipment = hellBomb(); + } + else + { + if (unit.equipment.grade < unit.equipment.limit) + { + unit.equipment.grade++; + switch(gameState.phase) + { + case "p1": + teams.p1.energy -= unit.equipment.cost; + break; + case "cpu": + teams.cpu.energy -= unit.equipment.cost; + break; + } + } + } + if (gameState.phase == "p1") + { + gameState.flow = "freeLook"; + } +} + +function hellBomb() +{ + var self = new equipment(); + self.range = 7; + self.name = "Hell Bomb"; + self.pattern = [[ 0, 0, 0, 0, 0], + [ 0, 1, 1, 1, 0], + [ 0, 1, 1, 1, 0], + [ 0, 1, 1, 1, 0], + [ 0, 0, 0, 0, 0]]; + self.cost = 80; + self.limit = 10; + return self; +}
A Keyboard.js

@@ -0,0 +1,94 @@

+document.addEventListener("keydown", pressHandler, false); +document.addEventListener("keyup", releaseHandler, false); + +function pressHandler(e) +{ + switch (e.key) + { + case "Right": + case "ArrowRight": + controller.right = true; + break; + case "Left": + case "ArrowLeft": + controller.left = true; + if (!gameState.paused) + break; + case "Up": + case "ArrowUp": + controller.up = true; + break; + case "Down": + case "ArrowDown": + controller.down = true; + break; + case "z": + controller.x = true; + break; + case "x": + controller.y = true; + break; + case "a": + controller.w = true; + break; + case "s": + controller.z = true; + break; + case "q": + controller.q = true; + gameState.playing = false; + gameState.paused = false; + gameState.over = false; + break; + case " ": + case "Spacebar": + controller.start = true; + break; + default: + console.log("That key doesn't do anything!"); + } +} + +function releaseHandler(e) +{ + switch (e.key) + { + case "Right": + case "ArrowRight": + controller.right = false; + break; + case "Left": + case "ArrowLeft": + controller.left = false; + break; + case "Up": + case "ArrowUp": + controller.up = false; + break; + case "Down": + case "ArrowDown": + controller.down = false; + break; + case "z": + controller.x = false; + break; + case "x": + controller.y = false; + break; + case "s": + controller.z = false; + break; + case "a": + controller.w = false; + break; + case "q": + controller.q = false; + break; + case " ": + case "Spacebar": + controller.start = false; + break; + default: + break; + } +}
A Map.js

@@ -0,0 +1,549 @@

+window.map = {}; +map.sz = 64; +map.gfx = {}; + + +window.camera = {}; +camera.x = 0; +camera.y = 0; + +window.hud = {}; +hud.gfx = {}; +hud.gfx.terrainWindow = new Image(); +hud.gfx.terrainWindow.src = "assets/ui/terrainWindow.png"; +hud.gfx.structWindow = new Image(); +hud.gfx.structWindow.src = "assets/ui/structWindow.png"; +hud.gfx.cycleModes = new Array(4); +hud.gfx.cycleModes[0] = new Image(); +hud.gfx.cycleModes[0].src = "assets/ui/cycleMode0.png" +hud.gfx.cycleModes[1] = new Image(); +hud.gfx.cycleModes[1].src = "assets/ui/cycleMode1.png" +hud.gfx.cycleModes[2] = new Image(); +hud.gfx.cycleModes[2].src = "assets/ui/cycleMode2.png" +hud.gfx.cycleModes[3] = new Image(); +hud.gfx.cycleModes[3].src = "assets/ui/cycleMode3.png" + +camera.manage = function() +{ + if (mapCursor.x < this.x) { this.x = mapCursor.x; } + if (mapCursor.x > this.x + 19) { this.x = mapCursor.x - 19; } + if (mapCursor.y < this.y) { this.y = mapCursor.y; } + if (mapCursor.y > this.y + 10) { this.y = mapCursor.y - 10; } + if (this.x < 0) { this.x = 0; } + if (this.x > map.sz - 20) { this.x = map.sz - 20; } + if (this.y < 0) { this.y = 0; } + if (this.y > map.sz - 11) { this.y = map.sz - 11; } +} + +camera.centerOnCursor = function() +{ + this.x = (mapCursor.x - 10); + this.y = (mapCursor.y - 5); + if (this.x < 0) { this.x = 0; } + if (this.x > map.sz - 20) { this.x = map.sz - 20; } + if (this.y < 0) { this.y = 0; } + if (this.y > map.sz - 11) { this.y = map.sz - 11; } + +} + +hud.draw = function() +{ + currentCell = map.data[mapCursor.x][mapCursor.y] + screen.drawImage(hud.gfx.terrainWindow, 5, 5) + screen.font = "8px console"; + screen.textBaseline = 'top'; + screen.fillStyle = "white"; + screen.fillText(mapCursor.x + ", " + mapCursor.y, 10, 10); + screen.fillText(currentCell.type, 10, 20); + screen.fillText("def+" + currentCell.defMod, 10, 30); + screen.fillText("agi-" + currentCell.agiMod, 10, 40); + + screen.fillText(gameState.phase + " phase", 240, 10); + screen.fillText("ruin: " + gameState.ruin, 240, 20); + screen.fillText("E: " + teams.p1.energy + "/" + teams.cpu.energy, 240, 30); + screen.fillText("S: " + teams.p1.structs.length + "/" + teams.cpu.structs.length, 240, 40); + screen.fillText("U: " + teams.p1.units.length + "/" + teams.cpu.units.length, 240, 50); + + screen.drawImage(hud.gfx.cycleModes[mapCursor.cycleMode], 85, 5); + + if (!isEmptyObject(currentCell.structure)) + { +// screen.drawImage(hud.gfx.structWindow, 5, 135); + screen.fillText(currentCell.structure.name, 10, 140); + screen.fillText("HP: " + currentCell.structure.hp + "/" + currentCell.structure.maxHP, 10, 150); + screen.fillText("E: " + currentCell.structure.energy + "@" + currentCell.structure.rate, 10, 160); + } + + if (!isEmptyObject(currentCell.unit)) + { + screen.fillText(currentCell.unit.name, 10, 60); + screen.fillText("HP: " + currentCell.unit.hp + "/" + currentCell.unit.maxHP, 10, 70); + screen.fillText("pow: " + currentCell.unit.pow, 10, 80); + screen.fillText("def: " + currentCell.unit.def, 10, 90); + screen.fillText("agi: " + currentCell.unit.agi, 10, 100); + var equipString; + if (!isEmptyObject(currentCell.unit.equipment)) + { + equipString = currentCell.unit.equipment.name; + } + else equipString = "none" + screen.fillText("equipment: " + equipString, 10, 110); + } + +} + + +window.mapCursor = {} +mapCursor.sprite = new Image(); +mapCursor.sprite.src = "assets/ui/mapCursor.png" +mapCursor.x = 0; +mapCursor.y = 0; +mapCursor.ticker = new Date(); +mapCursor.lastMove = new Date(); +mapCursor.cycleMode = 0; +mapCursor.metaCycle = function () +{ + this.cycleMode++; + if (this.cycleMode == 4) + { + this.cycleMode = 0; + } + controller.z = false; +} + +mapCursor.manage = function() +{ + this.ticker = new Date(); + if (this.ticker - this.lastMove >= 200) + { + if (controller.up){ this.y--; this.lastMove = this.ticker; +} + if (controller.down){ this.y++; this.lastMove = this.ticker; +} + if (controller.left){ this.x--; this.lastMove = this.ticker; +} + if (controller.right){ this.x++; this.lastMove = this.ticker; +} + + if (gameState.flow == "freeLook") + { + if (controller.w) { this.cycle(); } + if (controller.z) { this.metaCycle(); } + if (controller.y) { generateMainMenu(); } + if (controller.start) { gameState.flow = "miniMap" ; controller.start = false;} + } + if (this.x < 0) { this.x = 0; } + if (this.x > map.sz - 1) { this.x = map.sz - 1; } + if (this.y < 0) { this.y = 0; } + if (this.y > map.sz - 1) { this.y = map.sz - 1; } + } +} + +mapCursor.cycle = function() +{ + var i; + var arr; + + switch (this.cycleMode) + { + case 0: + arr = teams.p1.structs; + break; + case 1: + arr = teams.p1.units; + break; + case 2: + arr = teams.cpu.structs; + break; + case 3: + arr= teams.cpu.units; + break; + } + + console.log(arr.length); + if (arr.length == 0) return; + for (i = 0; i < arr.length; i++) + { + if (this.x == arr[i].x && this.y == arr[i].y) + { + if (i + 1 < arr.length) + { + i++; + } + else{ i = 0;} + this.x = arr[i].x; + this.y = arr[i].y; + controller.w = false; + this.manage(); + camera.centerOnCursor(); + return; + } + } + this.x = arr[0].x; + this.y = arr[0].y; + controller.w = false; + this.manage(); + camera.centerOnCursor(); +} + +mapCursor.draw = function() +{ + screen.drawImage(mapCursor.sprite, (mapCursor.x - camera.x)*16, (mapCursor.y - camera.y)*16); +} + +map.loadTiles = function() +{ + map.gfx.mapTiles = {}; + var tiles = map.gfx.mapTiles; + tiles.plain = new Image(); + tiles.plain.src = 'assets/mapbg/plain.png'; + tiles.forest = new Image(); + tiles.forest.src = 'assets/mapbg/forest.png'; + tiles.ocean = new Image(); + tiles.ocean.src = 'assets/mapbg/ocean.png'; + tiles.city = new Image(); + tiles.city.src = 'assets/mapbg/city.png'; + tiles.ruins = new Image(); + tiles.ruins.src = 'assets/mapbg/ruins.png' + tiles.mountain = new Image(); + tiles.mountain.src = 'assets/mapbg/mountain.png'; +} + + +map.cell = function() +{ + this.x = 0; + this.y = 0; + this.sprite = {}; + this.agiMod = 0; + this.defMod = 0; + this.flag = 0; + this.type = "null"; + this.structure = {}; + this.unit = {}; +} + +map.degradeCell = function(self) +{ + switch (self.type) + { + case "forest": + this.changeCell(self, "plain"); + break; + case "city": + this.changeCell(self, "ruins"); + break; + default: + break; + } +} + +map.changeCell = function(self, t) +{ + switch (t) + { + case "plain": + self.agiMod = 0; + self.defMod = 0; + self.sprite = map.gfx.mapTiles.plain; + break; + case "water": + self.agiMod = 0; + self.defMod = 0; + self.sprite = map.gfx.mapTiles.ocean; + self.flag = 1; + break; + case "mountain": + self.agiMod = 3; + self.defMod = 4; + self.sprite = map.gfx.mapTiles.mountain; + break; + case "city": + self.agiMod = 2; + self.defMod = 3; + self.sprite = map.gfx.mapTiles.city; + break; + case "ruins": + self.agiMod = 1; + self.defMod = 2; + self.sprite = map.gfx.mapTiles.ruins; + gameState.ruin += 1; + break; + case "forest": + self.agiMod = 1; + self.defMod = 1; + self.sprite = map.gfx.mapTiles.forest; + break; + } + self.type = t; +} + +map.init = function() +{ + map.data = new Array(map.sz); + var i; + for (i = 0; i < map.sz; i++) + { + map.data[i] = new Array(map.sz); + } +} + +map.draw = function() +{ + var i, j; + for (i = 0; i < 20; i++) + { + for (j = 0; j < 11; j++) + { + if (camera.y + j < map.sz) + { + screen.drawImage(map.data[camera.x + i][camera.y + j].sprite, 16*i, 16*j); + if (!isEmptyObject(map.data[camera.x + i][camera.y + j].structure)) + { + screen.drawImage(map.data[camera.x + i][camera.y + j].structure.sprite, 16*i, 16*j); + } + if (!isEmptyObject(map.data[camera.x + i][camera.y + j].unit)) + { + screen.drawImage(map.data[camera.x + i][camera.y + j].unit.sprite, 16*i, 16*j); + } + + } + } + } +} + +map.fillPlains = function() +{ + var i, j; + for (i = 0; i < map.sz; i++) + { + for (j = 0; j < map.sz; j++) + { + map.data[i][j] = new map.cell(); + map.changeCell(map.data[i][j], "plain"); + } + } +} + +map.genCities = function(number, sz, sigma) +{ + var cities = new Array(number); + var i, j, k; + for (i = 0; i < number; i++) + { + cities[i] = {}; + cities[i].x = Math.floor(Math.random()*map.sz); + cities[i].y = Math.floor(Math.random()*map.sz); + cities[i].radius = sz - Math.floor(Math.random()*sigma); + cities[i].style = Math.floor(Math.random()*2); + } + var z; + var delta = 0; + for (z = 0; z < number; z++) + { + delta = cities[z].radius + switch(cities[z].style) + { + case 0: + case 1: + for (j = 0; j < cities[z].radius; j++) + { + for (k = delta; k >= 0; k--) + { + if (cities[z].x + j < map.sz && cities[z].y + k < map.sz) + map.changeCell(map.data[cities[z].x + j][cities[z].y + k], "city"); + if (cities[z].x + j< map.sz && cities[z].y - k >= 0) + map.changeCell(map.data[cities[z].x + j][cities[z].y - k], "city"); + if (cities[z].x - j >= 0 && cities[z].y + k < map.sz) + map.changeCell(map.data[cities[z].x - j][cities[z].y + k], "city"); + if (cities[z].x - j >=0 && cities[z].y - k >= 0) + map.changeCell(map.data[cities[z].x - j][cities[z].y - k], "city"); + } + delta--; + } + } + } +} + + +map.genForests = function(density) +{ + var rX, rY, i; + for (i = 0; i < density*map.sz*map.sz; i++) + { + rX = Math.floor(Math.random()*map.sz); + rY = Math.floor(Math.random()*map.sz); + if (map.data[rX][rY].type == "plain") + { + map.changeCell(map.data[rX][rY], "forest"); + } + else { i--; } + } +} +map.genRuins = function(density) +{ + var rX, rY, i; + for (i = 0; i < density*density*map.sz*map.sz; i++) + { + rX = Math.floor(Math.random()*map.sz); + rY = Math.floor(Math.random()*map.sz); + if (map.data[rX][rY].type != "water") + { + map.changeCell(map.data[rX][rY], "ruins"); + } + } +} + +map.genMountains = function(number, sz, sigma) +{ + if (number < 10) { number = 10 }; + var mountains = new Array(number); + var i, j, k; + for (i = 0; i < number; i++) + { + mountains[i] = {}; + mountains[i].x = Math.floor(Math.random()*map.sz); + mountains[i].y = Math.floor(Math.random()*map.sz); + mountains[i].radius = sz - Math.floor(Math.random()*sigma); + mountains[i].style = Math.floor(Math.random()*2); + } + var z; + var delta = 0; + for (z = 0; z < number; z++) + { + delta = mountains[z].radius + switch(mountains[z].style) + { + case 0: + case 1: + for (j = 0; j < mountains[z].radius; j++) + { + for (k = delta; k >= 0; k--) + { + if (mountains[z].x + j < map.sz && mountains[z].y + k < map.sz) + map.changeCell(map.data[mountains[z].x + j][mountains[z].y + k], "mountain"); + if (mountains[z].x + j< map.sz && mountains[z].y - k >= 0) + map.changeCell(map.data[mountains[z].x + j][mountains[z].y - k], "mountain"); + if (mountains[z].x - j >= 0 && mountains[z].y + k < map.sz) + map.changeCell(map.data[mountains[z].x - j][mountains[z].y + k], "mountain"); + if (mountains[z].x -j >=0 && mountains[z].y - k >- 0) + map.changeCell(map.data[mountains[z].x - j][mountains[z].y - k], "mountain"); + } + delta--; + } + } + } +} + +map.fillOcean = function(sz, gravity) +{ + var oceanSize = sz ; + var gravity = gravity; + var ogSz = oceanSize; + var i, j, k + switch (gravity) + { + case 10: break; + case 7: + for (i = 0; i < ogSz; i++) + { + for (j = 0; j < oceanSize; j++) + { + map.changeCell(map.data[i][j], "water"); + } + oceanSize--; + } + break; + case 4: + for (i = 0; i < ogSz; i++) + { + for (j = 0; j < map.sz; j++) + { + map.changeCell(map.data[i][j], "water"); + } + } + break; + case 1: + for (i = 0; i < ogSz; i++) + { + for (j = 0; j < oceanSize; j++) + { + map.changeCell(map.data[i][map.sz - 1 - j], "water"); + } + oceanSize--; + } + break; + case 2: + for (i = 0; i < map.sz; i++) + { + for (j = 0; j < ogSz; j++) + { + map.changeCell(map.data[i][map.sz - 1 - j], "water"); + } + } + break; + case 3: + for (i = 0; i < ogSz; i++) + { + for (j = 0; j < oceanSize; j++) + { + map.changeCell(map.data[map.sz - 1 - i][map.sz - 1 - j], "water"); + } + oceanSize--; + } + break; + case 6: + for (i = 0; i < ogSz; i++) + { + for (j = 0; j < map.sz; j++) + { + map.changeCell(map.data[map.sz - 1 - i][j], "water"); + } + } + break; + case 9: + for (i = 0; i < ogSz; i++) + { + for (j = 0; j < oceanSize; j++) + { + map.changeCell(map.data[map.sz - 1 - i][j], "water"); + } + oceanSize--; + } + break; + case 8: + for (i = 0; i < map.sz; i++) + { + for (j = 0; j < ogSz; j++) + { + map.changeCell(map.data[i][j], "water"); + } + } + break; + case 5: + for (i = 0; i < ogSz; i++) + { + for (j = 0; j < oceanSize; j++) + { + map.changeCell(map.data[map.sz/2 + j][map.sz/2 + i], "water"); + map.changeCell(map.data[map.sz/2 - j][map.sz/2 + i], "water"); + map.changeCell(map.data[map.sz/2 + j][map.sz/2 - i], "water"); + map.changeCell(map.data[map.sz/2 - j][map.sz/2 - i], "water"); + } + oceanSize--; + } + + } +} + +map.generate = function() +{ + this.loadTiles(); + this.init() + this.fillPlains(); + this.genForests(0.5); + this.genMountains(Math.floor(Math.random()*this.sz/8), 10, 9); + this.genCities(Math.floor(Math.random()*this.sz/7 + 3), 5, 4); + this.genRuins(0.02); + this.fillOcean(8 + Math.floor(Math.random()*8), Math.floor(Math.random()*9) + 1); +}
A MiniMap.js

@@ -0,0 +1,90 @@

+window.minimap = {}; +minimap.gfx = {}; +minimap.gfx.bg = new Image(); +minimap.gfx.bg.src = "assets/mapbg/miniMap/miniMapBG.png" +minimap.gfx.cam = new Image(); +minimap.gfx.cam.src = "assets/mapbg/miniMap/cameraOverlay.png" + +minimap.gfx.ruins = new Image(); +minimap.gfx.ruins.src = "assets/mapbg/miniMap/ruins.png" +minimap.gfx.city = new Image(); +minimap.gfx.city.src = "assets/mapbg/miniMap/city.png" +minimap.gfx.forest = new Image(); +minimap.gfx.forest.src = "assets/mapbg/miniMap/forest.png" +minimap.gfx.mountain = new Image(); +minimap.gfx.mountain.src = "assets/mapbg/miniMap/mountain.png" +minimap.gfx.plain = new Image(); +minimap.gfx.plain.src = "assets/mapbg/miniMap/plain.png" +minimap.gfx.ocean = new Image(); +minimap.gfx.ocean.src = "assets/mapbg/miniMap/ocean.png" +minimap.gfx.p1 = new Image(); +minimap.gfx.p1.src = "assets/mapbg/miniMap/p1.png" +minimap.gfx.cpu = new Image(); +minimap.gfx.cpu.src = "assets/mapbg/miniMap/cpu.png" +minimap.gfx.p1u = new Image(); +minimap.gfx.p1u.src = "assets/mapbg/miniMap/p1u.png" +minimap.gfx.cpuu = new Image(); +minimap.gfx.cpuu.src = "assets/mapbg/miniMap/cpuu.png" + +minimap.draw = function() +{ + var i, j, sprite; + screen.drawImage(minimap.gfx.bg, 0, 0); + for (i = 0; i < 64; i++) + { + for (j = 0; j < 64; j++) + { + switch (map.data[i][j].type) + { + case "ruins": + sprite = this.gfx.ruins; + break; + case "plain": + sprite = this.gfx.plain; + break; + case "water": + sprite = this.gfx.ocean; + break; + case "mountain": + sprite = this.gfx.mountain; + break; + case "city": + sprite = this.gfx.city; + break; + case "forest": + sprite = this.gfx.forest; + break; + } + screen.drawImage(sprite, 96 + 2*i, 26 + 2*j); + if (!isEmptyObject(map.data[i][j].structure)) + { + if (map.data[i][j].structure.name.startsWith("p1")) + { + screen.drawImage(this.gfx.p1, 96 + 2*i, 26 + 2*j); + } + else { screen.drawImage(this.gfx.cpu, 96 + 2*i, 26 + 2*j) ; } + } + if (!isEmptyObject(map.data[i][j].unit)) + { + if (map.data[i][j].unit.name.startsWith("p1")) + { + screen.drawImage(this.gfx.p1u, 96 + 2*i, 26 + 2*j); + } + else { screen.drawImage(this.gfx.cpuu, 96 + 2*i, 26 + 2*j); } + } + if (i >= camera.x && i < camera.x + 20 && j >= camera.y && j < camera.y + 12) + { + screen.drawImage(this.gfx.cam, 96 + 2*i, 26 + 2*j); + } + } + } +} + +minimap.listen = function() +{ + if (controller.start || controller.y || controller.x) + { + controller.start = controller.y = controller.x = false; + gameState.flow = "freeLook"; + } +}
A Movement.js

@@ -0,0 +1,144 @@

+window.movement = {}; +movement.chain = new Array(); +movement.unit = {}; +movement.pool = 0; +movement.animCounter = 0; +movement.gfx = {}; +movement.gfx.overlay = new Image(); +movement.gfx.overlay.src = "assets/ui/movementOverlay.png"; + +function Coords(x,y) +{ + this.x = x; + this.y = y; +} + +movement.init = function(u) +{ + this.unit = u; + this.pool = u.agi; + this.chain.push(new Coords(u.x, u.y)); +} + +movement.cancel = function() +{ + this.unit = {}; + this.pool = 0; + this.chain = new Array(); + gameState.flow = "freeLook"; +} + +movement.listen = function() +{ + var z = {}; + var chainEnd = this.chain[this.chain.length - 1]; + + 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; + } + } + + if (controller.x) + { + this.cancel(); + return; + } + + if (controller.y) + { + this.confirm(); + return; + } + + if (controller.up) + { + z = new Coords(chainEnd.x, chainEnd.y - 1); + } + + if (controller.left) + { + z = new Coords(chainEnd.x - 1, chainEnd.y); + } + + if (controller.down) + { + z = new Coords(chainEnd.x, chainEnd.y + 1); + } + + if (controller.right) + { + z = new Coords(chainEnd.x + 1, chainEnd.y); + } + + if (!isEmptyObject(z)) + { + if (map.data[z.x][z.y].agiMod <= this.pool && z.x >= 0 && z.x < 64 && z.y >= 0 && z.y < 64 && isEmptyObject(map.data[z.x][z.y].unit)) + { + if (this.unit.name != "p1 Battle Angel") + { + this.pool -= map.data[z.x][z.y].agiMod + 1; + } + else { this.pool -= 1; } + this.chain.push(z); + mapCursor.x = z.x; + mapCursor.y = z.y; + } + } +} + +movement.showChain = function() +{ + var c, i, j; + screen.font = "8px console"; + 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)); + } +} + +movement.confirm = function() +{ + gameState.flow = "moveAnim"; +} + +movement.go = function() +{ + this.animCounter++; + if (this.animCounter == 10) + { + this.animCounter = 0; + if (this.chain.length > 1) + { + this.chain.shift(); + } + else + { + this.unit.hasMoved = true; + this.unit = {}; + this.chain = new Array(); + this.pool = 0; + gameState.flow = "freeLook"; + return; + } + moveToTile(this.unit, this.chain[0]); + } +} + +function moveToTile(unit, tile) +{ + var oX, oY; + oX = unit.x; + oY = unit.y; + map.data[tile.x][tile.y].unit = unit; + unit.x = tile.x; + unit.y = tile.y; + map.data[oX][oY].unit = {} +}
A Struct.js

@@ -0,0 +1,215 @@

+structure = function() +{ + this.x = 0; + this.y = 0; + this.name = "" + this.energy = 0; + this.rate = 0; + this.cost = 0; + this.sprite = {}; + this.flag = 0; + this.def = 0; + this.spd = 0; + this.hp = 0; + this.maxHP = 0; +} + +function mkFactory(player, x, y) +{ + var self = new structure(); + self.sprite = new Image(); + self.sprite.src = "assets/struct/" + player + "/factory.png"; + self.energy = 0; + self.cost = 40; + self.rate = 0; + self.hp = 30; + self.maxHP = 30; + self.x = x; + self.y = y; + self.name = player + " factory"; + map.data[x][y].structure = self; + return self; +} + +function mkArmory(player, x, y) +{ + var self = new structure(); + self.sprite = new Image(); + self.sprite.src = "assets/struct/" + player + "/armory.png"; + self.energy = 0; + self.cost = 40; + self.rate = 0; + self.hp = 25; + self.maxHP = 25; + self.x = x; + self.y = y; + self.name = player + " armory"; + map.data[x][y].structure = self; + return self; +} + + +function mkTidal(player, x, y) +{ + var self = new structure(); + self.sprite = new Image(); + self.sprite.src = "assets/struct/" + player + "/tidal.png"; + self.energy = 30; + self.cost = 30; + self.x = x; + self.y = y; + self.rate = 0.6 + self.hp = 20; + self.maxHP = 20; + self.name = player + " tidal plant" + self.flag = 2 + map.data[x][y].structure = self; + return self; +} + +function mkSolar(player, x, y) +{ + var self = new structure(); + self.sprite = new Image(); + self.sprite.src = "assets/struct/" + player + "/solar.png"; + self.energy = 10; + self.cost = 20; + self.rate = 0.8 + self.x = x; + self.y = y; + self.hp = 10; + self.maxHP = 10; + self.name = player + " solar array" + map.data[x][y].structure = self; + return self; +} + +function buildSolar() +{ + switch(gameState.phase) + { + case "p1": + teams.p1.structs.push(mkSolar("p1", mapCursor.x, mapCursor.y)); + teams.p1.energy -= teams.p1.structs[teams.p1.structs.length - 1].cost; + resetFlow(); + break; + case "cpu": + teams.cpu.structs.push(mkSolar("cpu", mapCursor.x, mapCursor.y)); + teams.cpu.energy -= teams.cpu.structs[teams.cpu.structs.length - 1].cost; + break; + } +} + +function buildMine() +{ + switch(gameState.phase) + { + case "p1": + teams.p1.structs.push(mkMine("p1", mapCursor.x, mapCursor.y)); + teams.p1.energy -= teams.p1.structs[teams.p1.structs.length - 1].cost; + resetFlow(); + break; + case "cpu": + teams.cpu.structs.push(mkMine("cpu", mapCursor.x, mapCursor.y)); + teams.cpu.energy -= teams.cpu.structs[teams.cpu.structs.length - 1].cost; + break; + } +} +function buildTidal() +{ + switch(gameState.phase) + { + case "p1": + teams.p1.structs.push(mkTidal("p1", mapCursor.x, mapCursor.y)); + teams.p1.energy -= teams.p1.structs[teams.p1.structs.length - 1].cost; + resetFlow(); + break; + case "cpu": + teams.cpu.structs.push(mkTidal("cpu", mapCursor.x, mapCursor.y)); + teams.cpu.energy -= teams.cpu.structs[teams.cpu.structs.length - 1].cost; + break; + } +} +function buildFactory() +{ + switch(gameState.phase) + { + case "p1": + teams.p1.structs.push(mkFactory("p1", mapCursor.x, mapCursor.y)); + teams.p1.energy -= teams.p1.structs[teams.p1.structs.length - 1].cost; + resetFlow(); + break; + case "cpu": + teams.cpu.structs.push(mkFactory("cpu", mapCursor.x, mapCursor.y)); + teams.cpu.energy -= teams.cpu.structs[teams.cpu.structs.length - 1].cost; + break; + } +} +function buildArmory() +{ + switch(gameState.phase) + { + case "p1": + teams.p1.structs.push(mkArmory("p1", mapCursor.x, mapCursor.y)); + teams.p1.energy -= teams.p1.structs[teams.p1.structs.length - 1].cost; + resetFlow(); + break; + case "cpu": + teams.cpu.structs.push(mkArmory("cpu", mapCursor.x, mapCursor.y)); + teams.cpu.energy -= teams.cpu.structs[teams.cpu.structs.length - 1].cost; + break; + } +} + +function mkMine(player, x, y) +{ + var self = new structure(); + self.sprite = new Image(); + self.sprite.src = "assets/struct/" + player + "/mine.png"; + self.energy = 20; + self.cost = 30; + self.rate = 0.5 + self.x = x; + self.y = y; + self.hp = 25; + self.maxHP = 25; + self.name = player + " mine" + self.flag = 3; + map.data[x][y].structure = self; + return self; +} + +function mkHQ(player) +{ + var self = new structure(); + self.sprite = new Image(); + self.sprite.src = "assets/struct/" + player + "/hq.png"; + self.flag = 1; + self.def = 2; + self.energy = 35; + self.rate = .2; + self.hp = 50; + self.maxHP = 50; + self.name = player + " HQ" + + switch (player) + { + case "p1": + self.x = 16; + self.y = 16; + break; + case "cpu": + self.x = 48; + self.y = 48; + break; + } + + map.data[self.x][self.y].structure = self; + + if (player == "p1") + { + mapCursor.x = self.x; + mapCursor.y = self.y; + } +return self; +}
A Team.js

@@ -0,0 +1,38 @@

+function defTeams() +{ + this.p1 = {}; + this.cpu = {}; + this.data = new Array(2); + this.data[0] = this.p1; + this.data[1] = this.cpu; + + var i; + for (i = 0; i < 2; i++) + { + this.data[i].units = new Array(); + this.data[i].structs = new Array(); + this.data[i].energy = 35; + switch (i) + { + case 0: + this.data[i].structs.push(mkHQ("p1")); + break; + case 1: + this.data[i].structs.push(mkHQ("cpu")); + break; + } + } +} + +function subtractCost(player, item) +{ + switch (player) + { + case "p1": + teams.p1.energy -= item.cost; + break; + case "cpu": + teams.cpu.energy -= item.cost; + break; + } +}
A Touch.js

@@ -0,0 +1,231 @@

+function doNothing(e) +{ + e.preventDefault(); +} + +function pressUp(e) +{ + controller.up = true; +} + +function releaseUp(e) +{ + controller.up = false; +} + +function pressDown(e) +{ + controller.down = true; +} + +function releaseDown(e) +{ + controller.down = false; +} + +function pressLeft(e) +{ + controller.left = true; +} + +function releaseLeft(e) +{ + controller.left = false; +} + +function pressRight(e) +{ + controller.right = true; +} + +function releaseRight(e) +{ + controller.right = false; +} + +function pressUpLeft(e) +{ + pressUp(e); + pressLeft(e); +} + +function releaseUpLeft(e) +{ + releaseUp(e); + releaseLeft(e); +} + +function pressUpRight(e) +{ + pressUp(e); + pressRight(e); +} + +function releaseUpRight(e) +{ + releaseUp(e); + releaseRight(e); +} + +function pressDownLeft(e) +{ + pressDown(e); + pressLeft(e); +} + +function releaseDownLeft(e) +{ + releaseDown(e); + releaseLeft(e); +} + +function pressDownRight(e) +{ + pressDown(e); + pressRight(e); +} + +function releaseDownRight(e) +{ + 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; +} + +function releaseStart(e) +{ + controller.space = false; +} + +function pressW(e) +{ + controller.w = true; +} + +function releaseW(e) +{ + controller.w = false; +} + +function pressX(e) +{ + controller.x = true; +} + +function releaseX(e) +{ + controller.x = false; +} + +function pressY(e) +{ + controller.y = true; +} + +function releaseY(e) +{ + controller.y = false; +} + +function pressZ(e) +{ + controller.z = true; +} + +function releaseZ(e) +{ + controller.z = false; +} + +function prepareTouchInput() +{ + +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"); +dPad.s = document.getElementById("downButton"); +dPad.w = document.getElementById("leftButton"); +dPad.e = document.getElementById("rightButton"); +dPad.nw = document.getElementById("nwButton"); +dPad.ne = document.getElementById("neButton"); +dPad.sw = document.getElementById("swButton"); +dPad.se = document.getElementById("seButton"); +dPad.n.addEventListener("touchstart",pressUp); +dPad.n.addEventListener("touchend", releaseUp); +dPad.n.addEventListener("touchcancel", releaseUp); + +dPad.s.addEventListener("touchstart", pressDown); +dPad.s.addEventListener("touchend", releaseDown); +dPad.s.addEventListener("touchcancel", releaseDown); +dPad.e.addEventListener("touchstart", pressRight); +dPad.e.addEventListener("touchend", releaseRight); +dPad.e.addEventListener("touchcancel", releaseRight); +dPad.w.addEventListener("touchstart", pressLeft); +dPad.w.addEventListener("touchend", releaseLeft); +dPad.w.addEventListener("touchcancel", releaseLeft); +dPad.nw.addEventListener("touchstart", pressUpLeft); +dPad.nw.addEventListener("touchend", releaseUpLeft); +dPad.nw.addEventListener("touchcancel", releaseUpLeft); +dPad.ne.addEventListener("touchstart", pressUpRight); +dPad.ne.addEventListener("touchend", releaseUpRight); +dPad.ne.addEventListener("touchcancel", releaseUpRight); +dPad.sw.addEventListener("touchstart", pressDownLeft); +dPad.sw.addEventListener("touchend", releaseDownLeft); +dPad.sw.addEventListener("touchcancel", releaseDownLeft); +dPad.se.addEventListener("touchstart", pressDownRight); +dPad.se.addEventListener("touchend", releaseDownRight); +dPad.se.addEventListener("touchcancel", releaseDownRight); + +window.faceButtons = {}; + +faceButtons.x = document.getElementById("xButton"); +faceButtons.y = document.getElementById("yButton"); +faceButtons.w = document.getElementById("wButton"); +faceButtons.z = document.getElementById("zButton"); + +faceButtons.x.addEventListener("touchstart", pressX); +faceButtons.x.addEventListener("touchend", releaseX); +faceButtons.x.addEventListener("touchcancel", releaseX); +faceButtons.y.addEventListener("touchstart", pressY); +faceButtons.y.addEventListener("touchend", releaseY); +faceButtons.y.addEventListener("touchcancel", releaseY); +faceButtons.z.addEventListener("touchstart", pressZ); +faceButtons.z.addEventListener("touchend", releaseZ); +faceButtons.z.addEventListener("touchcancel", releaseZ); +faceButtons.w.addEventListener("touchstart", pressW); +faceButtons.w.addEventListener("touchend", releaseW); +faceButtons.w.addEventListener("touchcancel", releaseW); + + +window.startButton = document.getElementById("startButton"); +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); + +}
A Unit.js

@@ -0,0 +1,77 @@

+function Unit() +{ + this.sprite = {}; + this.hp = 10; + this.maxHP = 10; + this.pow = 4; + this.def = 1; + this.agi = 5; + this.equipment = {}; + this.x = 0; + this.y = 0; + this.cost = 30; + this.hasMoved = false; + this.name = ""; +} + +function mkRanger(player, x, y) +{ + var self = new Unit(); + self.sprite = new Image(); + self.sprite.src = "assets/unit/" + player + "/ranger.png"; + self.x = x; + self.y = y; + self.name = player + " Ranger"; + map.data[x][y].unit = self; + return self; +} + +function buildRanger() +{ + switch(gameState.phase) + { + case "p1": + teams.p1.units.push(mkRanger("p1", mapCursor.x, mapCursor.y)); + teams.p1.energy -= teams.p1.units[teams.p1.units.length - 1].cost; + resetFlow(); + break; + case "cpu": + teams.cpu.structs.push(mkRanger("cpu", mapCursor.x, mapCursor.y)); + teams.cpu.energy -= teams.cpu.units[teams.cpu.units.length - 1].cost; + break; + } +} + +function mkKnight(player, x, y) +{ + var self = new Unit(); + self.sprite = new Image(); + self.sprite.src = "assets/unit/" + player + "/knight.png"; + self.hp = 20; + self.maxHP = 20; + self.pow = 6; + self.def = 3; + self.agi = 4; + cost = 60; + self.x = x; + self.y = y; + self.name = player + " Knight"; + map.data[x][y].unit = self; + return self; +} + +function buildKnight() +{ + switch(gameState.phase) + { + case "p1": + teams.p1.units.push(mkKnight("p1", mapCursor.x, mapCursor.y)); + teams.p1.energy -= teams.p1.units[teams.p1.units.length - 1].cost; + resetFlow(); + break; + case "cpu": + teams.cpu.structs.push(mkKnight("cpu", mapCursor.x, mapCursor.y)); + teams.cpu.energy -= teams.cpu.units[teams.cpu.units.length - 1].cost; + break; + } +}
A index.html

@@ -0,0 +1,240 @@

+<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8" /> + <meta name="HandheldFriendly" content="True" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + + <title>uStrat</title> + <style> + *{padding: 0; margin: 0;} + @font-face + { + font-family: console; + src: url("assets/pcsenior.ttf") format('truetype'); + font-weight: normal; + font-style: normal; + } + #loadFont + { + font-family: 'console'; + visibility: hidden; + height:0px; + } + #dpad + { + position:fixed; + bottom: 10px; + left: 10px; + background: rgba(0,0,0,0); + z-index:2; + width:150px; + height:150px; + visibility:hidden; + } + #facebuttons + { + position: fixed; + bottom: 10px; + right: 10px; + background: rgba(0,0,0,0); + z-index:2; + width:150px; + height:150px; + visibility: hidden; + } + #upButton, #zButton + { + position:absolute; + top: 0px; + left: 33%; + width:33%; + height:33%; + background: rgba(0,0,0,0.4); + border-width: 1px; + border-style: solid; + border-color: #444444; + } + #downButton, #xButton + { + position:absolute; + bottom:0px; + left:33%; + width:33%; + height:33%; + background: rgba(0,0,0,0.4); + border-width: 1px; + border-style: solid; + border-color: #444444; + } + #leftButton, #wButton + { + position:absolute; + top: 33%; + left: 0px; + width:33%; + height:33%; + background: rgba(0,0,0,0.4); + border-width: 1px; + border-style: solid; + border-color: #444444; + } + #rightButton, #yButton + { + position:absolute; + top: 33%; + right: 0px; + width:33%; + height:33%; + background: rgba(0,0,0,0.4); + border-width: 1px; + border-style: solid; + border-color: #444444; + } + #nwButton + { + position:absolute; + top: 0px; + left:0px; + width:33%; + height:33%; + background: rgba(0,0,0,0.4); + border-width: 1px; + border-style: solid; + border-color: #444444; + } + #neButton + { + position:absolute; + top: 0px; + right: 0px; + width:33%; + height:33%; + background: rgba(0,0,0,0.4); + border-width: 1px; + border-style: solid; + border-color: #444444; + } + #swButton + { + position:absolute; + bottom: 0px; + left: 0px; + width:33%; + height:33%; + background: rgba(0,0,0,0.4); + border-width: 1px; + border-style: solid; + border-color: #444444; + } + #seButton + { + position:absolute; + bottom: 0px; + right: 0px; + width:33%; + height:33%; + background: rgba(0,0,0,0.4); + border-width: 1px; + border-style: solid; + border-color: #444444; + } + #startButton + { + position: fixed; + bottom: 10px; + right: 160px; + background:rgba(0,0,0,0.4); + width: 40px; + height: 15px; + border-color: #444444; + border-width: 1px; + border-style: solid; + visibility:hidden; + } + #qButton + { + position: fixed; + top: 10px; + right: 10px; + background:rgba(0,0,0,0.4); + width: 50px; + height: 50px; + border-color: #444444; + border-width: 1px; + border-style: solid; + visibility:hidden; + } + canvas + { + font-family: 'console'; + background: #444444; + display: block; + margin: 0 auto; + width: 100%; + height: auto; + max-width: 640px; + -ms-interpolation-mode: nearest-neighbor; + image-rendering: -webkit-optimize-contrast; + image-rendering: -moz-crisp-edges; + image-rendering: -o-cristp-edges; + image-rendering: pixelated; + } + </style> + + <script type="text/javascript" src="Engine.js"></script> + <script type="text/javascript" src="Touch.js"></script> + <script type="text/javascript" src="Keyboard.js"></script> + <script type="text/javascript" src="Map.js"></script> + <script type="text/javascript" src="Struct.js"></script> + <script type="text/javascript" src="Unit.js"></script> + <script type="text/javascript" src="Equipment.js"></script> + <script type="text/javascript" src="Team.js"></script> + <script type="text/javascript" src="Menu.js"></script> + <script type="text/javascript" src="Movement.js"></script> + <script type="text/javascript" src="Attack.js"></script> + <script type="text/javascript" src="MiniMap.js"></script> + <script type="text/javascript"> + function main() + { + var gCanvas = document.getElementById("screen"); + window.screen = gCanvas.getContext("2d"); + map.generate(); + window.teams = new defTeams(); + camera.centerOnCursor(); + if (navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini|Mobile/i)) + { + + prepareTouchInput(); + } + + loop(); + } + </script> + + </head> + + <body onload="main();"> + <div id="loadFont">loading font...</div> + <div id="dpad"> + <div id="upButton"></div> + <div id="downButton"></div> + <div id="rightButton"></div> + <div id="leftButton"></div> + <div id="nwButton"></div> + <div id="neButton"></div> + <div id="swButton"></div> + <div id="seButton"></div> + </div> + <div id="facebuttons"> + <div id="zButton"></div> + <div id="wButton"></div> + <div id="xButton"></div> + <div id="yButton"></div> + </div> + <div id="qButton"></div> + <div id="startButton"></div> + <canvas id="screen" width="320" height="180"></canvas> + + </body> +</html>