summaryrefslogtreecommitdiffstats
path: root/Render.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Render.hs')
-rw-r--r--Render.hs54
1 files changed, 29 insertions, 25 deletions
diff --git a/Render.hs b/Render.hs
index 8832d3b..145dc8b 100644
--- a/Render.hs
+++ b/Render.hs
@@ -1,5 +1,5 @@
module Render ( setup
- , resize
+ --, resize
, render
) where
@@ -34,6 +34,7 @@ texturePath :: Texture -> String
texturePath t
| t == TextureWood = "tex/Wood.png"
| t == TextureTank = "tex/Tank.png"
+ | t == TextureCannon = "tex/Cannon.png"
getTexture :: Texture -> Game TextureObject
getTexture t = do
@@ -49,9 +50,8 @@ getTexture t = do
return tex
-setup :: Int -> Int -> Game ()
-setup w h = do
- resize w h
+setup :: Game ()
+setup = do
liftIO $ do
blend $= Enabled
blendFunc $= (SrcAlpha, OneMinusSrcAlpha)
@@ -59,33 +59,17 @@ setup w h = do
-- cache textures
getTexture TextureWood
getTexture TextureTank
+ getTexture TextureCannon
return ()
-resize :: Int -> Int -> Game ()
-resize w h = do
- let wn = fromIntegral w
- hn = fromIntegral h
- aspect = fromReal (wn/hn)
-
- lvl <- gets level
- let s = max (0.5*(fromIntegral $ levelWidth lvl)/aspect) (0.5*(fromIntegral $ levelHeight lvl)) :: GLdouble
-
- liftIO $ do
- matrixMode $= Projection
- loadIdentity
- ortho (-s*aspect) (s*aspect) (-s) s (-1) 1
-
- matrixMode $= Modelview 0
-
- viewport $= ((Position 0 0), (Size (fromIntegral w) (fromIntegral h)))
-
render :: Game ()
render = do
tanklist <- gets tanks
textureWood <- getTexture TextureWood
textureTank <- getTexture TextureTank
+ textureCannon <- getTexture TextureCannon
(lw, lh) <- gets level >>= \l -> return (fromIntegral . levelWidth $ l :: GLfloat, fromIntegral . levelHeight $ l :: GLfloat)
@@ -108,14 +92,33 @@ render = do
texCoord $ TexCoord2 lh (0 :: GLfloat)
vertex $ Vertex2 (0.5*lw) (-0.5*lh)
- textureBinding Texture2D $= Just textureTank
-
forM_ tanklist $ \tank -> preservingMatrix $ do
let x = fromReal . posx $ tank
y = fromReal . posy $ tank
+ rotDir = 90 + (fromReal . dir $ tank)
+ rotAim = 90 + (fromReal . aim $ tank)
translate $ Vector3 x y (0 :: GLfloat)
- rotate (90 + (fromReal . dir $ tank)) $ Vector3 0 0 (1 :: GLfloat)
+ rotate rotDir $ Vector3 0 0 (1 :: GLfloat)
+
+ textureBinding Texture2D $= Just textureTank
+
+ renderPrimitive Quads $ do
+ texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat)
+ vertex $ Vertex2 (-0.5 :: GLfloat) (-0.5 :: GLfloat)
+
+ texCoord $ TexCoord2 (0 :: GLfloat) (1 :: GLfloat)
+ vertex $ Vertex2 (-0.5 :: GLfloat) (0.5 :: GLfloat)
+
+ texCoord $ TexCoord2 (1 :: GLfloat) (1 :: GLfloat)
+ vertex $ Vertex2 (0.5 :: GLfloat) (0.5 :: GLfloat)
+
+ texCoord $ TexCoord2 (1 :: GLfloat) (0 :: GLfloat)
+ vertex $ Vertex2 (0.5 :: GLfloat) (-0.5 :: GLfloat)
+
+ rotate (rotAim-rotDir) $ Vector3 0 0 (1 :: GLfloat)
+
+ textureBinding Texture2D $= Just textureCannon
renderPrimitive Quads $ do
texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat)
@@ -130,5 +133,6 @@ render = do
texCoord $ TexCoord2 (1 :: GLfloat) (0 :: GLfloat)
vertex $ Vertex2 (0.5 :: GLfloat) (-0.5 :: GLfloat)
+
fromReal :: (Real a, Fractional b) => a -> b
fromReal = fromRational . toRational \ No newline at end of file