all repos — uStrat @ f00d6f066c46e88400a1513ec586cfd9a7980fdf

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

add glyphs to touch controls, resize map and remove all hardcoded references to map size; tweak formula for mountains and ocean generation
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQJDBAABCAAtFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAl64HT0PHG5pbGl4QG5p
bGZtLmNjAAoJEDt/vCIUTmOYomcP/2UUtGm0kn8Jfm9PypSn7HquKZYKsvhC4y6f
C31FNfsoCFQzRHFZxfHKs3USaX9kD3kUgIGOhKnWpVexkhHQiDV9tWhGMhTNpgWE
vtIW/oNU01JfeCIjJxgqqSJbVJoXdwWoPsmxtR9HIelKxa+MC7pDLqzU1dwbQCP3
Nuuy+CHPlGDRTXRjrkx9qdarHDVwsDEwlQHinbO5gjof88iA8BFxyUeEkeb8z8d8
MYrxg8yK59pp/laZuNuU6dzKBZsX2eTSMC+/QxNUO28dN4hFX4NCC1LGx/B219Ab
g5XHxE3ujUj8tNV17JxVgdMtMIDsZ6e6XY3Zlh+PEkKFRmIiF3d0hgGBP+dQWZuP
hoVwfdATqF4L+PYWVK20DBdjmQet04zufUsx+nZgPNMSPqaIqIRRwMUtx2ATLgFb
6Oj1dpuOFmrxfZZaKv+potj1EfMN02Z8dXJ/y1Kz5s2IPwTHhJZwA5tsxwg3bIvi
/+s8734mexzyigfLRv+XnDEbkw8bqsZhGYKRyFtgZZ92eQsFzacxb+omJYneELta
wbVRZuSXkVmzXFjyEXIwhUuqx8GhoFIrTv/nSn/lQteBL55rxobSQx8kzdZKVmq5
YrQT1s2uRD/0jIjyZs0txP0uuhnmjTX6DEPu7I5TTUyq942xE1EpLGpu6LiXgoeh
3r4iMbFZ
=s6gR
-----END PGP SIGNATURE-----
commit

f00d6f066c46e88400a1513ec586cfd9a7980fdf

parent

d398d667aca43d25519a4490042221cdaae76416

5 files changed, 68 insertions(+), 58 deletions(-)

jump to
M AI.jsAI.js

@@ -8,6 +8,7 @@ AI.Q = {}

AI.moveOptions = new Array(4); AI.focus = {}; AI.delay = 0; +const maxAttention = 1.5*Math.cieling(Math.sqrt(map.sz)); AI.rand = function(i)

@@ -24,7 +25,7 @@

