fix: pause timer when not in gaming state

This commit is contained in:
Renge 2022-04-24 21:12:15 -04:00
parent 58ef5cb59f
commit 42b58824cc
3 changed files with 17 additions and 3 deletions

View File

@ -1,3 +1,5 @@
import { GameState } from "../../shattered_sword/sword_enums";
import InputWrapper from "../../shattered_sword/Tools/InputWrapper";
import Updateable from "../DataTypes/Interfaces/Updateable"; import Updateable from "../DataTypes/Interfaces/Updateable";
import MathUtils from "../Utils/MathUtils"; import MathUtils from "../Utils/MathUtils";
import TimerManager from "./TimerManager"; import TimerManager from "./TimerManager";
@ -70,7 +72,7 @@ export default class Timer implements Updateable {
} }
update(deltaT: number){ update(deltaT: number){
if(this.state === TimerState.ACTIVE){ if(this.state === TimerState.ACTIVE && InputWrapper.getState() === GameState.GAMING){
this.timeLeft -= deltaT*1000; this.timeLeft -= deltaT*1000;
if(this.timeLeft <= 0){ if(this.timeLeft <= 0){

View File

@ -3,12 +3,21 @@ import EnemyState from "./EnemyState";
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite"; import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite"; import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
export default class Alert extends EnemyState { export default class Attack extends EnemyState {
protected charged: string;
protected attacked: string;
onEnter(options: Record<string, any>): void { onEnter(options: Record<string, any>): void {
(<AnimatedSprite>this.owner).animation.playIfNotAlready("WALK", true); let event = this.owner.id+"charged";
(<AnimatedSprite>this.owner).animation.play("DYING", false, event);
this.receiver.subscribe(event);
} }
update(deltaT: number): void { update(deltaT: number): void {
while (this.receiver.hasNextEvent()) {
this.receiver.getNextEvent();
}
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);

View File

@ -4,15 +4,18 @@ import Vec2 from "../../../Wolfie2D/DataTypes/Vec2";
import GameEvent from "../../../Wolfie2D/Events/GameEvent"; import GameEvent from "../../../Wolfie2D/Events/GameEvent";
import GameNode from "../../../Wolfie2D/Nodes/GameNode"; import GameNode from "../../../Wolfie2D/Nodes/GameNode";
import EnemyAI from "../EnemyAI"; import EnemyAI from "../EnemyAI";
import Receiver from "../../../Wolfie2D/Events/Receiver";
export default abstract class EnemyState extends State { export default abstract class EnemyState extends State {
protected parent: EnemyAI; protected parent: EnemyAI;
protected owner: GameNode; protected owner: GameNode;
protected receiver: Receiver;
gravity: number = 1500; //TODO - can change later gravity: number = 1500; //TODO - can change later
constructor(parent: EnemyAI, owner: GameNode) { constructor(parent: EnemyAI, owner: GameNode) {
super(parent); super(parent);
this.owner = owner; this.owner = owner;
this.receiver = new Receiver();
} }
handleInput(event: GameEvent): void { } handleInput(event: GameEvent): void { }