diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-07-20 22:22:26 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-07-20 22:22:26 -0700 |
commit | 619a039942c3c02552f72275634a9f6c0788c570 (patch) | |
tree | 43151191c920d0d705db71306f58409e97b60d03 /server/src/server.ts | |
parent | 72c6c7de12e9833f52bf2d0718d70f044f8ab57e (diff) | |
download | jumpstorm-619a039942c3c02552f72275634a9f6c0788c570.tar.gz jumpstorm-619a039942c3c02552f72275634a9f6c0788c570.zip |
very basic websocket setup
Diffstat (limited to 'server/src/server.ts')
-rw-r--r-- | server/src/server.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/server/src/server.ts b/server/src/server.ts new file mode 100644 index 0000000..f699ea9 --- /dev/null +++ b/server/src/server.ts @@ -0,0 +1,41 @@ +import { Game } from "../../engine/Game"; +import { Floor, Player } from "../../engine/entities"; +import { + WallBounds, + FacingDirection, + Physics, + Input, + Collision, +} from "../../engine/systems"; +import { Miscellaneous } from "../../engine/config"; + +const TICK_RATE = 60 / 1000; + +const game = new Game(); + +[new Physics(), new Collision(), new WallBounds(Miscellaneous.WIDTH)].forEach( + (system) => game.addSystem(system) +); + +[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}`); |