Functional Reactive F# - Storing States in Games -


I am currently learning about functional reactive patterns using F # This is a fundamental new approach to me. I have learned about creating a simple ping-pong game by using this paradigm. I still believe this idea: We believe in the form of time work. On its purest form, it is stateless, however, I have to remember the position of the ball (or state). That's why I always pass the current position of the ball as the parameter of the global function.

If we talk about a bit more complicated games, like Space Invaders, we have many states (aliens, aliens' current hp, number of remaining bombs etc.)

Is there any great / best way to deal with this problem? Do we always store the states at the top level? Should all existing states be given in addition to the global function in the form of input logic?

Can someone use simple samples on F #? Thanks a lot. There are more than one way to FRP, and it is an active field of research.

How much things work with each other, a lot can depend on its description, and in the future there may be new and better techniques.

It is broadly the idea that there are behaviors that are the work of time in place of normal values ​​(as you said). Behavior can be defined in the context of other behaviors, and can be defined to swap between other behaviors during special events. In your example, you usually do not need to remember the position of the ball through logic (but some kind of FRP can do). Instead you can do just one behavior:
ballPos: time -> (Float * float)
This can be a global scope, or for a large program it may be better for a local area with all its uses in that area.

Get more complex, your behavior will be defined more complexly, will depend on other behaviors and events - which include recurrent dependencies that are controlled separately in separate FRP frameworks . For recursive dependencies I had expected that you would need a REC with all the included behaviors, although they can still be arranged in the structures - you can have the top-level:

  type alienInfo = {pos: float * float; Hp: float} type playerInfo = {pos: float * float; Bomb: int} REC Aliens: Time - & gt; AlienInfo array = // You may want to be lazy here. Give behavior = [| 1.Name alien for - & gt; (AlienPos Player N, Alian HP Player N) |] Fun T - & gt; [| In practice (posBeh, hpBeh) - & gt; {Pos = posBeh t; Hp = hpbih t} | // // you want lazes here. And Player: Time - & gt; PlayerInfo = Funny T - & gt; {Pos = playerPos aliens t; Bombs = playerBombs aliens t}  

And then the behavior of alienPos can be defined, alienHP, with player dependence, and player ops, player bombs can be defined with dependence on aliens Could.

However, if you can give as much detail as to what kind of FRP you are using, then it will be easier to give more specific advice. (And if you want advice - how do I personally recommend reading):


Comments