Game structure
Minimal game: free movement on a 12x12 grid.
const scene = GameLib.defineWorld({columns: 12, rows: 12})
const game = {
init: () => ({x: 2, y: 2, direction: 'down-right'}),
step(state, input, world, dt) {
return {...state, ...GameLib.moveInWorld(scene, state, input.vector(), dt)}
},
draw(state, g, world) {
g.clear()
GameLib.drawWorld(g, scene, {
time: world.time,
objects: [{sprite: 'hero', ...state, pose: state.moving ? 'walk' : 'idle'}],
})
},
}