diff options
| author | Elizabeth Hunt <elizabeth@simponic.xyz> | 2024-09-07 20:20:07 -0700 |
|---|---|---|
| committer | Elizabeth Hunt <elizabeth@simponic.xyz> | 2024-09-12 17:23:30 -0700 |
| commit | 8ec7f5368232d59f344e1067e1bad5e48dbcb7ae (patch) | |
| tree | 1ad2df4dc00773f2307d1525cc80ac7410ea8fba /static/src/engine/render.ts | |
| parent | e4e31978bae7e45be57b376415a4b925ac8cbc03 (diff) | |
| download | kennel.hatecomputers.club-8ec7f5368232d59f344e1067e1bad5e48dbcb7ae.tar.gz kennel.hatecomputers.club-8ec7f5368232d59f344e1067e1bad5e48dbcb7ae.zip | |
get "cats" up there
Diffstat (limited to 'static/src/engine/render.ts')
| -rw-r--r-- | static/src/engine/render.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/static/src/engine/render.ts b/static/src/engine/render.ts new file mode 100644 index 0000000..8f0343a --- /dev/null +++ b/static/src/engine/render.ts @@ -0,0 +1,46 @@ +import { + ComponentType, + PositionComponent, + TrailingPositionComponent, +} from "./component"; +import { Game } from "./game"; +import { System, SystemType } from "./system"; +import { drawLaserPen } from "laser-pen"; + +export class RenderSystem extends System { + constructor(private readonly canvas: HTMLCanvasElement) { + super(SystemType.RENDER); + } + + public set_world_dimensions(width: number, height: number) { + this.canvas.width = width; + this.canvas.height = height; + } + + public update(_dt: number, game: Game) { + const ctx = this.canvas.getContext("2d"); + if (ctx === null) return; + ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); + + game.for_each_entity_with_component(ComponentType.RENDERABLE, (entity) => { + if (ComponentType.TRAILING_POSITION in entity.components) { + const trailing_position = entity.components[ + ComponentType.TRAILING_POSITION + ] as TrailingPositionComponent; + if (trailing_position.trails.length < 3) return; + drawLaserPen(ctx, trailing_position.trails); + return; + } + + if (ComponentType.POSITION in entity.components) { + const position = entity.components[ + ComponentType.POSITION + ] as PositionComponent; + ctx.beginPath(); + ctx.arc(position.x, position.y, 50, 0, 2 * Math.PI); + ctx.stroke(); + return; + } + }); + } +} |
