2

A simple game that runs its logic every iteration and draws to the screen 60 times per second in an imperative language might look like this:

function main() {
    player = new Player()
    lastUpdateTime, lastDrawTime = getTime()
    while (!quit) {
        deltaTime = getTime() - lastUpdateTime
        player.update(deltaTime)
        if (getTime() - lastDrawTime > 1/60) {
            player.draw()
            lastDrawTime = getTime()
        }
        lastUpdateTime = getTime()
    }
    delete player
}

I'm just not sure how that translates to reactive-banana.

mcjohnalds45
  • 667
  • 1
  • 8
  • 16
  • BTW: Variable dt isn't good. This will cause accuracy loss in the most of integration schemes. – user3974391 Dec 13 '13 at 12:55
  • I'm new to frp and not sure what you mean by "integration schemes," but as long as it wouldn't cause a difference noticeable to the user, it should be fine for most games. – mcjohnalds45 Dec 13 '13 at 13:03
  • 3
    Games usually use some sort of 'physics'. Generally speaking, game physics is system of ODEs which are solved by integration. Most of advanced integration schemes require constant dt. But this is a complain on your C code, it isn't related to FRP, so don't mind. In terms of FRP your code falls perfectly within the 'behavior' concept. – user3974391 Dec 13 '13 at 13:11
  • 1
    Is your question answered by the answers in ["How to implement a game loop in reactive-banana?"](http://stackoverflow.com/q/12685430/403805)? – Heinrich Apfelmus Dec 14 '13 at 09:58
  • @heinrich Kind of, I did however find a [gist](https://github.com/JPMoresmau/TypeClass/blob/master/src/Main.hs) that shows how to use reactive-banana for everything in an SDL game _except_ the actual game logic. So once I get an example working I'll write an answer. – mcjohnalds45 Dec 14 '13 at 23:47

0 Answers0