O'Reilly logo

TypeScript: Modern JavaScript Development by Ivo Gabe de Wolff, Vilic Vane, Remo H. Jansen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required