diff options
Diffstat (limited to 'demos')
-rw-r--r-- | demos/pong/Pong.hs | 34 |
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 | |||
11 | import Spear.Math.AABB | 11 | import Spear.Math.AABB |
12 | import Spear.Math.Spatial2 | 12 | import Spear.Math.Spatial2 |
13 | import Spear.Math.Vector | 13 | import Spear.Math.Vector |
14 | import Spear.Step | ||
14 | 15 | ||
15 | import Data.List (foldl') | 16 | import Data.List (foldl') |
16 | import Data.Monoid | 17 | import Data.Monoid |
17 | import GHC.Float (double2Float) | 18 | import GHC.Float (double2Float) |
18 | 19 | ||
19 | type Elapsed = Double | ||
20 | type Dt = Float | ||
21 | |||
22 | -- Step function | ||
23 | |||
24 | data Step a b = Step { step :: Elapsed -> Dt -> a -> (b, Step a b) } | ||
25 | |||
26 | sid :: Step a a | ||
27 | sid = Step $ \_ _ a -> (a, sid) | ||
28 | |||
29 | spure :: (a -> b) -> Step a b | ||
30 | spure f = Step $ \_ _ x -> (f x, spure f) | ||
31 | |||
32 | smap :: (a -> b) -> Step c a -> Step c b | ||
33 | smap 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 | |||
46 | sfst :: Step (a,b) a | ||
47 | sfst = spure $ \(a,_) -> a | ||
48 | |||
49 | ssnd :: Step (a,b) b | ||
50 | ssnd = spure $ \(_,b) -> b | ||
51 | |||
52 | -- Game events | 20 | -- Game events |
53 | 21 | ||
54 | data GameEvent | 22 | data GameEvent |