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

theif of the night #65

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ state.game = new Game({
},
killcount: 10,
monsters: [
MONSTERS.RED_ORC,
MONSTERS.THIEF_OF_THE_NIGHT,
],
message: "Room 1: Golem Orcs",
},
Expand Down
31 changes: 31 additions & 0 deletions source/scripts/data/monsters.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,35 @@ export default {
}
}
},
THIEF_OF_THE_NIGHT: {
sprite: DATA.SPRITES.MONSTERS.THIEF,
color: DATA.COLORS.GREEN,
health: 10,
strength: 2,
grabCounter: function() {
this.turnCount = this.turnCount || 0
//the adventurer cannot be grabbed by another monster and he cannot grab him more than once
if(this.game.adventurer.grabCount == 0 && this.turnCount == 0) {
this.turnCount = this.turnCount + 1
this.game.adventurer.grabCount += 3
this.game.adventurer.grabMonster = this
}
},
parry: function() {
if(this.game.adventurer.grabCount == 0) {
if(this.position.x > this.game.adventurer.position.x) {
this.position.x = this.position.x + 1
}
if(this.position.x < this.game.adventurer.position.x) {
this.position.x = this.position.x - 1
}
if(this.position.y > this.game.adventurer.position.y) {
this.position.y = this.position.y + 1
}
if(this.position.y < this.game.adventurer.position.y) {
this.position.y = this.position.y - 1
}
}
}
},
}
17 changes: 9 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 @@ -85,10 +85,11 @@ export default class Adventurer {
if(!monster.isDead) {
if(this.position.x + movement.x == monster.position.x
&& this.position.y + movement.y == monster.position.y) {
monster.handleAttack(1)

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 +127,7 @@ export default class Adventurer {
}
}
}

// translation
this.position.x += movement.x
this.position.y += movement.y
Expand Down Expand Up @@ -155,7 +156,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
6 changes: 5 additions & 1 deletion source/scripts/model/Monster.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export default class Monster {
if(dy < 0) return {y: -1}
}
}
this.parry = monster.protomonster.parry || function () {
}
this.grabCounter = monster.protomonster.grabCounter || function () {
}
this.turnCounter = monster.protomonster.turnCounter || function () {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -112,6 +114,7 @@ export default class Monster {
y: this.position.y + movement.y,
}
}))

movement.x = 0
movement.y = 0
}
Expand All @@ -121,6 +124,7 @@ export default class Monster {
this.position.y += movement.y
}
handleAttack(damage) {
this.parry()
this.health = this.health || 0
this.health -= damage
if(this.health <= 0) {
Expand Down