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 of the player based on the current movement:
const player = stepPlayer(level.player, level.currentMovement, level.walls);
Dots that are near the player, are eaten by the player...