add default arguments to grid; add grid to server gl
This commit is contained in:
parent
8fce5a5f25
commit
b786fe1e72
@ -64,12 +64,12 @@ export class JumpStorm {
|
|||||||
const clientSocketMessageQueueProvider =
|
const clientSocketMessageQueueProvider =
|
||||||
new ClientSocketMessageQueueProvider(socket);
|
new ClientSocketMessageQueueProvider(socket);
|
||||||
const clientSocketMessagePublisher = new ClientSocketMessagePublisher(
|
const clientSocketMessagePublisher = new ClientSocketMessagePublisher(
|
||||||
socket,
|
socket
|
||||||
);
|
);
|
||||||
|
|
||||||
const grid = new Grid(
|
const grid = new Grid(
|
||||||
{ width: Miscellaneous.WIDTH, height: Miscellaneous.HEIGHT },
|
{ width: Miscellaneous.WIDTH, height: Miscellaneous.HEIGHT },
|
||||||
{ width: 30, height: 30 },
|
{ width: 30, height: 30 }
|
||||||
);
|
);
|
||||||
|
|
||||||
[
|
[
|
||||||
@ -80,13 +80,13 @@ export class JumpStorm {
|
|||||||
new WallBounds(ctx.canvas.width),
|
new WallBounds(ctx.canvas.width),
|
||||||
new NetworkUpdate(
|
new NetworkUpdate(
|
||||||
clientSocketMessageQueueProvider,
|
clientSocketMessageQueueProvider,
|
||||||
clientSocketMessagePublisher,
|
clientSocketMessagePublisher
|
||||||
),
|
),
|
||||||
new Render(ctx),
|
new Render(ctx),
|
||||||
].forEach((system) => this.game.addSystem(system));
|
].forEach((system) => this.game.addSystem(system));
|
||||||
|
|
||||||
[new Floor(160), new Player()].forEach((entity) =>
|
[new Floor(160), new Player()].forEach((entity) =>
|
||||||
this.game.addEntity(entity),
|
this.game.addEntity(entity)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ export namespace KeyConstants {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const ActionKeys: Map<Action, string[]> = Object.keys(
|
export const ActionKeys: Map<Action, string[]> = Object.keys(
|
||||||
KeyActions,
|
KeyActions
|
||||||
).reduce((acc: Map<Action, string[]>, key) => {
|
).reduce((acc: Map<Action, string[]>, key) => {
|
||||||
const action = KeyActions[key];
|
const action = KeyActions[key];
|
||||||
|
|
||||||
@ -36,4 +36,7 @@ export namespace PhysicsConstants {
|
|||||||
export namespace Miscellaneous {
|
export namespace Miscellaneous {
|
||||||
export const WIDTH = 600;
|
export const WIDTH = 600;
|
||||||
export const HEIGHT = 800;
|
export const HEIGHT = 800;
|
||||||
|
|
||||||
|
export const DEFAULT_GRID_WIDTH = 40;
|
||||||
|
export const DEFAULT_GRID_HEIGHT = 40;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import type { Coord2D, Dimension2D } from "../interfaces";
|
import type { Coord2D, Dimension2D } from "../interfaces";
|
||||||
import type { BoxedEntry, RefreshingCollisionFinderBehavior } from ".";
|
import type { BoxedEntry, RefreshingCollisionFinderBehavior } from ".";
|
||||||
|
import { Miscellaneous } from "../config/constants";
|
||||||
|
|
||||||
export class Grid implements RefreshingCollisionFinderBehavior {
|
export class Grid implements RefreshingCollisionFinderBehavior {
|
||||||
private cellEntities: Map<number, string[]>;
|
private cellEntities: Map<number, string[]>;
|
||||||
@ -9,8 +10,14 @@ export class Grid implements RefreshingCollisionFinderBehavior {
|
|||||||
private topLeft: Coord2D;
|
private topLeft: Coord2D;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
gridDimension: Dimension2D,
|
gridDimension: Dimension2D = {
|
||||||
cellDimension: Dimension2D,
|
width: Miscellaneous.WIDTH,
|
||||||
|
height: Miscellaneous.HEIGHT,
|
||||||
|
},
|
||||||
|
cellDimension: Dimension2D = {
|
||||||
|
width: Miscellaneous.DEFAULT_GRID_WIDTH,
|
||||||
|
height: Miscellaneous.DEFAULT_GRID_HEIGHT,
|
||||||
|
},
|
||||||
topLeft = { x: 0, y: 0 }
|
topLeft = { x: 0, y: 0 }
|
||||||
) {
|
) {
|
||||||
this.gridDimension = gridDimension;
|
this.gridDimension = gridDimension;
|
||||||
|
BIN
server/bun.lockb
BIN
server/bun.lockb
Binary file not shown.
@ -1,21 +1,24 @@
|
|||||||
import { Game } from "../../engine/Game";
|
import { Game } from "@engine/Game";
|
||||||
import { Floor, Player } from "../../engine/entities";
|
import { Floor, Player } from "@engine/entities";
|
||||||
import {
|
import {
|
||||||
WallBounds,
|
WallBounds,
|
||||||
Physics,
|
Physics,
|
||||||
Collision,
|
Collision,
|
||||||
MessageQueueProvider,
|
MessageQueueProvider,
|
||||||
MessagePublisher,
|
MessagePublisher,
|
||||||
} from "../../engine/systems";
|
} from "@engine/systems";
|
||||||
import { Miscellaneous } from "../../engine/config";
|
import { Grid } from "@engine/structures";
|
||||||
|
import { Miscellaneous } from "@engine/config";
|
||||||
|
|
||||||
const TICK_RATE = 60 / 1000;
|
const TICK_RATE = 60 / 1000;
|
||||||
|
|
||||||
const game = new Game();
|
const game = new Game();
|
||||||
|
|
||||||
[new Physics(), new Collision(), new WallBounds(Miscellaneous.WIDTH)].forEach(
|
[
|
||||||
(system) => game.addSystem(system),
|
new Physics(),
|
||||||
);
|
new Collision(new Grid()),
|
||||||
|
new WallBounds(Miscellaneous.WIDTH),
|
||||||
|
].forEach((system) => game.addSystem(system));
|
||||||
|
|
||||||
[new Floor(160), new Player()].forEach((entity) => game.addEntity(entity));
|
[new Floor(160), new Player()].forEach((entity) => game.addEntity(entity));
|
||||||
|
|
||||||
@ -27,7 +30,7 @@ setInterval(() => {
|
|||||||
|
|
||||||
const server = Bun.serve({
|
const server = Bun.serve({
|
||||||
port: 8080,
|
port: 8080,
|
||||||
fetch(req, server) {
|
fetch: async (req, server): Promise<string> => {
|
||||||
const sessionId = Math.floor(Math.random() * 1e10).toString();
|
const sessionId = Math.floor(Math.random() * 1e10).toString();
|
||||||
|
|
||||||
server.upgrade(req, {
|
server.upgrade(req, {
|
||||||
@ -35,6 +38,8 @@ const server = Bun.serve({
|
|||||||
"Set-Cookie": `SessionId=${sessionId}`,
|
"Set-Cookie": `SessionId=${sessionId}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return "200 OK";
|
||||||
},
|
},
|
||||||
websocket: {
|
websocket: {
|
||||||
open(ws) {},
|
open(ws) {},
|
||||||
|
@ -21,6 +21,18 @@
|
|||||||
// best practices
|
// best practices
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"skipLibCheck": true
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
// engine path
|
||||||
|
"paths": {
|
||||||
|
"@engine/*": ["../engine/*"],
|
||||||
|
"@engine/components": ["../engine/components"],
|
||||||
|
"@engine/config": ["../engine/config"],
|
||||||
|
"@engine/entities": ["../engine/entities"],
|
||||||
|
"@engine/interfaces": ["../engine/interfaces"],
|
||||||
|
"@engine/structures": ["../engine/structures"],
|
||||||
|
"@engine/systems": ["../engine/systems"],
|
||||||
|
"@engine/utils": ["../engine/utils"],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user