@@ -1,72 +0,0 @@
4−import Maybe (mapMaybe)
16−desiredFPS = lift castIntToJSNumber dFPS
17−foreign export jsevent "desiredFPS"
18− desiredFPS :: Signal JSNumber
21−foreign import jsevent "trigger" (castIntToJSNumber 0)
22− jsTime :: Signal JSNumber
24−time = lift castJSNumberToFloat jsTime
27−-- Calculate FPS based on incoming times.
30− let len = length ts in
31− if len > 1 then (len-1) / (head ts - last ts) else 0
32−fps = lift (truncate . getFPS) (foldp (\t ts -> take 10 (t:ts)) [0] time)
35−-- Use time and keyboard input to determine the
36−-- position of the black square.
38−addVecs (x1,y1) (x2,y2) = (x1+x2, y1+y2)
39−scaleBy s (x,y) = (x*s, y*s)
42− if k < 37 || k > 40 then (x,y) else
43− if k `mod` 2 == 1 then (x + k - 38, y)
46−velocity = lift (foldl addKey (0,0)) keysDown
48−timestep = lift snd $ foldp (\t1 (t0,d) -> (t1, t1-t0)) (0,0) time
50−delta = dropIf (\(x,y) -> x == 0 && y == 0) (0,0) . sampleOn timestep $
51− lift (scaleBy 100) (lift2 scaleBy timestep velocity)
53−position = foldp addVecs (0,0) delta
56−-- Display moving square and FPS on screen.
59− flow down [ collage 400 400 [ outlined black (rect 40 40 pos) ]
60− , plainText "Move the square around with the arrow keys."
61− , plainText $ "Actual frames per second: " ++ show actual
62− , plainText "Desired frames per second: " `beside` drop
66−game = lift2 screen position fps
68−done = lift (\_ -> castBoolToJSBool True) game
69−foreign export jsevent "finished"
70− done :: Signal JSBool