Add monster logic
This commit is contained in:
parent
52d49ed9c2
commit
b534e23580
|
@ -190,14 +190,21 @@ 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)
|
||||||
|
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 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)
|
let a = r * (180 / Math.PI)
|
||||||
if (a < 0) {
|
if (a < 0) {
|
||||||
a += 360
|
a += 360
|
||||||
}
|
}
|
||||||
|
// Invert direction if not a monster.
|
||||||
|
if (!this.isMonster) {
|
||||||
a -= 180
|
a -= 180
|
||||||
|
}
|
||||||
if (a < 0) {
|
if (a < 0) {
|
||||||
a = 360 - a
|
a = 360 - a
|
||||||
}
|
}
|
||||||
|
@ -213,7 +220,9 @@ export class AnimalEntity extends Entity {
|
||||||
if (a < 0) {
|
if (a < 0) {
|
||||||
a += 360
|
a += 360
|
||||||
}
|
}
|
||||||
|
if (!this.isMonster) {
|
||||||
a -= 180
|
a -= 180
|
||||||
|
}
|
||||||
if (a < 0) {
|
if (a < 0) {
|
||||||
a = 360 - a
|
a = 360 - a
|
||||||
}
|
}
|
||||||
|
@ -236,7 +245,6 @@ export class AnimalEntity extends Entity {
|
||||||
this.wanderTimer = 0
|
this.wanderTimer = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this.thinkTimer -= 100
|
this.thinkTimer -= 100
|
||||||
this.act(this.desiredActions)
|
this.act(this.desiredActions)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user