Skip to content

Commit

Permalink
refactor other scenarios for worm state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Dec 28, 2024
1 parent 89a8fa4 commit fe2852d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
11 changes: 6 additions & 5 deletions src/entities/playable/remoteWorm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { WormInstance } from "../../logic/teams";
import { Toaster } from "../../overlays/toaster";
import { Coordinate } from "../../utils";
import { GameWorld } from "../../world";
import { FireFn, Worm, WormState } from "./worm";
import { FireFn, Worm } from "./worm";
import { StateWormAction } from "../../state/model";
import { InputKind } from "../../input";
import Logger from "../../log";
import { InnerWormState } from "./wormState";

const logger = new Logger("RemoteWorm");

Expand Down Expand Up @@ -78,7 +79,7 @@ export class RemoteWorm extends Worm {
}

update(dt: number): void {
if (this.state === WormState.Firing) {
if (this.state.isFiring) {
if (
this.remoteWeaponFiringDuration === undefined ||
this.fireWeaponDuration > this.remoteWeaponFiringDuration
Expand All @@ -90,12 +91,12 @@ export class RemoteWorm extends Worm {
}
super.update(dt);
if (
this.state === WormState.MovingLeft ||
this.state === WormState.MovingRight
this.state.state === InnerWormState.MovingLeft ||
this.state.state === InnerWormState.MovingRight
) {
this.movementCyclesLeft -= 1;
if (this.movementCyclesLeft === 0) {
this.state = WormState.Idle;
this.state.transition(InnerWormState.Idle);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/scenarios/netGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Background } from "../entities/background";
import { BitmapTerrain } from "../entities/bitmapTerrain";
import type { Game } from "../game";
import { Water } from "../entities/water";
import { Worm, WormState } from "../entities/playable/worm";
import { Worm } from "../entities/playable/worm";
import { Coordinate, MetersValue } from "../utils/coodinate";
import { GameState } from "../logic/gamestate";
import { TeamGroup } from "../logic/teams";
Expand Down Expand Up @@ -172,7 +172,7 @@ export default async function runScenario(game: Game) {
}
return;
}
if (currentWorm && currentWorm.currentState !== WormState.Inactive) {
if (currentWorm && currentWorm.currentState.active) {
return;
}
if (endOfRoundWaitDuration === null) {
Expand Down
4 changes: 2 additions & 2 deletions src/scenarios/replayTesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Background } from "../entities/background";
import { BitmapTerrain } from "../entities/bitmapTerrain";
import type { Game } from "../game";
import { Water } from "../entities/water";
import { Worm, WormState } from "../entities/playable/worm";
import { Worm } from "../entities/playable/worm";
import { Coordinate, MetersValue } from "../utils/coodinate";
import { GameState } from "../logic/gamestate";
import { GameStateOverlay } from "../overlays/gameStateOverlay";
Expand Down Expand Up @@ -209,7 +209,7 @@ export default async function runScenario(game: Game) {
}
return;
}
if (currentWorm && currentWorm.currentState !== WormState.Inactive) {
if (currentWorm && currentWorm.currentState.active) {
return;
}
if (endOfRoundWaitDuration === null) {
Expand Down
6 changes: 3 additions & 3 deletions src/scenarios/testingGround.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Background } from "../entities/background";
import { BitmapTerrain } from "../entities/bitmapTerrain";
import type { Game } from "../game";
import { Water } from "../entities/water";
import { Worm, WormState } from "../entities/playable/worm";
import { Worm } from "../entities/playable/worm";
import { Coordinate, MetersValue } from "../utils/coodinate";
import { GameState } from "../logic/gamestate";
import { TeamGroup } from "../logic/teams";
Expand Down Expand Up @@ -159,7 +159,7 @@ export default async function runScenario(game: Game) {
});
weaponText.position.set(20, 50);
staticController.on("inputEnd", (kind: InputKind) => {
if (currentWorm?.currentState !== WormState.Idle) {
if (currentWorm?.currentState.showWeapon) {
return;
}
if (kind === InputKind.WeaponMenu) {
Expand Down Expand Up @@ -188,7 +188,7 @@ export default async function runScenario(game: Game) {
}
return;
}
if (currentWorm && currentWorm.currentState !== WormState.Inactive) {
if (currentWorm && currentWorm.currentState.active) {
return;
}
if (endOfRoundWaitDuration === null) {
Expand Down

0 comments on commit fe2852d

Please sign in to comment.