I'm making a game where I need to draw random lines on the screen. Now it seems like Random needs a signal to work in 0.13 (and we are forced to work in 0.13). So how do I obtain those random number?
I started from the game skeleton provided at the elm-lang website and got to this:
type UserInput = { space : Bool, keys : [KeyCode] }
type Input = { timeDelta : Float, userInput : UserInput }
userInput : Signal UserInput
userInput = lift2 UserInput Keyboard.space Keyboard.keysDown
framesPerSecond = 30
delta : Signal Float
delta = lift (\t -> t / framesPerSecond) (Time.fps framesPerSecond)
input : Signal Input
input = Signal.sampleOn delta (Signal.lift2 Input delta userInput)
gameState : Signal GameState
gameState = Signal.foldp stepGame defaultGame input
stepGame : Input -> GameState -> GameState
stepGame i g =
if g.state == Start then *Get random floats*
Now in stepGame, I want to draw random lines. The problem is that I can only get random floats by providing a signal in 0.13. I have the Input signal close by the step function, but when I change the header to lets say stepGame : Signal Input -> GameState -> GameState
it doesn't compile. So how do I get a signal in that function to get some random numbers... I can't seem to find the solution, it's driving me crazy.
Aucun commentaire:
Enregistrer un commentaire