summaryrefslogtreecommitdiff
path: root/engine/systems/Render.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/Render.ts
parentb67ffb57c1bf6e9628339a3f43c71ccebdb46136 (diff)
downloadjumpstorm-c6e9baa0009f7cce0f6ff156a3957ef04a8cb684.tar.gz
jumpstorm-c6e9baa0009f7cce0f6ff156a3957ef04a8cb684.zip
the great engine refactor
Diffstat (limited to 'engine/systems/Render.ts')
-rw-r--r--engine/systems/Render.ts57
1 files changed, 26 insertions, 31 deletions
diff --git a/engine/systems/Render.ts b/engine/systems/Render.ts
index b5479e1..9bb4091 100644
--- a/engine/systems/Render.ts
+++ b/engine/systems/Render.ts
@@ -1,8 +1,6 @@
import { System, SystemNames } from ".";
import { BoundingBox, ComponentNames, Sprite } from "../components";
-import type { Entity } from "../entities";
import { Game } from "../Game";
-import type { DrawArgs } from "../interfaces";
import { clamp } from "../utils";
export class Render extends System {
@@ -16,39 +14,36 @@ export class Render extends System {
public update(dt: number, game: Game) {
this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
- game.componentEntities.get(ComponentNames.Sprite)?.forEach((entityId) => {
- const entity = game.entities.get(entityId);
+ game.forEachEntityWithComponent(ComponentNames.Sprite, (entity) => {
const sprite = entity.getComponent<Sprite>(ComponentNames.Sprite);
sprite.update(dt);
- let drawArgs: DrawArgs;
- if (entity.hasComponent(ComponentNames.BoundingBox)) {
- const boundingBox = entity.getComponent<BoundingBox>(
- ComponentNames.BoundingBox
- );
-
- // don't render if we're outside the screen
- if (
- clamp(
- boundingBox.center.y,
- -boundingBox.dimension.height / 2,
- this.ctx.canvas.height + boundingBox.dimension.height / 2
- ) != boundingBox.center.y ||
- clamp(
- boundingBox.center.x,
- -boundingBox.dimension.width / 2,
- this.ctx.canvas.width + boundingBox.dimension.width / 2
- ) != boundingBox.center.x
- ) {
- return;
- }
-
- drawArgs = {
- center: boundingBox.center,
- dimension: boundingBox.dimension,
- rotation: boundingBox.rotation,
- };
+ const boundingBox = entity.getComponent<BoundingBox>(
+ ComponentNames.BoundingBox,
+ );
+
+ // don't render if we're outside the screen
+ if (
+ clamp(
+ boundingBox.center.y,
+ -boundingBox.dimension.height / 2,
+ this.ctx.canvas.height + boundingBox.dimension.height / 2,
+ ) != boundingBox.center.y ||
+ clamp(
+ boundingBox.center.x,
+ -boundingBox.dimension.width / 2,
+ this.ctx.canvas.width + boundingBox.dimension.width / 2,
+ ) != boundingBox.center.x
+ ) {
+ return;
}
+
+ const drawArgs = {
+ center: boundingBox.center,
+ dimension: boundingBox.dimension,
+ rotation: boundingBox.rotation,
+ };
+
sprite.draw(this.ctx, drawArgs);
});
}