feat: implementing attack
This commit is contained in:
parent
42b58824cc
commit
6f4bbeb885
|
@ -81,7 +81,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "ATTACK",
|
"name": "ATTACK",
|
||||||
"repeat": true,
|
"repeat": false,
|
||||||
"frames": [
|
"frames": [
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
|
|
|
@ -12,7 +12,7 @@ export default class Alert extends EnemyState {
|
||||||
let position = this.parent.getPlayerPosition();
|
let position = this.parent.getPlayerPosition();
|
||||||
if (position) {
|
if (position) {
|
||||||
this.parent.velocity.x = this.parent.maxSpeed * Math.sign(position.x - this.owner.position.x);
|
this.parent.velocity.x = this.parent.maxSpeed * Math.sign(position.x - this.owner.position.x);
|
||||||
if (this.parent.attackTimer.isStopped()) {
|
if (this.parent.attackTimer.isStopped() && this.owner.position.distanceTo(position)<=32) {
|
||||||
this.finished(EnemyStates.ATTACK);
|
this.finished(EnemyStates.ATTACK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,31 +8,27 @@ export default class Attack extends EnemyState {
|
||||||
protected attacked: string;
|
protected attacked: string;
|
||||||
|
|
||||||
onEnter(options: Record<string, any>): void {
|
onEnter(options: Record<string, any>): void {
|
||||||
let event = this.owner.id+"charged";
|
this.parent.attackTimer.start();
|
||||||
(<AnimatedSprite>this.owner).animation.play("DYING", false, event);
|
this.parent.velocity.x = 0;
|
||||||
this.receiver.subscribe(event);
|
this.charged = this.owner.id+"charged";
|
||||||
|
this.attacked = this.owner.id+"attacked";
|
||||||
|
(<AnimatedSprite>this.owner).animation.play("DYING", false, this.charged);
|
||||||
|
this.receiver.subscribe(this.charged);
|
||||||
|
this.receiver.subscribe(this.attacked);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(deltaT: number): void {
|
update(deltaT: number): void {
|
||||||
while (this.receiver.hasNextEvent()) {
|
while (this.receiver.hasNextEvent()) {
|
||||||
this.receiver.getNextEvent();
|
let event = this.receiver.getNextEvent().type;
|
||||||
|
switch (event) {
|
||||||
|
case this.charged:
|
||||||
|
(<AnimatedSprite>this.owner).animation.play("ATTACK", false, this.attacked);
|
||||||
|
break;
|
||||||
|
case this.attacked:
|
||||||
|
this.finished(EnemyStates.ALERT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let position = this.parent.getPlayerPosition();
|
|
||||||
if (position) {
|
|
||||||
this.parent.velocity.x = this.parent.maxSpeed * Math.sign(position.x - this.owner.position.x);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.parent.velocity.x = 0;
|
|
||||||
this.finished(EnemyStates.PATROL);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.parent.direction = this.parent.velocity.x >= 0 ? 1 : -1;
|
|
||||||
if (!this.canWalk()) {
|
|
||||||
this.parent.velocity.x = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
(<Sprite>this.owner).invertX = this.parent.direction === 1 ? true : false ;
|
|
||||||
super.update(deltaT);
|
super.update(deltaT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user