From 9aa76b79634e7be2af2afdf93f8b860dc78b87e1 Mon Sep 17 00:00:00 2001 From: Renge Date: Sat, 30 Apr 2022 19:09:39 -0400 Subject: [PATCH] feat: tiger AI --- .../jsons/porcelain_template.json | 6 ++++++ src/shattered_sword/AI/EnemyStates/Attack.ts | 5 ----- src/shattered_sword/AI/EnemyStates/EnemyState.ts | 10 +++++++++- src/shattered_sword/AI/EnemyStates/TigerAttack.ts | 7 +++---- src/shattered_sword/Scenes/GameLevel.ts | 6 +++++- src/shattered_sword/Scenes/Porcelain.ts | 1 + src/shattered_sword/Scenes/Tutorial.ts | 1 - 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/dist/shattered_sword_assets/jsons/porcelain_template.json b/dist/shattered_sword_assets/jsons/porcelain_template.json index 00252e3..e50b670 100644 --- a/dist/shattered_sword_assets/jsons/porcelain_template.json +++ b/dist/shattered_sword_assets/jsons/porcelain_template.json @@ -40,6 +40,12 @@ "type": "player", "x": 5, "y": 10 + }, + { + "type": "Tiger", + "x": 3, + "y": 7, + "possibility": 1 } ] diff --git a/src/shattered_sword/AI/EnemyStates/Attack.ts b/src/shattered_sword/AI/EnemyStates/Attack.ts index a9d22f2..6dbeb9f 100644 --- a/src/shattered_sword/AI/EnemyStates/Attack.ts +++ b/src/shattered_sword/AI/EnemyStates/Attack.ts @@ -19,11 +19,6 @@ export default class Attack extends EnemyState { this.receiver.subscribe(this.attacked); } - update(deltaT: number): void { - this.finished(EnemyStates.ALERT); - super.update(deltaT); - } - onExit(): Record { this.parent.isCharging = false; (this.owner).animation.stop(); diff --git a/src/shattered_sword/AI/EnemyStates/EnemyState.ts b/src/shattered_sword/AI/EnemyStates/EnemyState.ts index 5c77dcb..b784489 100644 --- a/src/shattered_sword/AI/EnemyStates/EnemyState.ts +++ b/src/shattered_sword/AI/EnemyStates/EnemyState.ts @@ -31,7 +31,15 @@ export default abstract class EnemyState extends State { this.parent.velocity.x = 0; } // Do gravity - this.parent.velocity.y += this.gravity * deltaT; + 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.owner.move(this.parent.velocity.scaled(deltaT)); } } diff --git a/src/shattered_sword/AI/EnemyStates/TigerAttack.ts b/src/shattered_sword/AI/EnemyStates/TigerAttack.ts index e580307..f30a63d 100644 --- a/src/shattered_sword/AI/EnemyStates/TigerAttack.ts +++ b/src/shattered_sword/AI/EnemyStates/TigerAttack.ts @@ -7,7 +7,6 @@ import Attack from "./Attack"; export default class TigerAttack extends Attack { protected velocity: number; protected distance: number; - protected attacking: boolean = false; onEnter(options: Record): void { super.onEnter(options); @@ -15,7 +14,7 @@ export default class TigerAttack extends Attack { } update(deltaT: number): void { - if (this.attacking && this.owner.onGround) { + if (this.parent.isAttaking && this.owner.onGround) { this.emitter.fireEvent(this.attacked); } while (this.receiver.hasNextEvent()) { @@ -25,9 +24,9 @@ export default class TigerAttack extends Attack { this.parent.isCharging = false; this.parent.isAttaking = true; (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.attacking = true; + this.parent.velocity.y = -800; break; case this.attacked: this.parent.isAttaking = false; diff --git a/src/shattered_sword/Scenes/GameLevel.ts b/src/shattered_sword/Scenes/GameLevel.ts index 6f30dba..c24af9b 100644 --- a/src/shattered_sword/Scenes/GameLevel.ts +++ b/src/shattered_sword/Scenes/GameLevel.ts @@ -22,6 +22,7 @@ import BattleManager from "../GameSystems/BattleManager"; import EnemyAI from "../AI/EnemyAI"; import SnakeAI from "../AI/SnakeAI"; import SlimeAI from "../AI/SlimeAI"; +import TigerAI from "../AI/TigerAI"; import BattlerAI from "../AI/BattlerAI"; import InventoryManager from "../GameSystems/InventoryManager"; import Item from "../GameSystems/items/Item"; @@ -865,10 +866,13 @@ export default class GameLevel extends Scene { }) break; 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, health: 200, tilemap: "Main", + scale: 1.5, + size: new Vec2(30,18), + offset : new Vec2(0, 27), exp: 100, }) break; diff --git a/src/shattered_sword/Scenes/Porcelain.ts b/src/shattered_sword/Scenes/Porcelain.ts index 022a129..11d3945 100644 --- a/src/shattered_sword/Scenes/Porcelain.ts +++ b/src/shattered_sword/Scenes/Porcelain.ts @@ -20,6 +20,7 @@ export default class Porcelain extends GameLevel { this.map = this.rmg.getMap(); console.log(this.map); this.load.tilemapFromObject("map", this.map); + this.load.spritesheet("Tiger","shattered_sword_assets/spritesheets/Tiger.json"); // //load enemies // this.load.spritesheet("Snake","shattered_sword_assets/spritesheets/Snake.json"); diff --git a/src/shattered_sword/Scenes/Tutorial.ts b/src/shattered_sword/Scenes/Tutorial.ts index 12b6479..99e9a83 100644 --- a/src/shattered_sword/Scenes/Tutorial.ts +++ b/src/shattered_sword/Scenes/Tutorial.ts @@ -14,7 +14,6 @@ export default class Tutorial extends GameLevel { //load enemies 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 //sprites obtained from cse380 sprite wesbite