2020-02-16 05:01:30 +00:00
|
|
|
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";
|
2020-02-16 00:52:00 +00:00
|
|
|
import {} from "../Ecs/Lockstep";
|
2020-02-16 05:01:30 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|