aboutsummaryrefslogtreecommitdiff
path: root/Demos/Pong
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2023-03-10 09:30:47 -0800
committer3gg <3gg@shellblade.net>2023-03-10 09:30:47 -0800
commitb2b0e12c212a40ef2469f77043573b5569ff9e6d (patch)
tree2143488908f04414e74f6c36f0e373982f27d32c /Demos/Pong
parent6e26564f4235eeea5dda386282e18081db6f8f07 (diff)
Minor refactoring and formatting.
Diffstat (limited to 'Demos/Pong')
-rw-r--r--Demos/Pong/Main.hs34
-rw-r--r--Demos/Pong/Pong.hs16
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
3module Main where 3module Main where
4 4
5import Data.Maybe (mapMaybe) 5import Data.Maybe (mapMaybe)
6import Graphics.Rendering.OpenGL.GL (($=)) 6import Graphics.Rendering.OpenGL.GL (($=))
7import Graphics.Rendering.OpenGL.GL qualified as GL 7import qualified Graphics.Rendering.OpenGL.GL as GL
8import Pong 8import Pong
9import Spear.App 9import Spear.App
10import Spear.Game 10import Spear.Game
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.Window 14import Spear.Window
15 15
16data GameState = GameState 16data GameState = GameState
17 { window :: Window, 17 { window :: Window,
18 world :: [GameObject] 18 world :: [GameObject]
19 } 19 }
20 20
21main = 21main =
@@ -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
72translate = mapMaybe translate' 72translate = mapMaybe translate'
73 73
74translate' (KeyDown KEY_LEFT) = Just MoveLeft 74translate' (KeyDown KEY_LEFT) = Just MoveLeft
75translate' (KeyDown KEY_RIGHT) = Just MoveRight 75translate' (KeyDown KEY_RIGHT) = Just MoveRight
76translate' (KeyUp KEY_LEFT) = Just StopLeft 76translate' (KeyUp KEY_LEFT) = Just StopLeft
77translate' (KeyUp KEY_RIGHT) = Just StopRight 77translate' (KeyUp KEY_RIGHT) = Just StopRight
78translate' _ = Nothing 78translate' _ = Nothing
79 79
80exitRequested = any (== (KeyDown KEY_ESC)) 80exitRequested = elem (KeyDown KEY_ESC)
81 81
82f2d :: Float -> GL.GLdouble 82f2d :: Float -> GL.GLdouble
83f2d = realToFrac 83f2d = 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 )
8where 8where
9 9
10import Data.Monoid (mconcat) 10import Data.Monoid (mconcat)
11import GHC.Float (double2Float) 11import GHC.Float (double2Float)
12import Spear.Math.AABB 12import Spear.Math.AABB
13import Spear.Math.Spatial2 13import Spear.Math.Spatial2
14import Spear.Math.Vector 14import Spear.Math.Vector
15import Spear.Step 15import Spear.Step
16 16
17-- Configuration 17-- Configuration
18 18
@@ -42,8 +42,8 @@ data GameEvent
42-- Game objects 42-- Game objects
43 43
44data GameObject = GameObject 44data 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