Add monster logic

This commit is contained in:
Ketchetwahmeegwun T. Southall 2022-01-30 12:55:02 -08:00
parent 52d49ed9c2
commit b534e23580

View File

@ -190,14 +190,21 @@ export class AnimalEntity extends Entity {
think(delta: number) {
this.thinkTimer += delta
while (this.thinkTimer >= 100) {
if (!this.isMonster) {
if (this.seenTarget) {
if (this.seenTarget && this.isMonster && planck.Vec2.distance(planck.Vec2(this.x, this.y), planck.Vec2(this.seenTarget.x, this.seenTarget.y)) < 35) {
this.desiredActions = adjustAction([], 'attack', 1)
if (Math.random() > 1 - this.mode.laziness/4) {
this.desiredActions = []
}
} else if (this.seenTarget) {
let r = Math.atan2(this.y-(this.seenTarget.y+10), this.x-this.seenTarget.x) // FIXME: 10 ain't right son
let a = r * (180 / Math.PI)
if (a < 0) {
a += 360
}
// Invert direction if not a monster.
if (!this.isMonster) {
a -= 180
}
if (a < 0) {
a = 360 - a
}
@ -213,7 +220,9 @@ export class AnimalEntity extends Entity {
if (a < 0) {
a += 360
}
if (!this.isMonster) {
a -= 180
}
if (a < 0) {
a = 360 - a
}
@ -236,7 +245,6 @@ export class AnimalEntity extends Entity {
this.wanderTimer = 0
}
}
}
this.thinkTimer -= 100
this.act(this.desiredActions)
}