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,51 +190,59 @@ export class AnimalEntity extends Entity {
think(delta: number) { think(delta: number) {
this.thinkTimer += delta this.thinkTimer += delta
while (this.thinkTimer >= 100) { while (this.thinkTimer >= 100) {
if (!this.isMonster) { if (this.seenTarget && this.isMonster && planck.Vec2.distance(planck.Vec2(this.x, this.y), planck.Vec2(this.seenTarget.x, this.seenTarget.y)) < 35) {
if (this.seenTarget) { this.desiredActions = adjustAction([], 'attack', 1)
let r = Math.atan2(this.y-(this.seenTarget.y+10), this.x-this.seenTarget.x) // FIXME: 10 ain't right son if (Math.random() > 1 - this.mode.laziness/4) {
let a = r * (180 / Math.PI) this.desiredActions = []
if (a < 0) { }
a += 360 } 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 a -= 180
if (a < 0) { }
a = 360 - a if (a < 0) {
} a = 360 - a
}
this.desiredActions = adjustAction([], this.getCardinal(a), 0.85)
this.desiredActions = adjustAction(this.desiredActions, this.getCardinal(Math.random()*360), Math.random())
if (Math.random() > 1 - this.mode.erratic) {
this.desiredActions = adjustAction(this.desiredActions, this.getCardinal(Math.random()*360), 1)
}
this.yell(1)
} else if (this.smelledTarget) {
let r = Math.atan2(this.y-this.smelledTarget.y, this.x-this.smelledTarget.x)
let a = r * (180 / Math.PI)
if (a < 0) {
a += 360
}
if (!this.isMonster) {
a -= 180
}
if (a < 0) {
a = 360 - a
}
// 5% to walk away, otherwise just chill.
if (Math.random() > 0.95) {
this.desiredActions = adjustAction([], this.getCardinal(a), 0.85) this.desiredActions = adjustAction([], this.getCardinal(a), 0.85)
this.desiredActions = adjustAction(this.desiredActions, this.getCardinal(Math.random()*360), Math.random()) }
if (Math.random() > 1 - this.mode.erratic) { } else {
this.desiredActions = adjustAction(this.desiredActions, this.getCardinal(Math.random()*360), 1) this.wanderTimer += delta
if (this.wanderTimer >= this.nextWander) {
this.nextWander = Math.max(10, Math.random() * 100)
if (Math.random() > 1 - this.mode.laziness) {
this.desiredActions = []
} else {
this.desiredActions = adjustAction([], this.getCardinal(Math.random()*360), 1)
} }
this.yell(1) if (Math.random() > 1 - this.mode.noisiness) {
} else if (this.smelledTarget) { this.yell(0.1)
let r = Math.atan2(this.y-this.smelledTarget.y, this.x-this.smelledTarget.x)
let a = r * (180 / Math.PI)
if (a < 0) {
a += 360
}
a -= 180
if (a < 0) {
a = 360 - a
}
// 5% to walk away, otherwise just chill.
if (Math.random() > 0.95) {
this.desiredActions = adjustAction([], this.getCardinal(a), 0.85)
}
} else {
this.wanderTimer += delta
if (this.wanderTimer >= this.nextWander) {
this.nextWander = Math.max(10, Math.random() * 100)
if (Math.random() > 1 - this.mode.laziness) {
this.desiredActions = []
} else {
this.desiredActions = adjustAction([], this.getCardinal(Math.random()*360), 1)
}
if (Math.random() > 1 - this.mode.noisiness) {
this.yell(0.1)
}
this.wanderTimer = 0
} }
this.wanderTimer = 0
} }
} }
this.thinkTimer -= 100 this.thinkTimer -= 100