summaryrefslogtreecommitdiff
path: root/engine/systems/FacingDirection.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-08-12 13:49:16 -0600
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-08-12 13:49:16 -0600
commitc6e9baa0009f7cce0f6ff156a3957ef04a8cb684 (patch)
tree9766a4a33ad1c86aa71a5f92daf8917f3e5f5eed /engine/systems/FacingDirection.ts
parentb67ffb57c1bf6e9628339a3f43c71ccebdb46136 (diff)
downloadjumpstorm-c6e9baa0009f7cce0f6ff156a3957ef04a8cb684.tar.gz
jumpstorm-c6e9baa0009f7cce0f6ff156a3957ef04a8cb684.zip
the great engine refactor
Diffstat (limited to 'engine/systems/FacingDirection.ts')
-rw-r--r--engine/systems/FacingDirection.ts25
1 files changed, 16 insertions, 9 deletions
diff --git a/engine/systems/FacingDirection.ts b/engine/systems/FacingDirection.ts
index c6513ac..4426ab6 100644
--- a/engine/systems/FacingDirection.ts
+++ b/engine/systems/FacingDirection.ts
@@ -2,9 +2,9 @@ import {
ComponentNames,
Velocity,
FacingDirection as FacingDirectionComponent,
+ Control,
} from "../components";
import { Game } from "../Game";
-import type { Entity } from "../entities";
import { System, SystemNames } from "./";
export class FacingDirection extends System {
@@ -13,24 +13,31 @@ export class FacingDirection extends System {
}
public update(_dt: number, game: Game) {
- game.componentEntities
- .get(ComponentNames.FacingDirection)
- ?.forEach((entityId) => {
- const entity = game.entities.get(entityId);
+ game.forEachEntityWithComponent(
+ ComponentNames.FacingDirection,
+ (entity) => {
if (!entity.hasComponent(ComponentNames.Velocity)) {
return;
}
+ const totalVelocity: Velocity = new Velocity();
+ const control = entity.getComponent<Control>(ComponentNames.Control);
const velocity = entity.getComponent<Velocity>(ComponentNames.Velocity);
+ totalVelocity.add(velocity);
+ if (control) {
+ totalVelocity.add(control.controlVelocity);
+ }
+
const facingDirection = entity.getComponent<FacingDirectionComponent>(
- ComponentNames.FacingDirection
+ ComponentNames.FacingDirection,
);
- if (velocity.dCartesian.dx > 0) {
+ if (totalVelocity.dCartesian.dx > 0) {
entity.addComponent(facingDirection.facingRightSprite);
- } else if (velocity.dCartesian.dx < 0) {
+ } else if (totalVelocity.dCartesian.dx < 0) {
entity.addComponent(facingDirection.facingLeftSprite);
}
- });
+ },
+ );
}
}