Add turning and monster attack anim
This commit is contained in:
parent
abd4a629dd
commit
c968f7a9a6
|
@ -25,6 +25,7 @@ export class AnimalEntity extends Entity {
|
||||||
nextYell: number = 1000
|
nextYell: number = 1000
|
||||||
dead: boolean = false
|
dead: boolean = false
|
||||||
shouldGib: boolean = false
|
shouldGib: boolean = false
|
||||||
|
actionCooldown: number = 0
|
||||||
|
|
||||||
constructor(def: AnimalDefinition) {
|
constructor(def: AnimalDefinition) {
|
||||||
super(`${def.name}.animal.stand.west.0`)
|
super(`${def.name}.animal.stand.west.0`)
|
||||||
|
@ -73,6 +74,7 @@ export class AnimalEntity extends Entity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let shouldMove = false
|
let shouldMove = false
|
||||||
|
let shouldAttack = false
|
||||||
if (this.action) {
|
if (this.action) {
|
||||||
// FIXME: Use physics.
|
// FIXME: Use physics.
|
||||||
switch(this.action.type) {
|
switch(this.action.type) {
|
||||||
|
@ -117,7 +119,7 @@ export class AnimalEntity extends Entity {
|
||||||
shouldMove = true
|
shouldMove = true
|
||||||
break
|
break
|
||||||
case 'attack':
|
case 'attack':
|
||||||
this.yell(1)
|
shouldAttack = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if (this.direction > 360) {
|
if (this.direction > 360) {
|
||||||
|
@ -127,7 +129,12 @@ export class AnimalEntity extends Entity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldMove) {
|
this.actionCooldown += delta
|
||||||
|
if (this.actionCooldown >= 750 - 750 * this.mode.cdr) {
|
||||||
|
if (shouldAttack) {
|
||||||
|
this.attack()
|
||||||
|
this.actionCooldown = 0
|
||||||
|
} else if (shouldMove) {
|
||||||
this.stepSoundElapsed += delta
|
this.stepSoundElapsed += delta
|
||||||
let r = this.direction * (Math.PI/180)
|
let r = this.direction * (Math.PI/180)
|
||||||
if (Math.abs(this.velocity[0]) < this.mode.maxSpeed) {
|
if (Math.abs(this.velocity[0]) < this.mode.maxSpeed) {
|
||||||
|
@ -141,17 +148,24 @@ export class AnimalEntity extends Entity {
|
||||||
if (this.sprite.subsetKey !== cardinal || this.sprite.subsetKey !== 'run') {
|
if (this.sprite.subsetKey !== cardinal || this.sprite.subsetKey !== 'run') {
|
||||||
this.sprite.setCtor(`${this.sprite.spriteKey}.${this.sprite.animationKey}.${this.sprite.setKey}.${cardinal}.${this.sprite.frameIndex}`)
|
this.sprite.setCtor(`${this.sprite.spriteKey}.${this.sprite.animationKey}.${this.sprite.setKey}.${cardinal}.${this.sprite.frameIndex}`)
|
||||||
}
|
}
|
||||||
if (this.stepSoundElapsed >= 200) {
|
if (this.stepSoundElapsed >= 200*(this.isMonster?1.5:1)) {
|
||||||
let v = 1 + Math.floor(Math.random() * 3)
|
let v = 1 + Math.floor(Math.random() * 4)
|
||||||
|
if (this.isMonster) {
|
||||||
|
playSound('action/footstep-big-v'+v, 0.5)
|
||||||
|
} else {
|
||||||
playSound('action/footstep-tiny-v'+v, 0.5)
|
playSound('action/footstep-tiny-v'+v, 0.5)
|
||||||
|
}
|
||||||
this.stepSoundElapsed = 0
|
this.stepSoundElapsed = 0
|
||||||
}
|
}
|
||||||
this.sprite.animate = true
|
this.sprite.animate = true
|
||||||
|
this.sprite.loop = true
|
||||||
} else {
|
} else {
|
||||||
this.sprite.animate = false
|
this.sprite.animate = false
|
||||||
|
this.sprite.loop = true
|
||||||
this.sprite.setKey = 'stand'
|
this.sprite.setKey = 'stand'
|
||||||
this.sprite.setCtor(`${this.sprite.spriteKey}.${this.sprite.animationKey}.${this.sprite.setKey}.${this.getCardinal(this.direction)}.0`)
|
this.sprite.setCtor(`${this.sprite.spriteKey}.${this.sprite.animationKey}.${this.sprite.setKey}.${this.getCardinal(this.direction)}.0`)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
this.velocity[0] *= 0.65
|
this.velocity[0] *= 0.65
|
||||||
|
@ -263,11 +277,35 @@ export class AnimalEntity extends Entity {
|
||||||
this.seenTarget = undefined
|
this.seenTarget = undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
turn() {
|
||||||
|
this.isMonster = !this.isMonster
|
||||||
|
if (this.isMonster) {
|
||||||
|
console.log(`${this.sprite.spriteKey}.monster.${this.sprite.setKey}.${this.sprite.subsetKey}.${this.sprite.frameIndex}`)
|
||||||
|
this.sprite.setCtor(`${this.sprite.spriteKey}.monster.${this.sprite.setKey}.${this.sprite.subsetKey}.${this.sprite.frameIndex}`)
|
||||||
|
} else {
|
||||||
|
console.log(`${this.sprite.spriteKey}.animal.${this.sprite.setKey}.${this.sprite.subsetKey}.${this.sprite.frameIndex}`)
|
||||||
|
this.sprite.setCtor(`${this.sprite.spriteKey}.animal.${this.sprite.setKey}.${this.sprite.subsetKey}.${this.sprite.frameIndex}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attack() {
|
||||||
|
this.yell(1)
|
||||||
|
if (this.isMonster) {
|
||||||
|
let v = 1 + Math.floor(Math.random() * 4)
|
||||||
|
playSound(`action/hit-v${v}`, 1.0)
|
||||||
|
this.sprite.animate = true
|
||||||
|
this.sprite.loop = false
|
||||||
|
this.sprite.setKey = 'attack'
|
||||||
|
this.sprite.frameIndex = 0
|
||||||
|
this.sprite.setCtor(`${this.sprite.spriteKey}.${this.sprite.animationKey}.${this.sprite.setKey}.${this.sprite.subsetKey}.${this.sprite.frameIndex}`)
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
yell(volume: number) {
|
yell(volume: number) {
|
||||||
if (this.lastYellElapsed > this.nextYell) {
|
if (this.lastYellElapsed > this.nextYell) {
|
||||||
this.nextYell = 500 + Math.random()*3000
|
this.nextYell = 500 + Math.random()*3000
|
||||||
this.lastYellElapsed = 0
|
this.lastYellElapsed = 0
|
||||||
let v = 1 + Math.floor(Math.random() * 2)
|
let v = 1 + Math.floor(Math.random() * 3)
|
||||||
if (this.isMonster) {
|
if (this.isMonster) {
|
||||||
playSound(`monsters/evil-${this.def.name}-v${v}`, volume)
|
playSound(`monsters/evil-${this.def.name}-v${v}`, volume)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user