from events to reactions a progress report
play

From Events to Reactions: A Progress Report Tony Garnock-Jones - PowerPoint PPT Presentation

PLACES 2016, Eindhoven, Netherlands; 20160408 From Events to Reactions: A Progress Report Tony Garnock-Jones tonyg@ccs.neu.edu Northeastern University Joint work with Matthias Felleisen and Sam Caldwell A A B B Networked C C Program D


  1. Mapping events to components collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector Sprite published to next outer dataspace ↑ game → game ?(controller-event 'start #t) game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  2. Mapping events to components collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game Game-piece state published locally → game ?(controller-event 'start #t) game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  3. Mapping events to components collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game Subscription to game-piece states → game ?(controller-event 'start #t) game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  4. Mapping events to components collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game Interest in START presses at local dataspace → game ?(controller-event 'start #t) game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  5. Mapping events to components collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game Interest in LEFT presses/releases at local dataspace → game ?(controller-event 'start #t) game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  6. Mapping events to components collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game Interest in clock ticks at local dataspace → game ?(controller-event 'start #t) game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  7. Mapping events to components collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → game ?(controller-event 'start #t) Assertion of sprite position at local dataspace game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  8. Mapping events to components collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → game ?(controller-event 'start #t) game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  9. Mapping events to components collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game Pressing the START key should → game ?(controller-event 'start #t) terminate the game game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  10. Mapping events to components < (controller-event 'start #t) > collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → game ?(controller-event 'start #t) game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  11. Mapping events to components < (controller-event 'start #t) > collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → game ?(controller-event 'start #t) game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  12. Mapping events to components < ⇃ (controller-event 'start #t) > collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → game ?(controller-event 'start #t) game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  13. Mapping events to components quit-dataspace! collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → game ?(controller-event 'start #t) game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  14. Mapping events to components collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker player ⇃ ?(controller-event 'left ★ ) → ⇃ ?(clock-tick) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → game ?(controller-event 'start #t) game ?(controller-event 'left ★ ) → → game ?(clock-tick) → game (sprite 5 'player)

  15. Mapping events to components controller driver game ?(controller-event 'start #t) game ?(controller-event 'left ★ ) game ?(clock-tick) game (sprite 5 'player)

  16. Mapping events to components controller driver

  17. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) ))

  18. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) ))

  19. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) ))

  20. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) ))

  21. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) ))

  22. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) ))

  23. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) ))

  24. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) ))

  25. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) ))

  26. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) )) Dataspace lifetime not syntactically apparent

  27. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) ))

  28. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) )) 2× repetition of pattern

  29. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) ))

  30. (spawn-dataspace (spawn-start-button-monitor) (spawn-player) (spawn-collision-detection) ...) (define (spawn-start-button-monitor) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'start #t))) (transition state (quit-dataspace))])) (void) (sub (controller-event 'start #t) #:meta-level 1) )) 2× repetition of metalevel, in two styles

  31. (dataspace (spawn-player) (spawn-collision-detection) ... (until (message (controller-event 'start #t) #:meta-level 1)))

  32. dataspace termination near dataspace startup (dataspace (spawn-player) (spawn-collision-detection) ... (until (message (controller-event 'start #t) #:meta-level 1)))

  33. (dataspace (spawn-player) (spawn-collision-detection) ... (until (message (controller-event 'start #t) #:meta-level 1))) subscription/message pattern written once

  34. (dataspace (spawn-player) (spawn-collision-detection) ... (until (message (controller-event 'start #t) #:meta-level 1))) metalevel number written once , in one style

  35. Syndicate DSL by example ✓ Mapping events to components • Managing conversational state • Monitoring changes in shared state

  36. Managing conversational state collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level

  37. Managing conversational state collision “start” ... player detector checker Three jobs: ⇃ ?(controller-event 'start #t) → “start” checker − watch state of left-arrow ⇃ ?(controller-event 'left ★ ) → player − listen to clock-tick while arrow pressed controller ⇃ (sprite 5 'player) → player driver → player − maintain sprite & game-piece-state (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level

  38. Managing conversational state < (controller-event 'left #t) > collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level

  39. Managing conversational state < (controller-event 'left #t) > collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level

  40. Managing conversational state < ⇃ (controller-event 'left #t) > collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level

  41. Managing conversational state assert( ⇃ ?(clock-tick) ) collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level

  42. Managing conversational state assert( ⇃ ?(clock-tick) ) collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player player ⇃ ?(clock-tick) → controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level

  43. Managing conversational state assert( ?(clock-tick) ) collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player player ⇃ ?(clock-tick) → controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level

  44. Managing conversational state assert( ?(clock-tick) ) collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player player ⇃ ?(clock-tick) → controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level level → ?(clock-tick)

  45. Managing conversational state collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player player ⇃ ?(clock-tick) → controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level level → ?(clock-tick)

  46. Managing conversational state < (controller-event 'left #f) > collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player player ⇃ ?(clock-tick) → controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level level → ?(clock-tick)

  47. Managing conversational state < (controller-event 'left #f) > collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player player ⇃ ?(clock-tick) → controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level level → ?(clock-tick)

  48. Managing conversational state < ⇃ (controller-event 'left #f) > collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player player ⇃ ?(clock-tick) → controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level level → ?(clock-tick)

  49. Managing conversational state retract( ⇃ ?(clock-tick) ) collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player player ⇃ ?(clock-tick) → controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level level → ?(clock-tick)

  50. Managing conversational state collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player player ⇃ ?(clock-tick) controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level level → ?(clock-tick)

  51. Managing conversational state retract( ?(clock-tick) ) collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level level → ?(clock-tick)

  52. Managing conversational state collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level level ?(clock-tick)

  53. Managing conversational state collision “start” ... player detector checker ⇃ ?(controller-event 'start #t) → “start” checker ⇃ ?(controller-event 'left ★ ) → player controller ⇃ (sprite 5 'player) → player driver → player (game-piece-state 'player 5) ?(game-piece-state ★ ★ ) → collision detector ↑ game → level ?(controller-event 'start #t) ?(controller-event 'left ★ ) → level

  54. (struct player-state (position left-down?)) (define (spawn-player) (define initial-pos 5) (define initial-state (player-state initial-pos #f)) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'left pressed?))) (transition (struct-copy player-state state [left-down? pressed?]) '())] [(message (at-meta (clock-tick))) (define new-state (if (player-state-left-down? state) (struct-copy player-state state [position (- (player-state-position state) 1)]) state)) (define new-pos (player-state-position new-state)) (transition new-state (patch-seq (retract (sprite ? ?) #:meta-level 1) (assert (sprite new-pos 'player) #:meta-level 1) (retract (game-piece-state ? ?)) (assert (game-piece-state 'player new-pos))) )] initial-state (patch-seq (sub (controller-event 'left ?) #:meta-level 1) (sub (clock-tick) #:meta-level 1) (assert (sprite initial-pos 'player) #:meta-level 1) (assert (game-piece-state 'player initial-pos)))))

  55. (struct player-state (position left-down?)) (define (spawn-player) (define initial-pos 5) (define initial-state (player-state initial-pos #f)) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'left pressed?))) (transition (struct-copy player-state state [left-down? pressed?]) '())] [(message (at-meta (clock-tick))) (define new-state (if (player-state-left-down? state) (struct-copy player-state state [position (- (player-state-position state) 1)]) state)) (define new-pos (player-state-position new-state)) (transition new-state (patch-seq (retract (sprite ? ?) #:meta-level 1) (assert (sprite new-pos 'player) #:meta-level 1) (retract (game-piece-state ? ?)) (assert (game-piece-state 'player new-pos))) )] initial-state (patch-seq (sub (controller-event 'left ?) #:meta-level 1) (sub (clock-tick) #:meta-level 1) (assert (sprite initial-pos 'player) #:meta-level 1) (assert (game-piece-state 'player initial-pos)))))

  56. (struct player-state (position left-down?)) (define (spawn-player) (define initial-pos 5) (define initial-state (player-state initial-pos #f)) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'left pressed?))) (transition (struct-copy player-state state [left-down? pressed?]) '())] [(message (at-meta (clock-tick))) (define new-state (if (player-state-left-down? state) (struct-copy player-state state [position (- (player-state-position state) 1)]) state)) (define new-pos (player-state-position new-state)) (transition new-state (patch-seq (retract (sprite ? ?) #:meta-level 1) (assert (sprite new-pos 'player) #:meta-level 1) (retract (game-piece-state ? ?)) (assert (game-piece-state 'player new-pos))) )] initial-state (patch-seq (sub (controller-event 'left ?) #:meta-level 1) (sub (clock-tick) #:meta-level 1) (assert (sprite initial-pos 'player) #:meta-level 1) (assert (game-piece-state 'player initial-pos)))))

  57. (struct player-state (position left-down?)) (define (spawn-player) (define initial-pos 5) (define initial-state (player-state initial-pos #f)) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'left pressed?))) (transition (struct-copy player-state state [left-down? pressed?]) '())] [(message (at-meta (clock-tick))) (define new-state (if (player-state-left-down? state) (struct-copy player-state state [position (- (player-state-position state) 1)]) state)) (define new-pos (player-state-position new-state)) (transition new-state (patch-seq (retract (sprite ? ?) #:meta-level 1) (assert (sprite new-pos 'player) #:meta-level 1) (retract (game-piece-state ? ?)) (assert (game-piece-state 'player new-pos))) )] initial-state (patch-seq (sub (controller-event 'left ?) #:meta-level 1) (sub (clock-tick) #:meta-level 1) (assert (sprite initial-pos 'player) #:meta-level 1) (assert (game-piece-state 'player initial-pos)))))

  58. (struct player-state (position left-down?)) (define (spawn-player) (define initial-pos 5) (define initial-state (player-state initial-pos #f)) (spawn (lambda (evt state) (match-event evt [(message (at-meta (controller-event 'left pressed?))) (transition (struct-copy player-state state [left-down? pressed?]) '())] [(message (at-meta (clock-tick))) (define new-state (if (player-state-left-down? state) (struct-copy player-state state [position (- (player-state-position state) 1)]) state)) (define new-pos (player-state-position new-state)) (transition new-state (patch-seq (retract (sprite ? ?) #:meta-level 1) (assert (sprite new-pos 'player) #:meta-level 1) (retract (game-piece-state ? ?)) (assert (game-piece-state 'player new-pos))) )] initial-state (patch-seq (sub (controller-event 'left ?) #:meta-level 1) (sub (clock-tick) #:meta-level 1) (assert (sprite initial-pos 'player) #:meta-level 1) (assert (game-piece-state 'player initial-pos)))))

Recommend


More recommend