jumpstorm/server/src/server.ts

38 lines
958 B
TypeScript
Raw Normal View History

2023-07-21 01:22:26 -04:00
import { Game } from "../../engine/Game";
import { Floor, Player } from "../../engine/entities";
2023-08-12 15:49:16 -04:00
import { WallBounds, Physics, Collision } from "../../engine/systems";
2023-07-21 01:22:26 -04:00
import { Miscellaneous } from "../../engine/config";
const TICK_RATE = 60 / 1000;
const game = new Game();
2023-08-12 15:49:16 -04:00
[
new Physics(),
new Collision({ width: Miscellaneous.WIDTH, height: Miscellaneous.HEIGHT }),
new WallBounds(Miscellaneous.WIDTH),
].forEach((system) => game.addSystem(system));
2023-07-21 01:22:26 -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,
fetch(req, server) {
server.upgrade(req, {
data: {},
});
},
websocket: {
// handler called when a message is received
async message(ws, message) {
console.log(`Received ${message}`);
},
},
});
console.log(`Listening on localhost:${server.port}`);