diff options
Diffstat (limited to 'engine')
-rw-r--r-- | engine/components/Control.ts | 5 | ||||
-rw-r--r-- | engine/config/constants.ts | 13 | ||||
-rw-r--r-- | engine/entities/Entity.ts | 4 | ||||
-rw-r--r-- | engine/entities/Player.ts | 12 | ||||
-rw-r--r-- | engine/systems/NetworkUpdate.ts | 7 |
5 files changed, 25 insertions, 16 deletions
diff --git a/engine/components/Control.ts b/engine/components/Control.ts index fb7b916..a3621b0 100644 --- a/engine/components/Control.ts +++ b/engine/components/Control.ts @@ -3,7 +3,10 @@ import { Component, ComponentNames, Velocity } from "."; export class Control extends Component { public controlVelocityComponent: Velocity; - constructor(controlVelocityComponent: Velocity = new Velocity()) { + constructor( + controlVelocityComponent: Velocity = new Velocity(), + controllableBy: string + ) { super(ComponentNames.Control); this.controlVelocityComponent = controlVelocityComponent; diff --git a/engine/config/constants.ts b/engine/config/constants.ts index b3c3f62..fa3f81b 100644 --- a/engine/config/constants.ts +++ b/engine/config/constants.ts @@ -4,25 +4,28 @@ export namespace KeyConstants { export const KeyActions: Record<string, Action> = { a: Action.MOVE_LEFT, ArrowLeft: Action.MOVE_LEFT, + d: Action.MOVE_RIGHT, ArrowRight: Action.MOVE_RIGHT, + w: Action.JUMP, ArrowUp: Action.JUMP, }; + // value -> [key] from KeyActions export const ActionKeys: Map<Action, string[]> = Object.keys( KeyActions ).reduce((acc: Map<Action, string[]>, key) => { const action = KeyActions[key]; if (acc.has(action)) { - acc.get(action)?.push(key); + acc.get(action)!.push(key); return acc; } acc.set(action, [key]); return acc; - }, new Map<Action, string[]>()); + }, new Map()); } export namespace PhysicsConstants { @@ -37,6 +40,8 @@ export namespace Miscellaneous { export const WIDTH = 600; export const HEIGHT = 800; - export const DEFAULT_GRID_WIDTH = 40; - export const DEFAULT_GRID_HEIGHT = 40; + export const DEFAULT_GRID_WIDTH = 30; + export const DEFAULT_GRID_HEIGHT = 30; + + export const SERVER_TICK_RATE = 5 / 100; } diff --git a/engine/entities/Entity.ts b/engine/entities/Entity.ts index b2d875d..4e9df78 100644 --- a/engine/entities/Entity.ts +++ b/engine/entities/Entity.ts @@ -4,8 +4,8 @@ export abstract class Entity { public readonly id: string; public readonly components: Map<string, Component>; - constructor() { - this.id = crypto.randomUUID(); + constructor(id: string = crypto.randomUUID()) { + this.id = id; this.components = new Map(); } diff --git a/engine/entities/Player.ts b/engine/entities/Player.ts index 377e0ca..03fa69b 100644 --- a/engine/entities/Player.ts +++ b/engine/entities/Player.ts @@ -21,7 +21,7 @@ export class Player extends Entity { private static MOI: number = 100; private static spriteSpec: SpriteSpec = SPRITE_SPECS.get( - Sprites.COFFEE, + Sprites.COFFEE ) as SpriteSpec; constructor() { @@ -34,12 +34,12 @@ export class Player extends Entity { y: 100, }, { width: Player.spriteSpec.width, height: Player.spriteSpec.height }, - 0, - ), + 0 + ) ); this.addComponent( - new Velocity({ dCartesian: { dx: 0, dy: 0 }, dTheta: 0 }), + new Velocity({ dCartesian: { dx: 0, dy: 0 }, dTheta: 0 }) ); this.addComponent(new Mass(Player.MASS)); @@ -64,8 +64,8 @@ export class Player extends Entity { { x: 0, y: 0 }, { width: Player.spriteSpec.width, height: Player.spriteSpec.height }, Player.spriteSpec.msPerFrame, - Player.spriteSpec.frames, - ), + Player.spriteSpec.frames + ) ); this.addComponent(new FacingDirection(leftSprite, rightSprite)); diff --git a/engine/systems/NetworkUpdate.ts b/engine/systems/NetworkUpdate.ts index 6f8acb9..cdd6de7 100644 --- a/engine/systems/NetworkUpdate.ts +++ b/engine/systems/NetworkUpdate.ts @@ -18,7 +18,7 @@ export class NetworkUpdate extends System { constructor( queueProvider: MessageQueueProvider, - publisher: MessagePublisher, + publisher: MessagePublisher ) { super(SystemNames.NetworkUpdate); @@ -28,15 +28,16 @@ export class NetworkUpdate extends System { public update(_dt: number, game: Game) { const messages = this.queueProvider.getNewMessages(); + if (messages.length) console.log(messages); this.queueProvider.clearMessages(); game.forEachEntityWithComponent( ComponentNames.NetworkUpdateable, (entity) => { const networkUpdateComponent = entity.getComponent<NetworkUpdateable>( - ComponentNames.NetworkUpdateable, + ComponentNames.NetworkUpdateable ); - }, + } ); } } |