2023-08-21 16:50:09 -04:00
|
|
|
import { Game } from "@engine/Game";
|
|
|
|
import { Floor, Player } from "@engine/entities";
|
2023-08-15 20:30:19 -04:00
|
|
|
import {
|
|
|
|
WallBounds,
|
|
|
|
Physics,
|
|
|
|
Collision,
|
|
|
|
MessageQueueProvider,
|
|
|
|
MessagePublisher,
|
2023-08-21 16:50:09 -04:00
|
|
|
} from "@engine/systems";
|
|
|
|
import { Grid } from "@engine/structures";
|
|
|
|
import { Miscellaneous } from "@engine/config";
|
2023-07-21 01:22:26 -04:00
|
|
|
|
|
|
|
const TICK_RATE = 60 / 1000;
|
|
|
|
|
2023-08-16 17:41:35 -04:00
|
|
|
const game = new Game();
|
|
|
|
|
2023-08-21 16:50:09 -04:00
|
|
|
[
|
|
|
|
new Physics(),
|
|
|
|
new Collision(new Grid()),
|
|
|
|
new WallBounds(Miscellaneous.WIDTH),
|
|
|
|
].forEach((system) => game.addSystem(system));
|
2023-08-16 17:41:35 -04:00
|
|
|
|
|
|
|
[new Floor(160), new Player()].forEach((entity) => game.addEntity(entity));
|
|
|
|
|
|
|
|
game.start();
|
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
game.doGameLoop(performance.now());
|
|
|
|
}, TICK_RATE);
|
|
|
|
|
|
|
|
const server = Bun.serve({
|
|
|
|
port: 8080,
|
2023-08-21 16:50:09 -04:00
|
|
|
fetch: async (req, server): Promise<string> => {
|
2023-08-16 17:41:35 -04:00
|
|
|
const sessionId = Math.floor(Math.random() * 1e10).toString();
|
|
|
|
|
|
|
|
server.upgrade(req, {
|
|
|
|
headers: {
|
|
|
|
"Set-Cookie": `SessionId=${sessionId}`,
|
2023-08-15 20:30:19 -04:00
|
|
|
},
|
2023-07-21 01:22:26 -04:00
|
|
|
});
|
2023-08-21 16:50:09 -04:00
|
|
|
|
|
|
|
return "200 OK";
|
2023-08-16 17:41:35 -04:00
|
|
|
},
|
|
|
|
websocket: {
|
|
|
|
open(ws) {},
|
|
|
|
message(ws, message) {
|
|
|
|
console.log(message);
|
|
|
|
},
|
|
|
|
close(ws) {},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(`Listening on ${server.hostname}:${server.port}`);
|