Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chaos wizard #60

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Binary file added source/images/sprites/monsters/chaos_alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/images/sprites/monsters/chaos_omega.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ state.game = new Game({
"Move ↑↑↑ to the next room."
].join("\n")
},
{
capacity: 1,
killcount: 1,
monsters: [
MONSTERS.CHAOS_WIZARD,
],
message: "Room 0: chaos wizard",
},
// orcs
{
capacity: function() {
Expand Down
4 changes: 4 additions & 0 deletions source/scripts/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export default {
ALPHA: require("images/sprites/monsters/thief_alpha.png"),
OMEGA: require("images/sprites/monsters/thief_omega.png"),
},
CHAOS_WIZARD: {
ALPHA: require("images/sprites/monsters/chaos_alpha.png"),
OMEGA: require("images/sprites/monsters/chaos_omega.png"),
},
},
EFFECTS: {
SLICE: [
Expand Down
81 changes: 81 additions & 0 deletions source/scripts/data/monsters.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,85 @@ export default {
}
}
},
CHAOS_WIZARD: {
sprite: DATA.SPRITES.MONSTERS.CHAOS_WIZARD,
color: DATA.COLORS.BROWN,
health: 10,
strength: 1,
onSpawn: function() {
this.spawnSomeBats = function() {
this.childCount = this.childCount || 0
var countToSpawn = () => {
if (this.health < 3) {
return 8
} else if (this.health < 6) {
return 4
} else {
return 2
}
}
var parent = this
for(var i = 0; i < countToSpawn(); i += 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
}
}
var newPosition = this.getFreeSpace()
this.position = newPosition
}
},
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
if (this.turnCount <= 0) {
this.phase = !this.phase
this.turnCount = 4
if (this.getDistanceToAdventurer() > 2) {
this.spawnSomeBats()
this.pauseCount = 4
}
}
} else {
this.pauseCount -= 1
}
},
movement: function () {
if (this.pauseCount > 0) {
return
}
if(this.getOffscreenMovement()) {
return this.getOffscreenMovement()
}
var choices = [
{x: -1},
{x: +1},
{y: -1},
{y: +1}
]
choices = this.pruneMovement(choices)
return choices[Math.floor((Math.random() * choices.length))]
},
onHit: function() {
this.spawnSomeBats()
}
},
}
16 changes: 8 additions & 8 deletions source/scripts/model/Adventurer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export default class Adventurer {

this.maxhealth = 3
this.health = this.maxhealth

this.wave = 0

this.grabCount = 0
this.grabMonster = null
}
Expand Down Expand Up @@ -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) {
Expand All @@ -75,7 +75,7 @@ export default class Adventurer {
console.log("!!")
movement.y = 0
}

this.bloodscreen = false

if(this.grabCount == 0) {
Expand All @@ -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) {
Expand Down Expand Up @@ -126,7 +126,7 @@ export default class Adventurer {
}
}
}

// translation
this.position.x += movement.x
this.position.y += movement.y
Expand Down Expand Up @@ -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()
Expand Down
32 changes: 31 additions & 1 deletion source/scripts/model/Monster.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default class Monster {

this.health = monster.protomonster.health || 1

this.onHit = monster.protomonster.onHit || function () {}

this.onSpawn = monster.protomonster.onSpawn || function () {}
this.onSpawn()

}
pickSprite() {
Expand All @@ -63,7 +67,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) {
Expand Down Expand Up @@ -123,6 +127,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
Expand Down Expand Up @@ -193,4 +198,29 @@ 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}
}

getDistanceToAdventurer() {
return Math.abs(this.game.adventurer.position.x - this.position.x) + Math.abs(this.game.adventurer.position.y - this.position.y)
}
}