summaryrefslogtreecommitdiffstats
path: root/Render.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Render.hs')
-rw-r--r--Render.hs35
1 files changed, 31 insertions, 4 deletions
diff --git a/Render.hs b/Render.hs
index bd989b3..e51b2fb 100644
--- a/Render.hs
+++ b/Render.hs
@@ -5,7 +5,6 @@ module Render ( setup
import Game
import Level
-import Tank
import Texture
import Control.Monad.State
@@ -34,6 +33,7 @@ texturePath t
| t == TextureWood = "tex/Wood.png"
| t == TextureTank = "tex/Tank.png"
| t == TextureCannon = "tex/Cannon.png"
+ | t == TextureBullet = "tex/Bullet.png"
getTexture :: Texture -> Game TextureObject
getTexture t = do
@@ -59,6 +59,7 @@ setup = do
getTexture TextureWood
getTexture TextureTank
getTexture TextureCannon
+ getTexture TextureBullet
return ()
@@ -66,9 +67,12 @@ setup = do
render :: Game ()
render = do
tanklist <- gets tanks
+ shootlist <- gets shoots
+
textureWood <- getTexture TextureWood
textureTank <- getTexture TextureTank
textureCannon <- getTexture TextureCannon
+ textureBullet <- getTexture TextureBullet
(lw, lh) <- gets level >>= \l -> return (fromIntegral . levelWidth $ l :: GLfloat, fromIntegral . levelHeight $ l :: GLfloat)
@@ -94,8 +98,8 @@ render = do
forM_ tanklist $ \tank -> preservingMatrix $ do
let x = fromReal . posx $ tank
y = fromReal . posy $ tank
- rotDir = 90 + (fromReal . dir $ tank)
- rotAim = 90 + (fromReal . aim $ tank)
+ rotDir = fromReal . dir $ tank
+ rotAim = fromReal . aim $ tank
translate $ Vector3 x y (0 :: GLfloat)
rotate rotDir $ Vector3 0 0 (1 :: GLfloat)
@@ -131,7 +135,30 @@ render = do
texCoord $ TexCoord2 (1 :: GLfloat) (0 :: GLfloat)
vertex $ Vertex2 (0.5 :: GLfloat) (-0.5 :: GLfloat)
-
+
+ forM_ shootlist $ \shoot -> preservingMatrix $ do
+ let x = fromReal . shootX $ shoot
+ y = fromReal . shootY $ shoot
+ rotDir = fromReal . shootDir $ shoot
+
+ translate $ Vector3 x y (0 :: GLfloat)
+ rotate rotDir $ Vector3 0 0 (1 :: GLfloat)
+
+ textureBinding Texture2D $= Just textureBullet
+
+ renderPrimitive Quads $ do
+ texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat)
+ vertex $ Vertex2 (-0.2 :: GLfloat) (-0.2 :: GLfloat)
+
+ texCoord $ TexCoord2 (0 :: GLfloat) (1 :: GLfloat)
+ vertex $ Vertex2 (-0.2 :: GLfloat) (0.2 :: GLfloat)
+
+ texCoord $ TexCoord2 (1 :: GLfloat) (1 :: GLfloat)
+ vertex $ Vertex2 (0.2 :: GLfloat) (0.2 :: GLfloat)
+
+ texCoord $ TexCoord2 (1 :: GLfloat) (0 :: GLfloat)
+ vertex $ Vertex2 (0.2 :: GLfloat) (-0.2 :: GLfloat)
+
fromReal :: (Real a, Fractional b) => a -> b
fromReal = fromRational . toRational \ No newline at end of file