aboutsummaryrefslogtreecommitdiff
path: root/demos/pong/Pong.hs
diff options
context:
space:
mode:
authorJeanne-Kamikaze <jeannekamikaze@gmail.com>2013-08-11 23:58:28 +0200
committerJeanne-Kamikaze <jeannekamikaze@gmail.com>2013-08-11 23:58:28 +0200
commit59d2edd9877a2aa1e243597052a3af6bbeefa3cf (patch)
treeef77d9bcd77b159529b4b268ce1bbee2801a1268 /demos/pong/Pong.hs
parente15a9cc51e31b5deb973d8583298aa130dd82b17 (diff)
Moved step into its own module
Diffstat (limited to 'demos/pong/Pong.hs')
-rw-r--r--demos/pong/Pong.hs34
1 files changed, 1 insertions, 33 deletions
diff --git a/demos/pong/Pong.hs b/demos/pong/Pong.hs
index 9a3138b..b323aa2 100644
--- a/demos/pong/Pong.hs
+++ b/demos/pong/Pong.hs
@@ -11,44 +11,12 @@ where
11import Spear.Math.AABB 11import Spear.Math.AABB
12import Spear.Math.Spatial2 12import Spear.Math.Spatial2
13import Spear.Math.Vector 13import Spear.Math.Vector
14import Spear.Step
14 15
15import Data.List (foldl') 16import Data.List (foldl')
16import Data.Monoid 17import Data.Monoid
17import GHC.Float (double2Float) 18import GHC.Float (double2Float)
18 19
19type Elapsed = Double
20type Dt = Float
21
22-- Step function
23
24data Step a b = Step { step :: Elapsed -> Dt -> a -> (b, Step a b) }
25
26sid :: Step a a
27sid = Step $ \_ _ a -> (a, sid)
28
29spure :: (a -> b) -> Step a b
30spure f = Step $ \_ _ x -> (f x, spure f)
31
32smap :: (a -> b) -> Step c a -> Step c b
33smap f (Step s1) = Step $ \elapsed dt x ->
34 let (a, s') = s1 elapsed dt x
35 in (f a, smap f s')
36
37(.>) :: Step a b -> Step b c -> Step a c
38(Step s1) .> (Step s2) = Step $ \elapsed dt a ->
39 let (b, s1') = s1 elapsed dt a
40 (c, s2') = s2 elapsed dt b
41 in (c, s1' .> s2')
42
43(.<) :: Step a b -> Step c a -> Step c b
44(.<) = flip (.>)
45
46sfst :: Step (a,b) a
47sfst = spure $ \(a,_) -> a
48
49ssnd :: Step (a,b) b
50ssnd = spure $ \(_,b) -> b
51
52-- Game events 20-- Game events
53 21
54data GameEvent 22data GameEvent