The question is somewhat vague and not easy to answer, but I'll try my best.
First, looking at your code, I find it odd that you have "outsourced" the actual gameplay logic to the monolithic GameState
type and the updateGS
function. Now, this is not a bad thing to do, it's just that there is no benefit from using FRP in this style. You can remove the makeNetworkDescription
function altogether and register an even thandler with addCommandEvent
by hand instead.
The benefit of FRP is that you can model the game state as a network of behaviors and events. If the state is modular enough, then this will simplify the code significantly.
Second, concerning your question about modelling hyperspace travel.
Here is one way to do it:
-- indicates whether hyperspace travel is currently happening
bTravelling :: Behavior t Bool
-- increment travel distance, but only when travelling
bTravelDistance :: Behavior t Distance
bTravelDistance = accumB 0 $ (+1) <$> whenE bTravelling eTick
-- calculate player location from travel distance
bPlayerLocation :: Behavior t Location
bPlayerLocation =
(\distance -> if distance > total then Left Planet else Right HyperSpace)
<$> bTravelDistance
You probably want to repeat this process several times in a game, though. Unfortunately, reactive-banana currently doesn't offer a "first do this, then do that" kind of abstraction. There is dynamic event switching, but it may be a bit unwieldy.