AI.incrementAttention = function() { teams.cpu.units[AI.focus].attentionSpan += 1; - if (teams.cpu.units[AI.focus].attentionSpan == 7) + if (teams.cpu.units[AI.focus].attentionSpan == maxAttention) { teams.cpu.units[AI.focus].attentionSpan = 0; }

@@ -93,9 +94,9 @@ tY = -1;

d = 1000; z = teams.cpu.units[AI.focus] - for (i = 0; i < 64; i++) + for (i = 0; i < map.sz; i++) { - for (j = 0; j < 64; j++) + for (j = 0; j < map.sz; j++) { if (map.data[i][j].type == "city" && dist(map.data[i][j], z) < d) {

@@ -545,9 +546,9 @@ w = AI.rand(4);

switch (w) { case 0: - for (i = 0; i < 64; i++) + for (i = 0; i < map.sz; i++) { - for (j = origin.y; j < 64; j++) + for (j = origin.y; j < map.sz; j++) { if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) {

@@ -557,7 +558,7 @@ }

} break; case 1: - for (i = 63; i >= 0; i--) + for (i = map.sz - 1; i >= 0; i--) { for (j = origin.y; j >= 0; j--) {

@@ -569,9 +570,9 @@ }

} break; case 2: - for (i = origin.x; i < 64; i++) + for (i = origin.x; i < map.sz; i++) { - for (j = 0; j < 64; j++) + for (j = 0; j < map.sz; j++) { if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) {

@@ -583,7 +584,7 @@ break;

case 3: for (i = origin.x; i >= 0; i--) { - for (j = 63; j >= 0; j--) + for (j = map.sz - 1; j >= 0; j--) { if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) {

@@ -606,9 +607,9 @@ switch(w)

{ case 0: console.log("rolled 0"); - for (i = 0; i < 64; i++) + for (i = 0; i < map.sz; i++) { - for (j = 0; j < 64; j++) + for (j = 0; j < map.sz; j++) { if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) {

@@ -619,9 +620,9 @@ }

break; case 1: console.log("rolled 1"); - for (i = 63; i >= 0; i--) + for (i = map.sz - 1; i >= 0; i--) { - for (j = 63; j >= 0; j--) + for (j = map.sz - 1; j >= 0; j--) { if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) {

@@ -632,9 +633,9 @@ }

break; case 2: console.log("rolled 2"); - for (i = 63; i >= 0; i--) + for (i = map.sz - 1; i >= 0; i--) { - for (j = 0; j < 64; j++) + for (j = 0; j < map.sz; j++) { if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) {

@@ -645,9 +646,9 @@ }

break; case 3: console.log("rolled 3"); - for (i = 0; i < 64; i++) + for (i = 0; i < map.sz; i++) { - for (j = 63; j >= 0; j--) + for (j = map.sz - 1; j >= 0; j--) { if (dist(origin, map.data[i][j]) < teams.cpu.energy/15 && isEmptyObject(map.data[i][j].structure)) {
M Map.jsMap.js

@@ -2,7 +2,7 @@ // Map.js & uStrat (c) Derek Stevens <drkste@zoho.com>

// this file contains map, camera, and HUD data and functions window.map = {}; -map.sz = 64; +map.sz = 32; map.ogCities = 0; map.gfx = {};

@@ -571,8 +571,8 @@ this.loadTiles();

this.init() this.fillPlains(); this.genForests(0.5); - this.genMountains(Math.floor(Math.random()*this.sz/8), 10, 9); + this.genMountains(Math.floor(Math.random()*this.sz/8), Math.floor(Math.random()*map.sz/6), 9); this.genCities(Math.floor(Math.random()*this.sz/7 + 3), 5, 4); - this.fillOcean(8 + Math.floor(Math.random()*8), Math.floor(Math.random()*9) + 1); + this.fillOcean(Math.floor(Math.random()*map.sz/8) + Math.floor(Math.random()*Math.sqrt(map.sz)), Math.floor(Math.random()*9) + 1); this.countCities(); }
M MiniMap.jsMiniMap.js

@@ -33,9 +33,9 @@ minimap.draw = function()

{ var i, j, sprite; screen.drawImage(minimap.gfx.bg, 0, 0); - for (i = 0; i < 64; i++) + for (i = 0; i < map.sz; i++) { - for (j = 0; j < 64; j++) + for (j = 0; j < map.sz; j++) { switch (map.data[i][j].type) {

@@ -58,26 +58,26 @@ case "forest":

sprite = this.gfx.forest; break; } - screen.drawImage(sprite, 96 + 2*i, 26 + 2*j); + screen.drawImage(sprite, 320/2 - map.sz + 2*i, 180/2 - map.sz + 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); + screen.drawImage(this.gfx.p1, 320/2 - map.sz + 2*i, 180/2 - map.sz + 2*j); } - else { screen.drawImage(this.gfx.cpu, 96 + 2*i, 26 + 2*j) ; } + else { screen.drawImage(this.gfx.cpu, 320/2 - map.sz + 2*i, 180/2 - map.sz + 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); + screen.drawImage(this.gfx.p1u, 320/2 - map.sz + 2*i, 180/2 - map.sz + 2*j); } - else { screen.drawImage(this.gfx.cpuu, 96 + 2*i, 26 + 2*j); } + else { screen.drawImage(this.gfx.cpuu, 320/2 - map.sz + 2*i, 180/2 - map.sz + 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); + screen.drawImage(this.gfx.cam, 320/2 - map.sz + 2*i, 180/2 - map.sz + 2*j); } } }
M Struct.jsStruct.js

@@ -200,12 +200,12 @@

switch (player) { case "p1": - self.x = 16; - self.y = 16; + self.x = Math.floor(map.sz/4); + self.y = Math.floor(map.sz/4); break; case "cpu": - self.x = 48; - self.y = 48; + self.x = Math.floor(3*map.sz/4); + self.y = Math.floor(3*map.sz/4); break; }
M index.htmlindex.html

@@ -7,6 +7,11 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0" />

<title>uStrat</title> <style> + + body + { + height: 100vh; + } *{padding: 0; margin: 0;} @font-face {

@@ -31,6 +36,15 @@ z-index:2;

width:150px; height:150px; visibility:hidden; + line-height: 50px; + color: #ffffff; + text-align: center; + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; } #facebuttons {

@@ -42,6 +56,15 @@ z-index:2;

width:150px; height:150px; visibility: hidden; + line-height: 55px; + color: #ffffff; + text-align: center; + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; } #upButton, #zButton {

@@ -157,7 +180,7 @@ {

font-family: 'console'; background: #444444; display: block; - margin: 0 auto; + margin: 0 auto; width: 100%; height: auto; max-width: 640px;

@@ -166,7 +189,7 @@ 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>

@@ -191,24 +214,10 @@ map.generate();

window.teams = new defTeams(); - teams.p1.structs.push(mkSolar("p1", 15, 15)); - teams.p1.structs.push(mkSolar("p1", 16, 15)); - teams.p1.structs.push(mkSolar("p1", 17, 15)); - teams.p1.structs.push(mkSolar("p1", 15, 16)); - teams.p1.structs.push(mkSolar("p1", 17, 16)); - teams.p1.structs.push(mkFactory("p1", 15, 17)); - teams.p1.structs.push(mkArmory("p1", 16, 17)); - - teams.p1.units.push(mkRanger("p1", 18, 17)); - teams.p1.units.push(mkKnight("p1", 17, 17)); - teams.p1.units.push(mkAce("p1", 18, 16)); - teams.p1.units.push(mkBattleAngel("p1", 18, 15)); - teams.p1.units.push(mkBlitzWalker("p1", 17, 14)); - camera.centerOnCursor(); if (navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini|Mobile/i)) { - + prepareTouchInput(); }

@@ -224,19 +233,19 @@

<div id="startButton"></div> <div id="dpad"> - <div id="upButton"></div> - <div id="downButton"></div> - <div id="rightButton"></div> - <div id="leftButton"></div> + <div id="upButton">&uarr;</div> + <div id="downButton">&darr;</div> + <div id="rightButton">&rarr;</div> + <div id="leftButton">&larr;</div> </div> <div id="facebuttons"> - <div id="zButton"></div> - <div id="wButton"></div> - <div id="xButton"></div> - <div id="yButton"></div> + <div id="zButton">Z</div> + <div id="wButton">W</div> + <div id="xButton">X</div> + <div id="yButton">Y</div> </div> <canvas id="screen" width="320" height="180"></canvas> </body> -</html>+</html>