Render stub static scene

This commit is contained in:
Tangent 2020-02-16 00:01:30 -05:00
parent d321098555
commit bf26e85b49
4 changed files with 62 additions and 3 deletions

View file

@ -1,2 +1,52 @@
import subscribe from "callbag-subscribe";
import { Game } from "../Applet/Init";
import { KeyControl, KeyName } from "../Applet/Keyboard";
import { DrawSet } from "../Applet/Render";
import { Location, Polygon, RenderBounds } from "../Ecs/Components";
import { Create } from "../Ecs/Data";
import {} from "../Ecs/Lockstep";
import {} from "./GameComponents";
import { RunRenderBounds } from "../Ecs/Renderers";
import { LockstepClient } from "../Net/LockstepClient";
import { Data, Engine } from "./GameComponents";
import { Buttons } from "./Input";
@Game("#GameCanvas")
export class Main extends LockstepClient<KeyName[], Data> {
buttons = new Buttons();
constructor(canvas: HTMLCanvasElement, cx: CanvasRenderingContext2D, keys: KeyControl) {
super(new Engine());
keys.setHandler(this.buttons);
subscribe((frame: Data) => {
const drawSet = new DrawSet();
RunRenderBounds(frame, drawSet);
drawSet.draw(cx, 0);
})(this.renderFrames);
}
gatherInput() {
return this.buttons.getPressed();
}
initState(patch: Partial<Data>) {
const newState = new Data();
Create(newState, {
location: new Location({
X: 200,
Y: 200,
VAngle: 0.02,
}),
bounds: new Polygon([-30, 0, 30, 0, 0, 40]),
renderBounds: new RenderBounds("#a0f", 0),
});
return newState;
}
}

View file

@ -4,7 +4,7 @@
<title></title>
<link rel="stylesheet" href="./index.scss" />
</head><body>
<canvas id="RenderTest" width="500" height="400"></canvas>
<canvas id="GameCanvas" width="500" height="400"></canvas>
<canvas id="RenderTest" width="500" height="400"></canvas>
<script src="./index.ts"></script>
</body></html>