diff --git a/source/index.js b/source/index.js index b71f4d8..9c0d31b 100644 --- a/source/index.js +++ b/source/index.js @@ -51,7 +51,7 @@ state.game = new Game({ }, killcount: 10, monsters: [ - MONSTERS.RED_ORC, + MONSTERS.THIEF_OF_THE_NIGHT, ], message: "Room 1: Golem Orcs", }, diff --git a/source/scripts/data/monsters.js b/source/scripts/data/monsters.js index 4e6fb91..8632d9e 100644 --- a/source/scripts/data/monsters.js +++ b/source/scripts/data/monsters.js @@ -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 + } + } + } + }, } diff --git a/source/scripts/model/Adventurer.js b/source/scripts/model/Adventurer.js index 710b465..8a3373e 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) { @@ -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) { @@ -126,7 +127,7 @@ export default class Adventurer { } } } - + // translation this.position.x += movement.x this.position.y += movement.y @@ -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() diff --git a/source/scripts/model/Monster.js b/source/scripts/model/Monster.js index ea3e497..4b8181b 100644 --- a/source/scripts/model/Monster.js +++ b/source/scripts/model/Monster.js @@ -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 () { @@ -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) { @@ -112,6 +114,7 @@ export default class Monster { y: this.position.y + movement.y, } })) + movement.x = 0 movement.y = 0 } @@ -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) {