From c83f4bca89f524244bc64219be963f0f7d304900 Mon Sep 17 00:00:00 2001 From: Will Lewis Date: Mon, 21 Nov 2016 15:57:38 -0500 Subject: [PATCH 1/8] Add base chaos wizard --- .../images/sprites/monsters/chaos_alpha.png | Bin 0 -> 213 bytes .../images/sprites/monsters/chaos_omega.png | Bin 0 -> 216 bytes source/index.js | 8 ++++++++ source/scripts/data/index.js | 4 ++++ source/scripts/data/monsters.js | 19 ++++++++++++++++++ 5 files changed, 31 insertions(+) create mode 100755 source/images/sprites/monsters/chaos_alpha.png create mode 100755 source/images/sprites/monsters/chaos_omega.png diff --git a/source/images/sprites/monsters/chaos_alpha.png b/source/images/sprites/monsters/chaos_alpha.png new file mode 100755 index 0000000000000000000000000000000000000000..6cb18036cad78b9a748fe111760f560079d167fc GIT binary patch literal 213 zcmeAS@N?(olHy`uVBq!ia0vp^0zfRm!2~304!w#7Qfwtbe!)PRfq_wSp*cH{?(%eT z46*3l8WPQQzXw@?3y9mR?eVLNk!JV7cMYw8pwl4kD z{i?F+>xoORex18Ced98#OZVQaHEC{=Pcyw?cdh2)>iGxsTZCONr*S`<^587Ud7iF* JF6*2UngFv&Qz-xd literal 0 HcmV?d00001 diff --git a/source/images/sprites/monsters/chaos_omega.png b/source/images/sprites/monsters/chaos_omega.png new file mode 100755 index 0000000000000000000000000000000000000000..13dcf8c21681404783467379ff60366b3b99645e GIT binary patch literal 216 zcmeAS@N?(olHy`uVBq!ia0vp^0zfRm!2~304!w#7Qfwtbe!)PRfq_wSp*cH{?)7wW z46*3l8sf-zK!GFs?7#m{Ha1I7(t0&*&Bun8TU>!mN0>KH)~VG|a4_y}%z3=)yh8WQ zm+9Rd=?o@;&nqron6xY_@L8RM0JEOx#H{OVywBFKfF Lu6{1-oD!M Date: Mon, 21 Nov 2016 15:58:45 -0500 Subject: [PATCH 2/8] Bump up the chaos wizard's health --- source/scripts/data/monsters.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/scripts/data/monsters.js b/source/scripts/data/monsters.js index e7e7854..4335b6e 100644 --- a/source/scripts/data/monsters.js +++ b/source/scripts/data/monsters.js @@ -228,7 +228,7 @@ export default { CHAOS_WIZARD: { sprite: DATA.SPRITES.MONSTERS.CHAOS_WIZARD, color: DATA.COLORS.BROWN, - health: 1, + health: 20, strength: 1, movement: function () { if(this.getOffscreenMovement()) { From 802772d9dfd04dbc2b163acb58a27e3b095e9c22 Mon Sep 17 00:00:00 2001 From: Will Lewis Date: Mon, 21 Nov 2016 17:09:04 -0500 Subject: [PATCH 3/8] Make chaos wizard spawn and move without regards to its health or the quantity of bats --- source/scripts/data/monsters.js | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/source/scripts/data/monsters.js b/source/scripts/data/monsters.js index 4335b6e..1244e41 100644 --- a/source/scripts/data/monsters.js +++ b/source/scripts/data/monsters.js @@ -230,7 +230,48 @@ export default { color: DATA.COLORS.BROWN, health: 20, strength: 1, + turnCounter: function() { + /* + * phase indicates the shifting of alpha/omega or stand/move + * turn count indicates how many of the wizard's turns are remaining before a spawn + * pause count indicates how many of the player's turns are remaining before the wizard resumes moving + */ + this.pauseCount = this.pauseCount || 0 + this.turnCount = this.turnCount || 4 + + if (this.pauseCount <= 0 ) { + this.phase = !this.phase + this.turnCount -= 1 + } else { + this.pauseCount -= 1 + } + if (this.turnCount <= 0) { + this.phase = !this.phase + this.pauseCount = 6 + this.turnCount = 8; + [ + {x: this.position.x, y: this.position.y}, + {x: this.position.x, y: this.position.y}, + {x: this.position.x, y: this.position.y}, + {x: this.position.x, y: this.position.y}, + ].forEach((position) => { + var child = new Monster(this.game, { + protomonster: MONSTERS.RED_BAT, + position: position, + }) + child.onDeath = function() { + this.game.wave.killcount += 1 + } + this.game.monsters.push(child) + }) + } + this.game.wave.message = + "phase: " + (this.phase ? 'will pause' : 'will move/attack') + "\n" + + "pause: " + this.pauseCount + "\n" + + "turn: " + this.turnCount; + }, movement: function () { + if (this.pauseCount > 0) {return} if(this.getOffscreenMovement()) { return this.getOffscreenMovement() } From 6392e90191b021e306651d2df38ae0dc356452df Mon Sep 17 00:00:00 2001 From: Will Lewis Date: Mon, 21 Nov 2016 18:48:27 -0500 Subject: [PATCH 4/8] Make chaos wizard spawn bats on hit --- source/scripts/data/monsters.js | 36 +++++++++++++++++++-------------- source/scripts/model/Monster.js | 5 ++++- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/source/scripts/data/monsters.js b/source/scripts/data/monsters.js index 1244e41..a197f04 100644 --- a/source/scripts/data/monsters.js +++ b/source/scripts/data/monsters.js @@ -230,6 +230,23 @@ export default { color: DATA.COLORS.BROWN, health: 20, strength: 1, + spawnSomeBats: function() { + [ + {x: this.position.x, y: this.position.y}, + {x: this.position.x, y: this.position.y}, + {x: this.position.x, y: this.position.y}, + {x: this.position.x, y: this.position.y}, + ].forEach((position) => { + var child = new Monster(this.game, { + protomonster: MONSTERS.RED_BAT, + position: position, + }) + child.onDeath = function() { + this.game.wave.killcount += 1 + } + this.game.monsters.push(child) + }) + } turnCounter: function() { /* * phase indicates the shifting of alpha/omega or stand/move @@ -249,21 +266,7 @@ export default { this.phase = !this.phase this.pauseCount = 6 this.turnCount = 8; - [ - {x: this.position.x, y: this.position.y}, - {x: this.position.x, y: this.position.y}, - {x: this.position.x, y: this.position.y}, - {x: this.position.x, y: this.position.y}, - ].forEach((position) => { - var child = new Monster(this.game, { - protomonster: MONSTERS.RED_BAT, - position: position, - }) - child.onDeath = function() { - this.game.wave.killcount += 1 - } - this.game.monsters.push(child) - }) + this.spawnSomeBats() } this.game.wave.message = "phase: " + (this.phase ? 'will pause' : 'will move/attack') + "\n" + @@ -283,6 +286,9 @@ export default { ] choices = this.pruneMovement(choices) return choices[Math.floor((Math.random() * choices.length))] + }, + onHit: function() { + spawnSomeBats() } }, } diff --git a/source/scripts/model/Monster.js b/source/scripts/model/Monster.js index ea3e497..6394658 100644 --- a/source/scripts/model/Monster.js +++ b/source/scripts/model/Monster.js @@ -38,6 +38,8 @@ export default class Monster { this.health = monster.protomonster.health || 1 + this.onHit = monster.protomonster.onHit || function () {} + } pickSprite() { @@ -63,7 +65,7 @@ export default class Monster { movement = movement || {} movement.x = movement.x || 0 movement.y = movement.y || 0 - + // collision with the camera if(this.position.x + movement.x < DATA.FRAME.WIDTH * 0 || this.position.x + movement.x >= DATA.FRAME.WIDTH * 1) { @@ -123,6 +125,7 @@ export default class Monster { handleAttack(damage) { this.health = this.health || 0 this.health -= damage + this.onHit() if(this.health <= 0) { this.onDeath() this.isDead = true From 8d25ae8d584e2f4682bf5431053d9931958ace9f Mon Sep 17 00:00:00 2001 From: Will Lewis Date: Mon, 21 Nov 2016 22:17:05 -0500 Subject: [PATCH 5/8] Fix some code linting issues and add chaos wizard spawn limit and decay --- source/scripts/data/monsters.js | 67 ++++++++++++++++++++------------- source/scripts/model/Monster.js | 2 + 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/source/scripts/data/monsters.js b/source/scripts/data/monsters.js index a197f04..9a1ae6a 100644 --- a/source/scripts/data/monsters.js +++ b/source/scripts/data/monsters.js @@ -230,23 +230,35 @@ export default { color: DATA.COLORS.BROWN, health: 20, strength: 1, - spawnSomeBats: function() { - [ - {x: this.position.x, y: this.position.y}, - {x: this.position.x, y: this.position.y}, - {x: this.position.x, y: this.position.y}, - {x: this.position.x, y: this.position.y}, - ].forEach((position) => { - var child = new Monster(this.game, { - protomonster: MONSTERS.RED_BAT, - position: position, - }) - child.onDeath = function() { - this.game.wave.killcount += 1 + onSpawn: function() { + this.spawnSomeBats = function() { + this.childCount = this.childCount || 0 + var countToSpawn = () => { + if (this.childCount < 4) { + return 4 + } else if (this.childCount < 8) { + return 2 + } else if (this.childCount < 12) { + return 1 + } else { + return 0 + } } - this.game.monsters.push(child) - }) - } + var parent = this + for(var i = 0; i < countToSpawn(); i += 1) { + var child = new Monster(this.game, { + protomonster: MONSTERS.RED_BAT, + position: {x: this.position.x, y: this.position.y}, + }) + child.onDeath = function() { + this.game.wave.killcount += 1 + parent.childCount -= 1 + } + this.game.monsters.push(child) + this.childCount += 1 + } + } + }, turnCounter: function() { /* * phase indicates the shifting of alpha/omega or stand/move @@ -259,22 +271,25 @@ export default { if (this.pauseCount <= 0 ) { this.phase = !this.phase this.turnCount -= 1 + if (this.turnCount <= 0) { + this.phase = !this.phase + this.pauseCount = 8 + this.turnCount = 10 + this.spawnSomeBats() + } } else { this.pauseCount -= 1 } - if (this.turnCount <= 0) { - this.phase = !this.phase - this.pauseCount = 6 - this.turnCount = 8; - this.spawnSomeBats() - } this.game.wave.message = - "phase: " + (this.phase ? 'will pause' : 'will move/attack') + "\n" + + "phase: " + (this.phase ? "will pause" : "will move/attack") + "\n" + "pause: " + this.pauseCount + "\n" + - "turn: " + this.turnCount; + "turn: " + this.turnCount + "\n" + + "children: " + this.childCount }, movement: function () { - if (this.pauseCount > 0) {return} + if (this.pauseCount > 0) { + return + } if(this.getOffscreenMovement()) { return this.getOffscreenMovement() } @@ -288,7 +303,7 @@ export default { return choices[Math.floor((Math.random() * choices.length))] }, onHit: function() { - spawnSomeBats() + this.spawnSomeBats() } }, } diff --git a/source/scripts/model/Monster.js b/source/scripts/model/Monster.js index 6394658..2c3d083 100644 --- a/source/scripts/model/Monster.js +++ b/source/scripts/model/Monster.js @@ -40,6 +40,8 @@ export default class Monster { this.onHit = monster.protomonster.onHit || function () {} + this.onSpawn = monster.protomonster.onSpawn || function () {} + this.onSpawn() } pickSprite() { From 0bc16144408c1430d010a065a7cab8416eae6780 Mon Sep 17 00:00:00 2001 From: Will Lewis Date: Mon, 21 Nov 2016 22:48:05 -0500 Subject: [PATCH 6/8] Make chaos wizard jump to a random position upon spawning bats --- source/scripts/data/monsters.js | 16 ++++++++++------ source/scripts/model/Monster.js | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/source/scripts/data/monsters.js b/source/scripts/data/monsters.js index 9a1ae6a..e164a2c 100644 --- a/source/scripts/data/monsters.js +++ b/source/scripts/data/monsters.js @@ -228,7 +228,7 @@ export default { CHAOS_WIZARD: { sprite: DATA.SPRITES.MONSTERS.CHAOS_WIZARD, color: DATA.COLORS.BROWN, - health: 20, + health: 10, strength: 1, onSpawn: function() { this.spawnSomeBats = function() { @@ -248,8 +248,9 @@ export default { for(var i = 0; i < countToSpawn(); i += 1) { var child = new Monster(this.game, { protomonster: MONSTERS.RED_BAT, - position: {x: this.position.x, y: this.position.y}, + position: {x: this.position.x, y: this.position.y} }) + child.phase = true child.onDeath = function() { this.game.wave.killcount += 1 parent.childCount -= 1 @@ -257,6 +258,8 @@ export default { this.game.monsters.push(child) this.childCount += 1 } + var newPosition = this.getFreeSpace() + this.position = newPosition } }, turnCounter: function() { @@ -281,10 +284,11 @@ export default { this.pauseCount -= 1 } this.game.wave.message = - "phase: " + (this.phase ? "will pause" : "will move/attack") + "\n" + - "pause: " + this.pauseCount + "\n" + - "turn: " + this.turnCount + "\n" + - "children: " + this.childCount + "health: " + this.health + // "phase: " + (this.phase ? "will pause" : "will move/attack") + "\n" + + // "pause: " + this.pauseCount + "\n" + + // "turn: " + this.turnCount + "\n" + + // "children: " + this.childCount }, movement: function () { if (this.pauseCount > 0) { diff --git a/source/scripts/model/Monster.js b/source/scripts/model/Monster.js index 2c3d083..7c4d2d5 100644 --- a/source/scripts/model/Monster.js +++ b/source/scripts/model/Monster.js @@ -198,4 +198,25 @@ export default class Monster { } return false } + getFreeSpace(depth) { + depth = depth || 0 + if (depth > 10) { + return {x: this.x, y: this.y} + } + var x = Math.floor((Math.random() * DATA.FRAME.WIDTH)) + var y = Math.floor((Math.random() * DATA.FRAME.HEIGHT * this.game.adventurer.wave * -1)) + this.game.monsters.forEach((monster) => { + if (monster) { + if (monster.position.x == x && monster.position.y == y) { + return this.getFreeSpace(depth + 1) + } + } + }) + if (this.game.adventurer) { + if (this.game.adventurer.position.x == x && this.game.adventurer.position.y == y) { + return this.getFreeSpace(depth + 1) + } + } + return {x: x, y: y} + } } From ccc23cb74b21937cf9131bd685d3abfc8d9d0510 Mon Sep 17 00:00:00 2001 From: Will Lewis Date: Mon, 21 Nov 2016 22:58:37 -0500 Subject: [PATCH 7/8] Make chaos wizard spawn counts vary based on health and adjust turn/pause counts --- source/scripts/data/monsters.js | 36 +++++++++++++++--------------- source/scripts/model/Adventurer.js | 16 ++++++------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/source/scripts/data/monsters.js b/source/scripts/data/monsters.js index e164a2c..de49334 100644 --- a/source/scripts/data/monsters.js +++ b/source/scripts/data/monsters.js @@ -234,29 +234,29 @@ export default { this.spawnSomeBats = function() { this.childCount = this.childCount || 0 var countToSpawn = () => { - if (this.childCount < 4) { + if (this.health < 3) { + return 8 + } else if (this.health < 6) { return 4 - } else if (this.childCount < 8) { - return 2 - } else if (this.childCount < 12) { - return 1 } else { - return 0 + return 2 } } var parent = this for(var i = 0; i < countToSpawn(); i += 1) { - var child = new Monster(this.game, { - protomonster: MONSTERS.RED_BAT, - position: {x: this.position.x, y: this.position.y} - }) - child.phase = true - child.onDeath = function() { - this.game.wave.killcount += 1 - parent.childCount -= 1 + if (this.childCount < 12) { + var child = new Monster(this.game, { + protomonster: MONSTERS.RED_BAT, + position: {x: this.position.x, y: this.position.y} + }) + child.phase = true + child.onDeath = function() { + this.game.wave.killcount += 1 + parent.childCount -= 1 + } + this.game.monsters.push(child) + this.childCount += 1 } - this.game.monsters.push(child) - this.childCount += 1 } var newPosition = this.getFreeSpace() this.position = newPosition @@ -276,8 +276,8 @@ export default { this.turnCount -= 1 if (this.turnCount <= 0) { this.phase = !this.phase - this.pauseCount = 8 - this.turnCount = 10 + this.pauseCount = 4 + this.turnCount = 4 this.spawnSomeBats() } } else { diff --git a/source/scripts/model/Adventurer.js b/source/scripts/model/Adventurer.js index 710b465..f0e6873 100644 --- a/source/scripts/model/Adventurer.js +++ b/source/scripts/model/Adventurer.js @@ -23,9 +23,9 @@ export default class Adventurer { this.maxhealth = 3 this.health = this.maxhealth - + this.wave = 0 - + this.grabCount = 0 this.grabMonster = null } @@ -58,7 +58,7 @@ export default class Adventurer { this.animation = false var didSomething = false - + // collision with room if(this.position.x + movement.x < DATA.FRAME.WIDTH * 0 || this.position.x + movement.x >= DATA.FRAME.WIDTH * 1) { @@ -75,7 +75,7 @@ export default class Adventurer { console.log("!!") movement.y = 0 } - + this.bloodscreen = false if(this.grabCount == 0) { @@ -86,9 +86,9 @@ export default class Adventurer { if(this.position.x + movement.x == monster.position.x && this.position.y + movement.y == monster.position.y) { monster.handleAttack(1) - + didSomething = true - + if(movement.x < 0 && movement.y == 0) { this.animation = "attack-westwards" } else if(movement.x > 0 && movement.y == 0) { @@ -126,7 +126,7 @@ export default class Adventurer { } } } - + // translation this.position.x += movement.x this.position.y += movement.y @@ -155,7 +155,7 @@ export default class Adventurer { this.grabCount = this.grabCount - 1 this.grabMonster.handleAttack(1) } - + // signaling if(didSomething || movement.x != 0 || movement.y != 0) { this.game.onAction() From 27e30267dbb1d4d51362ef8c8c7a783e05d9ea5d Mon Sep 17 00:00:00 2001 From: Will Lewis Date: Mon, 21 Nov 2016 23:06:28 -0500 Subject: [PATCH 8/8] Don't allow chaos wizard to perform turn based spawning of bats when the player is near --- source/scripts/data/monsters.js | 12 ++++-------- source/scripts/model/Monster.js | 4 ++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/scripts/data/monsters.js b/source/scripts/data/monsters.js index de49334..254d85a 100644 --- a/source/scripts/data/monsters.js +++ b/source/scripts/data/monsters.js @@ -276,19 +276,15 @@ export default { this.turnCount -= 1 if (this.turnCount <= 0) { this.phase = !this.phase - this.pauseCount = 4 this.turnCount = 4 - this.spawnSomeBats() + if (this.getDistanceToAdventurer() > 2) { + this.spawnSomeBats() + this.pauseCount = 4 + } } } else { this.pauseCount -= 1 } - this.game.wave.message = - "health: " + this.health - // "phase: " + (this.phase ? "will pause" : "will move/attack") + "\n" + - // "pause: " + this.pauseCount + "\n" + - // "turn: " + this.turnCount + "\n" + - // "children: " + this.childCount }, movement: function () { if (this.pauseCount > 0) { diff --git a/source/scripts/model/Monster.js b/source/scripts/model/Monster.js index 7c4d2d5..fb4bbb1 100644 --- a/source/scripts/model/Monster.js +++ b/source/scripts/model/Monster.js @@ -219,4 +219,8 @@ export default class Monster { } return {x: x, y: y} } + + getDistanceToAdventurer() { + return Math.abs(this.game.adventurer.position.x - this.position.x) + Math.abs(this.game.adventurer.position.y - this.position.y) + } }