aboutsummaryrefslogtreecommitdiff
path: root/Demos/Pong
diff options
context:
space:
mode:
Diffstat (limited to 'Demos/Pong')
-rw-r--r--Demos/Pong/Main.hs17
-rw-r--r--Demos/Pong/Pong.hs17
2 files changed, 17 insertions, 17 deletions
diff --git a/Demos/Pong/Main.hs b/Demos/Pong/Main.hs
index ee55622..c863a55 100644
--- a/Demos/Pong/Main.hs
+++ b/Demos/Pong/Main.hs
@@ -53,6 +53,14 @@ step elapsed dt inputEvents = do
53 } 53 }
54 return (not $ exitRequested inputEvents) 54 return (not $ exitRequested inputEvents)
55 55
56processInput :: Window -> Game GameState [GameEvent]
57processInput window = processKeys window
58 [ (KEY_A, MoveLeft)
59 , (KEY_D, MoveRight)
60 ]
61
62exitRequested = elem (KeyDown KEY_ESC)
63
56render :: Game GameState () 64render :: Game GameState ()
57render = do 65render = do
58 gameState <- getGameState 66 gameState <- getGameState
@@ -113,12 +121,3 @@ resize (ResizeEvent w h) =
113 modifyGameState $ \state -> state { 121 modifyGameState $ \state -> state {
114 viewProjection = Matrix4.ortho left right bottom top (-1) 1 122 viewProjection = Matrix4.ortho left right bottom top (-1) 1
115 } 123 }
116
117
118processInput :: Window -> Game GameState [GameEvent]
119processInput window = processKeys window
120 [ (KEY_A, MoveLeft)
121 , (KEY_D, MoveRight)
122 ]
123
124exitRequested = elem (KeyDown KEY_ESC)
diff --git a/Demos/Pong/Pong.hs b/Demos/Pong/Pong.hs
index 2bd9df1..e834c5d 100644
--- a/Demos/Pong/Pong.hs
+++ b/Demos/Pong/Pong.hs
@@ -77,14 +77,6 @@ instance Spatial GameObject Vector2 Angle Transform2 where
77 transform = basis 77 transform = basis
78 78
79 79
80stepWorld :: Elapsed -> Dt -> [GameEvent] -> [GameObject] -> [GameObject]
81stepWorld elapsed dt evts gos = map (update elapsed dt evts gos) gos
82
83update :: Elapsed -> Dt -> [GameEvent] -> [GameObject] -> GameObject -> GameObject
84update elapsed dt evts gos go =
85 let (go', s') = runStep (gostep go) elapsed dt gos evts go
86 in go' {gostep = s'}
87
88ballBox, padBox :: AABB2 80ballBox, padBox :: AABB2
89ballBox = AABB2 (vec2 (-s) (-s)) (vec2 s s) where s = ballSize 81ballBox = AABB2 (vec2 (-s) (-s)) (vec2 s s) where s = ballSize
90padBox = AABB2 (-padSize) padSize 82padBox = AABB2 (-padSize) padSize
@@ -96,6 +88,15 @@ newWorld =
96 ] 88 ]
97 where makeAt = newTransform2 unitx2 unity2 89 where makeAt = newTransform2 unitx2 unity2
98 90
91
92stepWorld :: Elapsed -> Dt -> [GameEvent] -> [GameObject] -> [GameObject]
93stepWorld elapsed dt evts gos = map (update elapsed dt evts gos) gos
94
95update :: Elapsed -> Dt -> [GameEvent] -> [GameObject] -> GameObject -> GameObject
96update elapsed dt evts gos go =
97 let (go', s') = runStep (gostep go) elapsed dt gos evts go
98 in go' {gostep = s'}
99
99-- Ball steppers 100-- Ball steppers
100 101
101stepBall vel = collideBall vel .> moveBall 102stepBall vel = collideBall vel .> moveBall