Creating the time handler
The time handler requires some more work. First, we import other types and functions.
import { State, Level, Object, Enemy, Wall, Movement, isOppositeMovement, onGrid, Difficulty } from "./model"; import { update, randomInt, chance, distance, isInt } from "./utils";
We define a step
function so that we can add the menu
later on.
export function step(state: State) { return stepLevel(state); }
In stepLevel
, we can update the objects in the level. First, we update the location of the enemies. We use stepEnemy
, which we define later on.
function stepLevel(state: State): State { const level = state.level; const enemies = level.enemies.map(enemy => stepEnemy(enemy, level.player, level.walls, level.difficulty));
We update the location ...
Get TypeScript: Modern JavaScript Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.