Unit.js (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 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; } } |