Compare commits

...

5 Commits

Author SHA1 Message Date
558b77603b
wave documentation 2017-08-23 19:26:40 +03:00
b6736c4da0 Merge pull request #5 from Tsa6/fix-enemy-alignment
Fix enemy alignment
2017-08-22 20:13:43 +03:00
Taizo 'Tsa6' Simpson
3bcb14f3fb Merge branch 'master' of https://github.com/LunaSquee/html5-tower-defense-experiment into fix-enemy-alignment 2017-08-22 12:49:06 -04:00
Taizo 'Tsa6' Simpson
292afea46b Simplified expressions 2017-08-22 12:37:19 -04:00
Taizo 'Tsa6' Simpson
af7dcd70c8 Added margin system to enemy rendering, fixing alignment issues 2017-08-22 12:36:10 -04:00

View File

@ -70,7 +70,7 @@ window.onload = function () {
tough: {
speed: 5,
node: 1,
health: 80,
health: 100,
reward: 20,
frequency: 40,
icon: '#f40'
@ -124,6 +124,39 @@ window.onload = function () {
}
}
/*
Tiles:
* 0 - grass
* 1 - path
* 2 - spawn
* 3 - end
Wave layout:
[] - optional
<> - value type
{
type - 'recurring', 'once-every' or 'once'
* recurring
waveLow <int> - wave in which this entry will start spawning enemies
[waveHigh] <int> - wave in which this entry will stop spawning enemies
* once-every
every <int> - every x wave this entry will spawn enemies
* once
wave <int> - wave in which this entry will spawn enemies
[oneAfterAnother] <bool> - If true, enemy types specified below will be spawned one-after-another
enemies: [{
type <string> - type of enemy
count <int> - base count to spawn
[incrementCount] <bool> - increments count by wave number
[countFactor] <int> - this number is multiplied by the wave and then added to count only if incrementCount is true
[incrementHealth] <bool> - increments health by wave number times healthFactor (default is 5)
[healthFactor] <int> - this number is multiplied by the wave and then added to health only if incrementHealth is true (default is 5)
}]
}
*/
let Maps = {
width: 20, // Width of the map
height: 20, // Height of the map
@ -175,8 +208,8 @@ window.onload = function () {
enemies: [{
type: 'basic',
count: 5,
inclCount: true,
inclHealth: true
incrementCount: true,
incrementHealth: true
}]
},
{
@ -187,14 +220,14 @@ window.onload = function () {
enemies: [{
type: 'basic',
count: 5,
inclCount: true,
inclHealth: true
incrementCount: true,
incrementHealth: true
},
{
type: 'speedy',
count: 10,
inclCount: true,
inclHealth: true
incrementCount: true,
incrementHealth: true
}]
},
{
@ -204,14 +237,16 @@ window.onload = function () {
enemies: [{
type: 'basic',
count: 5,
inclCount: true,
inclHealth: true
incrementCount: true,
incrementHealth: true,
healthFactor: 10
},
{
type: 'speedy',
count: 10,
inclCount: true,
inclHealth: true
incrementCount: true,
incrementHealth: true,
healthFactor: 10
}]
},
{
@ -221,8 +256,8 @@ window.onload = function () {
enemies: [{
type: 'tough',
count: 5,
inclCount: true,
inclHealth: true
incrementCount: true,
incrementHealth: true
}]
},
{
@ -230,7 +265,7 @@ window.onload = function () {
wave: 3,
enemies: [{
type: 'tough',
count: 2
count: 1
}]
}
]
@ -632,16 +667,16 @@ window.onload = function () {
let eHealthIncl = 0
let multiply = wv.oneAfterAnother != null ? wv.oneAfterAnother : false
if (e.inclCount === true) {
eCount += Game.wave
if (e.incrementCount === true) {
eCount += Game.wave * (e.countFactor != null ? e.countFactor : 1)
}
if (e.baseHealth) {
eHealthIncl = e.baseHealth
}
if (e.inclHealth === true) {
eHealthIncl = Game.wave * 5
if (e.incrementHealth === true) {
eHealthIncl = Game.wave * (e.healthFactor != null ? e.healthFactor : 5)
if (eHealthIncl > 500) {
eHealthIncl = 500
}
@ -868,7 +903,7 @@ window.onload = function () {
if (can === false) break
let tower = Game.towers[j]
// tower placement restriction visualization
// Tower placement restriction around the tower
for (let i = 0; i < 4; i++) {
if (can === false) break
let ax = tower.x
@ -1027,11 +1062,13 @@ window.onload = function () {
// Draw enemies
for (let i in Game.enemies) {
let margin = .25 //A ratio of the width of a tile. .25 margins with 32 px tiles leave a 8 px margin on all sides, with the body being 16px x 16px
let enemy = Game.enemies[i]
let rx = (enemy.x * mt) + mt / 8
let ry = (enemy.y * mt) + mt / 8
let rx = (enemy.x + margin) * mt
let ry = (enemy.y + margin) * mt
let w = mt * (1 - margin * 2)
ctx.fillStyle = enemy.icon
ctx.fillRect(rx, ry, 16, 16)
ctx.fillRect(rx, ry, w, w)
// health bars
let hx = rx - 6