3

In my breakout implementation there are two main behaviors that describe the game's main state:

paddlePosition :: Behavior t Point
ballPosition :: Behavior t Point

Both are implemented in terms of tickEvent :: Event t () which discretely updates them.

The gameOverEvent :: Event t () filters all tick events where the ball position is below the screen.

I would like to replace paddlePosition by a new behavior as soon as there is a gameOverEvent, leaving the paddle in place, in pseudo code:

newPaddlePosition = \t -> case gameOverEvent of
    [] -> paddlePosition t
    ((t',()) : _) -> paddlePosition t'

The first question is: How do I express newPaddlePosition using reactive-banana?

The second is question is a bit more vague: What is a good way to organize the whole program depending on if the game is over or not? There are other considerations like: How to handle ballPosition, how to draw the game, and so on.

1 Answers1

0

You are probably looking for dynamic event switching, in particular the switchB combinator.

See also this question.

Note that the pseudocode for your newPaddlePosition function does not make much sense: It says that when the gameOverEvent never occurs, then the new paddle position is equal to paddlePosition, otherwise it is constant and equal to the value of paddlePosition at the time that the event occurs. This is impossible to express in a causal FRP library. You probably mean something else.

Community
  • 1
  • 1
Heinrich Apfelmus
  • 11,034
  • 1
  • 39
  • 67