feat(js): m09 input, app, runtime, browser, main, index.html and smoke test
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
584f1d4825
commit
8028bb2fc0
@@ -0,0 +1,24 @@
|
||||
import { Action } from './model.js'
|
||||
import { update } from './game.js'
|
||||
import { newGame } from './spawn.js'
|
||||
import { view } from './view.js'
|
||||
import { map as mapIO, randomSeed, drawScene } from './io.js'
|
||||
import { keyDowns, interval, map, filterMap, merge, scan, startWith } from './stream.js'
|
||||
import { keyToAction } from './input.js'
|
||||
|
||||
export const TICK_MS = 150
|
||||
|
||||
// Everything that can happen to the game: a Tick every TICK_MS, and a Turn for each steering key.
|
||||
export const classicActions = merge(
|
||||
map(interval(TICK_MS), () => Action.Tick),
|
||||
filterMap(keyDowns, keyToAction))
|
||||
|
||||
// Actions folded into game states. startWith puts the initial state first so it is drawn right away.
|
||||
export const states = (seed, actions) =>
|
||||
startWith(scan(actions, update, newGame(seed)), newGame(seed))
|
||||
|
||||
export const render = (state) => drawScene(view(state))
|
||||
|
||||
// The whole program as a value: get a seed, then turn the stream of states into a stream of drawings.
|
||||
// Nothing runs here; runtime.js interprets it.
|
||||
export const main = mapIO(randomSeed, (seed) => map(states(seed, classicActions), render))
|
||||
Reference in New Issue
Block a user