diff options
Diffstat (limited to 'engine/config')
-rw-r--r-- | engine/config/assets.ts | 10 | ||||
-rw-r--r-- | engine/config/constants.ts | 8 | ||||
-rw-r--r-- | engine/config/sprites.ts | 35 |
3 files changed, 27 insertions, 26 deletions
diff --git a/engine/config/assets.ts b/engine/config/assets.ts index 51a5303..173bab3 100644 --- a/engine/config/assets.ts +++ b/engine/config/assets.ts @@ -4,7 +4,7 @@ import { SPRITE_SPECS } from "./sprites"; export const IMAGES = new Map<string, HTMLImageElement>(); export const loadSpritesIntoImageElements = ( - spriteSpecs: Partial<SpriteSpec>[] + spriteSpecs: Partial<SpriteSpec>[], ): Promise<void>[] => { const spritePromises: Promise<void>[] = []; @@ -17,13 +17,13 @@ export const loadSpritesIntoImageElements = ( spritePromises.push( new Promise((resolve) => { img.onload = () => resolve(); - }) + }), ); } if (spriteSpec.states) { spritePromises.push( - ...loadSpritesIntoImageElements(Object.values(spriteSpec.states)) + ...loadSpritesIntoImageElements(Array.from(spriteSpec.states.values())), ); } } @@ -34,7 +34,9 @@ export const loadSpritesIntoImageElements = ( export const loadAssets = () => Promise.all([ ...loadSpritesIntoImageElements( - Array.from(SPRITE_SPECS.keys()).map((key) => SPRITE_SPECS.get(key)) + Array.from(SPRITE_SPECS.keys()).map( + (key) => SPRITE_SPECS.get(key) as SpriteSpec, + ), ), // TODO: Sound ]); diff --git a/engine/config/constants.ts b/engine/config/constants.ts index 9a3169b..3d536d3 100644 --- a/engine/config/constants.ts +++ b/engine/config/constants.ts @@ -11,12 +11,12 @@ export namespace KeyConstants { }; export const ActionKeys: Map<Action, string[]> = Object.keys( - KeyActions + 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; } @@ -29,8 +29,8 @@ export namespace PhysicsConstants { export const MAX_JUMP_TIME_MS = 150; export const GRAVITY = 0.0075; export const PLAYER_MOVE_VEL = 1; - export const PLAYER_JUMP_ACC = -0.01; - export const PLAYER_JUMP_INITIAL_VEL = -0.9; + export const PLAYER_JUMP_ACC = -0.008; + export const PLAYER_JUMP_INITIAL_VEL = -1; } export namespace Miscellaneous { diff --git a/engine/config/sprites.ts b/engine/config/sprites.ts index 18bec73..1f65c18 100644 --- a/engine/config/sprites.ts +++ b/engine/config/sprites.ts @@ -10,7 +10,7 @@ export interface SpriteSpec { height: number; frames: number; msPerFrame: number; - states?: Record<string | number, Partial<SpriteSpec>>; + states?: Map<string | number, Partial<SpriteSpec>>; } export const SPRITE_SPECS: Map<Sprites, Partial<SpriteSpec>> = new Map< @@ -22,28 +22,27 @@ const floorSpriteSpec = { height: 40, frames: 3, msPerFrame: 125, - states: {}, + states: new Map<number, Partial<SpriteSpec>>(), }; -floorSpriteSpec.states = [40, 80, 120, 160].reduce((acc, cur) => { - acc[cur] = { - width: cur, - sheet: `/assets/floor_tile_${cur}.png`, - }; - return acc; -}, {}); +[40, 80, 120, 160].forEach((width) => { + floorSpriteSpec.states.set(width, { + width, + sheet: `/assets/floor_tile_${width}.png`, + }); +}); SPRITE_SPECS.set(Sprites.FLOOR, floorSpriteSpec); -SPRITE_SPECS.set(Sprites.COFFEE, { +const coffeeSpriteSpec = { msPerFrame: 100, width: 60, height: 45, frames: 3, - states: { - LEFT: { - sheet: "/assets/coffee_left.png", - }, - RIGHT: { - sheet: "/assets/coffee_right.png", - }, - }, + states: new Map<string, Partial<SpriteSpec>>(), +}; +coffeeSpriteSpec.states.set("LEFT", { + sheet: "/assets/coffee_left.png", +}); +coffeeSpriteSpec.states.set("RIGHT", { + sheet: "/assets/coffee_right.png", }); +SPRITE_SPECS.set(Sprites.COFFEE, coffeeSpriteSpec); |