fumieval / free-game

The free game engine
http://hackage.haskell.org/package/free-game
BSD 3-Clause "New" or "Revised" License
64 stars 15 forks source link

Stateful demo request #28

Closed EPashkin closed 9 years ago

EPashkin commented 10 years ago

Can be added demo with state? I wrote a demo based on the article http://fumieval.hatenablog.com/entry/2013/01/10/201945 Perhaps now it is better to use another method.

-- demo_stateful.hs
import FreeGame

data StateData = StateData { _counter :: Int
                           , _font :: Font
                           }

loop :: StateData -> Game ()
loop state = do
    let fnt = _font state
        cnt = 1 + _counter state
        state' = state{_counter = cnt}

    translate (V2 100 240) . color green . text fnt 15 $ show cnt
    translate (V2 340 240) . rotateD (fromIntegral cnt) . color red $ text fnt 70 "Test"

    key <- keyPress KeyEscape
    unless key $ tick >> loop state'

main = runGame Windowed (Box (V2 0 0) (V2 640 480)) $ do
    font <- loadFont "VL-PGothic-Regular.ttf"
    clearColor black
    let state = StateData{_counter = 0, _font = font}
    loop state
fumieval commented 10 years ago

Actually I don't care for record syntax (since I am a lens junkie). But as you say, we need some "animated" example.

EPashkin commented 10 years ago

My demo is normal? Or is there a way to transfer status when using foreverFrame? I have not found it.

fumieval commented 10 years ago

StateT can abstract states :)

As of now foreverFrame is inflexible so that foreverFrame cannot be used over StateT -- I have to improve somehow.

EPashkin commented 10 years ago

I'm do stateful loop with state in my project. But I have not found a way to apply to StateT to Game for use with runGame without loss of state.

EPashkin commented 9 years ago

It seems there is no better solution :(