AI attack logic improved; documentation
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE----- iQJDBAABCAAtFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAl5PbJMPHG5pbGl4QG5p bGZtLmNjAAoJEDt/vCIUTmOY7oAP/2XYam5oAyWBHTOX18AiEVixB74ReBZawHqq 0C1Cq97TZ/07SgyF+W6bIJWQLB2kgwGo800H0uvk6wDS8Vb8gwLGq9xH7GeNwA/M 0h5GW3vo5pxqJE6ewtR+V8KgrexjAkNnxH7cNUp88rIwtyTNlzDK/ur0+d0N+gcF goNeDwGfk9NTHcdnpGTtxmF9AP/fnDCVCFlMRSHTPgqmodHLWxg8zoWy2pA8EiFl teVspYHm+ia6Y+zftC1HmdHq7Y/qPVlqiGGM5Wix++V0lzI1yqr/YZQ+qwR2jcKK NvjAVHH4WUoXElehbtSGzGJ+MgEmq6qHjOwrdCZi8vDwypLM75k2RkABllrshAAo aKqo1LGLcqNSizACaKC2l6wPOLDrVrbE/lxzCT2ujelzTxhsAqdXtNi3DXcuf7S+ 1fMzTJ0nkiWIStbqE3A+b7OWkGJS9ZB0OXZc0H/BeiEDZfxls5yRcWQpMKQ9WTRN 4w7uUInDVXO9VyetI+iG+/oORg0xoNQ8XFLbZaJD1iVf+ml7W6N0vtxqupMX8sp3 Hrpm7GTgX/oW9RpLUtzYPUNcukh6dP4q0xSGQlyifarDJhRboWaLfmfGs8GhnDCN jLtM0dpp68G3jtDCV5EJacJ3UVJBg5Gc+DGP5OrYCNpLpedNwWRAbF4vuZ+GbMcR AlMsFv4Q =x1C/ -----END PGP SIGNATURE-----
14 files changed,
123 insertions(+),
6 deletions(-)
M
Attack.js
→
Attack.js
@@ -1,3 +1,7 @@
+// Attack.js & uStrat (c) Derek Stevens <drkste@zoho.com> +// this file contains Attack procedures and some AI code related to them + + window.attack = {}; attack.pattern = {}; attack.rotations = [ 0 ];@@ -27,21 +31,45 @@ {
AI.focus = 0; endPhase(); } - gameState.flow = "cpuAttackReady"; attack.src = teams.cpu.units[AI.focus]; attack.pattern = attack.src.equipment.pattern; if (attack.src.mode != "defend") { - mapCursor.x = attack.src.target.x; - mapCursor.y = attack.src.target.y; + if (dist(attack.src.target, attack.src) <= attack.src.equipment.range) + { + mapCursor.x = attack.src.target.x; + mapCursor.y = attack.src.target.y; + } + else + { + AI.focus++; + return; + } } else { // search for closest enemy unit in range, target it // if nothing in range, do nothing - AI.focus++; - gameState.flow = "cpuAttackReady" + var i, min, working; + min = 99999; + working = 0; + for (i = 0; i < teams.p1.units.length; i++) + { + working = dist(attack.src, teams.p1.units[i]); + if (working <= min && dist(teams.p1.units[i], attack.src) <= attack.src.range) + { + min = working; + mapCursor.x = taems.p1.units[i].x; + mapCursor.y = teams.p1.units[i].y; + } + } + if (min == 99999) + { + AI.focus++; + return; + } } + gameState.flow = "cpuAttackReady"; } attack.cancel = function()
M
Engine.js
→
Engine.js
@@ -1,3 +1,9 @@
+// Engine.js & uStrat (c) Derek Stevens <drkste@zoho.com> +// this file contains high level engine code and utility functions; +// aside from utility functions and the state machine known as loop(), +// we mostly have wrapper functions that call more complex +// functions from other files + window.gameState = {}; window.controller = {}; window.gameOverWindow = new Image();
M
Equipment.js
→
Equipment.js
@@ -1,3 +1,6 @@
+// Equipment.js & uStrat (c) Derek Stevens <drkste@zoho.com> +// this file contains all functions directly related to equipment + function equipment() { this.pattern = new Array(5);
M
Keyboard.js
→
Keyboard.js
@@ -1,3 +1,6 @@
+// Keyboard.js & uStrat (c) Derek Stevens <drkste@zoho.com> +// this file contains keybinds! + document.addEventListener("keydown", pressHandler, false); document.addEventListener("keyup", releaseHandler, false);
M
MiniMap.js
→
MiniMap.js
@@ -1,3 +1,6 @@
+// MiniMap.js & uStrat (c) Derek Stevens <drkste@zoho.com> +// this file contains the mini-map data, listening, and drawing procedure + window.minimap = {}; minimap.gfx = {}; minimap.gfx.bg = new Image();
M
Movement.js
→
Movement.js
@@ -1,3 +1,8 @@
+// Movement.js & uStrat (c) Derek Stevens <drkste@zoho.com> +// this file contains data and functions related to Unit +// movement including player plotting of paths and movement +// animation + window.movement = {}; movement.chain = new Array(); movement.unit = {};
A
README.md
@@ -0,0 +1,42 @@
+# uStrat + +uStrat is a strategy game developed primarily for mobile phones. It is inspired by games like uCity, Fire Emblem, and Super Robot Wars. uStrat is written in Javascript using HTML5 Canvas and a whole lotta elbow grease. + +## Gameplay + +The map is randomly generated at the beginning of the game. P1 and CPU headquarters are spawned in opposite quadrants of the map. The goal is to build your headquarters up with power generation, factories, and armories (Structures), and build an army of mecha soldiers (Units) equipped to defend the Cities and destroy the enemy's HQ. The CPU team will be doing the same, but aiming to destroy the Cities. + +Resource management is centered around Energy. Each power generation Structure adds a certain amount of Energy to your team's pool, up to a maximum defined by the sum of the power generation Structures. Building Units, Structures, and Equipment costs energy. + +Each Unit has its own strengths and weaknesses; Same goes for the equipment. You can mix and match units and equipment to come up with an arsenal that best matches your strategy. + +The game ends when too many cities are destroyed or either HQ is destroyed. + +## Controls + +uStrat can be controlled by keyboard (desktop/laptop) or touch (mobile). The game will automatically detect a mobile platform and render the touch controls when necessary. The controls are as follows: + +### touch + +* `d-Pad (left cross)`: movement +* `pause (center button)`: show/hide mini-map +* `face buttons (right cross)`: + * `Y (right button)`: select tile/menu option + * `X (bottom button)`: cancel selection or operation + * `Z (top button)`: reset movement path; change cycle class; rotate attack pattern + * `W (left button)`: cycle through current cycle class; rotate attack pattern + +### keyboard + +* `arrow keys`: movement +* `spacebar`: show/hide mini-map +* `x`: select tile/menu option +* `z`: cancel selection or operation +* `s`: reset movement path; change cycle class; rotate attack pattern +* `a`: cycle through current cycle class; rotate attack pattern + +## Development + +* currently finishing the AI and polishing up some UI +* there is a lot of improvement to be made on the AI's basic pathfinding. more will be done with this later after the game is more or less playable +* probably a million and one bugs. please do report them and/or contribute fixes!