feat: tiger AI
This commit is contained in:
parent
3511dbae8b
commit
9aa76b7963
|
@ -40,6 +40,12 @@
|
||||||
"type": "player",
|
"type": "player",
|
||||||
"x": 5,
|
"x": 5,
|
||||||
"y": 10
|
"y": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Tiger",
|
||||||
|
"x": 3,
|
||||||
|
"y": 7,
|
||||||
|
"possibility": 1
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,6 @@ export default class Attack extends EnemyState {
|
||||||
this.receiver.subscribe(this.attacked);
|
this.receiver.subscribe(this.attacked);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(deltaT: number): void {
|
|
||||||
this.finished(EnemyStates.ALERT);
|
|
||||||
super.update(deltaT);
|
|
||||||
}
|
|
||||||
|
|
||||||
onExit(): Record<string, any> {
|
onExit(): Record<string, any> {
|
||||||
this.parent.isCharging = false;
|
this.parent.isCharging = false;
|
||||||
(<AnimatedSprite>this.owner).animation.stop();
|
(<AnimatedSprite>this.owner).animation.stop();
|
||||||
|
|
|
@ -31,7 +31,15 @@ export default abstract class EnemyState extends State {
|
||||||
this.parent.velocity.x = 0;
|
this.parent.velocity.x = 0;
|
||||||
}
|
}
|
||||||
// Do gravity
|
// Do gravity
|
||||||
|
if (this.owner.onGround) {
|
||||||
|
this.parent.velocity.y = 0;
|
||||||
|
}
|
||||||
|
else if (this.owner.onCeiling) {
|
||||||
|
this.parent.velocity.y += this.gravity * deltaT * 2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
this.parent.velocity.y += this.gravity * deltaT;
|
this.parent.velocity.y += this.gravity * deltaT;
|
||||||
|
}
|
||||||
this.owner.move(this.parent.velocity.scaled(deltaT));
|
this.owner.move(this.parent.velocity.scaled(deltaT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import Attack from "./Attack";
|
||||||
export default class TigerAttack extends Attack {
|
export default class TigerAttack extends Attack {
|
||||||
protected velocity: number;
|
protected velocity: number;
|
||||||
protected distance: number;
|
protected distance: number;
|
||||||
protected attacking: boolean = false;
|
|
||||||
|
|
||||||
onEnter(options: Record<string, any>): void {
|
onEnter(options: Record<string, any>): void {
|
||||||
super.onEnter(options);
|
super.onEnter(options);
|
||||||
|
@ -15,7 +14,7 @@ export default class TigerAttack extends Attack {
|
||||||
}
|
}
|
||||||
|
|
||||||
update(deltaT: number): void {
|
update(deltaT: number): void {
|
||||||
if (this.attacking && this.owner.onGround) {
|
if (this.parent.isAttaking && this.owner.onGround) {
|
||||||
this.emitter.fireEvent(this.attacked);
|
this.emitter.fireEvent(this.attacked);
|
||||||
}
|
}
|
||||||
while (this.receiver.hasNextEvent()) {
|
while (this.receiver.hasNextEvent()) {
|
||||||
|
@ -25,9 +24,9 @@ export default class TigerAttack extends Attack {
|
||||||
this.parent.isCharging = false;
|
this.parent.isCharging = false;
|
||||||
this.parent.isAttaking = true;
|
this.parent.isAttaking = true;
|
||||||
(<AnimatedSprite>this.owner).animation.play("ATTACK", true);
|
(<AnimatedSprite>this.owner).animation.play("ATTACK", true);
|
||||||
this.velocity = (this.parent.getPlayerPosition().x - this.owner.position.x)/2;
|
this.velocity = (this.parent.getPlayerPosition().x - this.owner.position.x)/1.5;
|
||||||
this.parent.direction = this.velocity >= 0 ? 1 : 0;
|
this.parent.direction = this.velocity >= 0 ? 1 : 0;
|
||||||
this.attacking = true;
|
this.parent.velocity.y = -800;
|
||||||
break;
|
break;
|
||||||
case this.attacked:
|
case this.attacked:
|
||||||
this.parent.isAttaking = false;
|
this.parent.isAttaking = false;
|
||||||
|
|
|
@ -22,6 +22,7 @@ import BattleManager from "../GameSystems/BattleManager";
|
||||||
import EnemyAI from "../AI/EnemyAI";
|
import EnemyAI from "../AI/EnemyAI";
|
||||||
import SnakeAI from "../AI/SnakeAI";
|
import SnakeAI from "../AI/SnakeAI";
|
||||||
import SlimeAI from "../AI/SlimeAI";
|
import SlimeAI from "../AI/SlimeAI";
|
||||||
|
import TigerAI from "../AI/TigerAI";
|
||||||
import BattlerAI from "../AI/BattlerAI";
|
import BattlerAI from "../AI/BattlerAI";
|
||||||
import InventoryManager from "../GameSystems/InventoryManager";
|
import InventoryManager from "../GameSystems/InventoryManager";
|
||||||
import Item from "../GameSystems/items/Item";
|
import Item from "../GameSystems/items/Item";
|
||||||
|
@ -865,10 +866,13 @@ export default class GameLevel extends Scene {
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
case "Tiger": //Tiger can be miniboss for now?
|
case "Tiger": //Tiger can be miniboss for now?
|
||||||
this.addEnemy("Tiger", enemy.position.scale(32), EnemyAI, {
|
this.addEnemy("Tiger", enemy.position.scale(32), TigerAI, {
|
||||||
player: this.player,
|
player: this.player,
|
||||||
health: 200,
|
health: 200,
|
||||||
tilemap: "Main",
|
tilemap: "Main",
|
||||||
|
scale: 1.5,
|
||||||
|
size: new Vec2(30,18),
|
||||||
|
offset : new Vec2(0, 27),
|
||||||
exp: 100,
|
exp: 100,
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -20,6 +20,7 @@ export default class Porcelain extends GameLevel {
|
||||||
this.map = this.rmg.getMap();
|
this.map = this.rmg.getMap();
|
||||||
console.log(this.map);
|
console.log(this.map);
|
||||||
this.load.tilemapFromObject("map", this.map);
|
this.load.tilemapFromObject("map", this.map);
|
||||||
|
this.load.spritesheet("Tiger","shattered_sword_assets/spritesheets/Tiger.json");
|
||||||
|
|
||||||
// //load enemies
|
// //load enemies
|
||||||
// this.load.spritesheet("Snake","shattered_sword_assets/spritesheets/Snake.json");
|
// this.load.spritesheet("Snake","shattered_sword_assets/spritesheets/Snake.json");
|
||||||
|
|
|
@ -14,7 +14,6 @@ export default class Tutorial extends GameLevel {
|
||||||
|
|
||||||
//load enemies
|
//load enemies
|
||||||
this.load.spritesheet("Snake","shattered_sword_assets/spritesheets/Snake.json");
|
this.load.spritesheet("Snake","shattered_sword_assets/spritesheets/Snake.json");
|
||||||
this.load.spritesheet("Tiger","shattered_sword_assets/spritesheets/Tiger.json");
|
|
||||||
|
|
||||||
//can load enemy sprite here
|
//can load enemy sprite here
|
||||||
//sprites obtained from cse380 sprite wesbite
|
//sprites obtained from cse380 sprite wesbite
|
||||||
|
|
Loading…
Reference in New Issue
Block a user