Everyone seems to be making a computer game with a reactive banana FRP structure, so I had to try this too. However, I was stuck with the early steps trying to describe the game data as types of Behavior reactive banana.
Basically, I'm trying to have a (changing) list of game characters (such as Frodo or Sam). Game characters can be updated on every tick of the game (modeled as a tick event). The idea is that whenever a game symbol changes, a single Event (Character) triggered, and the symbol update is finally sent over the network. The advantage of this in comparison with Asteroids.hs should be that the full state of the game (the entire list of game characters) does not need to be sent over the network, as there will be a number of events having one game symbol instead of one event with a game list of symbols.
For one game character, this works great! I created a Behavior (Character) using mapaccum so that the symbol update signal is sent when the symbol is updated. The problem that I cannot solve is how to make this work with the Behavior list of game characters.
I am trying to simulate a list of game characters as Behavior , as characters can come and go during the game. Do I need to use dynamic event switching here? Or, if I do not use Behavior with individual game symbols (and use only Behavior in the list of game symbols), is there a way to conditionally trigger update events when I look at the list of symbols? Or do I understand nothing here?
source share