diff options
Diffstat (limited to 'Demos/Pong')
-rw-r--r-- | Demos/Pong/Main.hs | 34 | ||||
-rw-r--r-- | Demos/Pong/Pong.hs | 16 |
2 files changed, 25 insertions, 25 deletions
diff --git a/Demos/Pong/Main.hs b/Demos/Pong/Main.hs index 4dbe0a3..ee0f8d8 100644 --- a/Demos/Pong/Main.hs +++ b/Demos/Pong/Main.hs | |||
@@ -2,20 +2,20 @@ | |||
2 | 2 | ||
3 | module Main where | 3 | module Main where |
4 | 4 | ||
5 | import Data.Maybe (mapMaybe) | 5 | import Data.Maybe (mapMaybe) |
6 | import Graphics.Rendering.OpenGL.GL (($=)) | 6 | import Graphics.Rendering.OpenGL.GL (($=)) |
7 | import Graphics.Rendering.OpenGL.GL qualified as GL | 7 | import qualified Graphics.Rendering.OpenGL.GL as GL |
8 | import Pong | 8 | import Pong |
9 | import Spear.App | 9 | import Spear.App |
10 | import Spear.Game | 10 | import Spear.Game |
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.Window | 14 | import Spear.Window |
15 | 15 | ||
16 | data GameState = GameState | 16 | data GameState = GameState |
17 | { window :: Window, | 17 | { window :: Window, |
18 | world :: [GameObject] | 18 | world :: [GameObject] |
19 | } | 19 | } |
20 | 20 | ||
21 | main = | 21 | main = |
@@ -53,7 +53,7 @@ renderGO go = do | |||
53 | (xmin, ymin, xmax, ymax) = (f2d xmin', f2d ymin', f2d xmax', f2d ymax') | 53 | (xmin, ymin, xmax, ymax) = (f2d xmin', f2d ymin', f2d xmax', f2d ymax') |
54 | GL.preservingMatrix $ do | 54 | GL.preservingMatrix $ do |
55 | GL.translate (GL.Vector3 (f2d xcenter) (f2d ycenter) 0) | 55 | GL.translate (GL.Vector3 (f2d xcenter) (f2d ycenter) 0) |
56 | GL.renderPrimitive (GL.TriangleStrip) $ do | 56 | GL.renderPrimitive GL.TriangleStrip $ do |
57 | GL.vertex (GL.Vertex2 xmin ymax) | 57 | GL.vertex (GL.Vertex2 xmin ymax) |
58 | GL.vertex (GL.Vertex2 xmin ymin) | 58 | GL.vertex (GL.Vertex2 xmin ymin) |
59 | GL.vertex (GL.Vertex2 xmax ymax) | 59 | GL.vertex (GL.Vertex2 xmax ymax) |
@@ -71,13 +71,13 @@ procEvent _ = return () | |||
71 | 71 | ||
72 | translate = mapMaybe translate' | 72 | translate = mapMaybe translate' |
73 | 73 | ||
74 | translate' (KeyDown KEY_LEFT) = Just MoveLeft | 74 | translate' (KeyDown KEY_LEFT) = Just MoveLeft |
75 | translate' (KeyDown KEY_RIGHT) = Just MoveRight | 75 | translate' (KeyDown KEY_RIGHT) = Just MoveRight |
76 | translate' (KeyUp KEY_LEFT) = Just StopLeft | 76 | translate' (KeyUp KEY_LEFT) = Just StopLeft |
77 | translate' (KeyUp KEY_RIGHT) = Just StopRight | 77 | translate' (KeyUp KEY_RIGHT) = Just StopRight |
78 | translate' _ = Nothing | 78 | translate' _ = Nothing |
79 | 79 | ||
80 | exitRequested = any (== (KeyDown KEY_ESC)) | 80 | exitRequested = elem (KeyDown KEY_ESC) |
81 | 81 | ||
82 | f2d :: Float -> GL.GLdouble | 82 | f2d :: Float -> GL.GLdouble |
83 | f2d = realToFrac | 83 | f2d = realToFrac |
diff --git a/Demos/Pong/Pong.hs b/Demos/Pong/Pong.hs index b048bbc..fd7fbeb 100644 --- a/Demos/Pong/Pong.hs +++ b/Demos/Pong/Pong.hs | |||
@@ -7,12 +7,12 @@ module Pong | |||
7 | ) | 7 | ) |
8 | where | 8 | where |
9 | 9 | ||
10 | import Data.Monoid (mconcat) | 10 | import Data.Monoid (mconcat) |
11 | import GHC.Float (double2Float) | 11 | import GHC.Float (double2Float) |
12 | import Spear.Math.AABB | 12 | import Spear.Math.AABB |
13 | import Spear.Math.Spatial2 | 13 | import Spear.Math.Spatial2 |
14 | import Spear.Math.Vector | 14 | import Spear.Math.Vector |
15 | import Spear.Step | 15 | import Spear.Step |
16 | 16 | ||
17 | -- Configuration | 17 | -- Configuration |
18 | 18 | ||
@@ -42,8 +42,8 @@ data GameEvent | |||
42 | -- Game objects | 42 | -- Game objects |
43 | 43 | ||
44 | data GameObject = GameObject | 44 | data GameObject = GameObject |
45 | { aabb :: AABB2, | 45 | { aabb :: AABB2, |
46 | obj :: Obj2, | 46 | obj :: Obj2, |
47 | gostep :: Step [GameObject] [GameEvent] GameObject GameObject | 47 | gostep :: Step [GameObject] [GameEvent] GameObject GameObject |
48 | } | 48 | } |
49 | 49 | ||