summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2010-03-15 14:46:14 +0100
committerMatthias Schiffer <matthias@gamezock.de>2010-03-15 14:46:14 +0100
commit90b8d87e02bfb0d1d3d10c3b824df8fd8ce37a9f (patch)
tree35f51096c034e881198447671896535dafcdbe69
parente85dc20a4869c91faa3869695d2d19bfe07f9abc (diff)
downloadhtanks-90b8d87e02bfb0d1d3d10c3b824df8fd8ce37a9f.tar
htanks-90b8d87e02bfb0d1d3d10c3b824df8fd8ce37a9f.zip
Reorganized code to add Debris class
-rw-r--r--htanks.cabal2
-rw-r--r--src/Collision.hs2
-rw-r--r--src/Debris.hs21
-rw-r--r--src/DefaultPlayer.hs2
-rw-r--r--src/Game.hs17
-rw-r--r--src/HTanks.hs1
-rw-r--r--src/Level.hs10
-rw-r--r--src/Player.hs2
-rw-r--r--src/Render.hs7
-rw-r--r--src/Simulation.hs1
-rw-r--r--src/Tank.hs17
11 files changed, 57 insertions, 25 deletions
diff --git a/htanks.cabal b/htanks.cabal
index 584e905..34eb52c 100644
--- a/htanks.cabal
+++ b/htanks.cabal
@@ -14,7 +14,7 @@ data-files: tex/*.png
executable: HTanks
hs-source-dirs: src
main-is: HTanks.hs
-other-modules: Collision, CPUPlayer, DefaultPlayer, Game, GLDriver, GLX, Level, MainLoop, Paths_htanks, Player, Render, Simulation, Texture,
+other-modules: Collision, CPUPlayer, DefaultPlayer, Game, GLDriver, GLX, Level, MainLoop, Paths_htanks, Player, Render, Simulation, Texture, Debris, Tank,
Bindings.GLX, Bindings.GLPng
ghc-options: -threaded -O2
extra-libraries: glpng
diff --git a/src/Collision.hs b/src/Collision.hs
index d29738a..84227d4 100644
--- a/src/Collision.hs
+++ b/src/Collision.hs
@@ -1,7 +1,7 @@
module Collision ( collisionTankBorder
) where
-import Game
+import Tank
import Data.Fixed
import Data.Ratio
diff --git a/src/Debris.hs b/src/Debris.hs
new file mode 100644
index 0000000..40b7def
--- /dev/null
+++ b/src/Debris.hs
@@ -0,0 +1,21 @@
+{-# LANGUAGE ExistentialQuantification #-}
+
+module Debris ( Debris(..)
+ , SomeDebris(..)
+ ) where
+
+import Tank
+
+class Show a => Debris a where
+ collideTank :: a -> Tank -> Tank
+
+
+data SomeDebris = forall a. Debris a => SomeDebris a
+
+instance Show SomeDebris
+ where
+ show (SomeDebris a) = show a
+
+instance Debris SomeDebris
+ where
+ collideTank (SomeDebris a) = collideTank a
diff --git a/src/DefaultPlayer.hs b/src/DefaultPlayer.hs
index af9aaf5..49371dc 100644
--- a/src/DefaultPlayer.hs
+++ b/src/DefaultPlayer.hs
@@ -9,7 +9,7 @@ import Data.Fixed
import Data.Ratio ((%))
import Data.Typeable
-import Game (Tank(..))
+import Tank
import GLDriver
import Player
diff --git a/src/Game.hs b/src/Game.hs
index 248287b..651918c 100644
--- a/src/Game.hs
+++ b/src/Game.hs
@@ -1,13 +1,13 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-module Game ( Tank(..)
- , Bullet(..)
+module Game ( Bullet(..)
, GameState(..)
, Game
, runGame
) where
import Level
+import Tank
import Texture
import Control.Monad
@@ -16,19 +16,6 @@ import Data.Fixed
import qualified Data.Map as M
-data Tank = Tank
- { tankX :: !Micro
- , tankY :: !Micro
- , tankDir :: !Micro
- , tankAim :: !Micro
- , tankSpeed :: !Micro
- , tankTurnspeed :: !Micro
- , tankMoving :: !Bool
- , tankBulletSpeed :: !Micro
- , tankBulletBounces :: !Int
- , tankBulletsLeft :: !Int
- } deriving Show
-
data Bullet = Bullet
{ bulletX :: !Micro
, bulletY :: !Micro
diff --git a/src/HTanks.hs b/src/HTanks.hs
index 03388db..c815992 100644
--- a/src/HTanks.hs
+++ b/src/HTanks.hs
@@ -8,6 +8,7 @@ import Player
import CPUPlayer
import DefaultPlayer
import Simulation
+import Tank
import GLDriver
import GLX
diff --git a/src/Level.hs b/src/Level.hs
index c99a4b5..152e15d 100644
--- a/src/Level.hs
+++ b/src/Level.hs
@@ -4,15 +4,19 @@ module Level ( Level(..)
import Data.List
+import Debris
+
data Level = Level
{ levelWidth :: !Int
, levelHeight :: !Int
+ , debris :: ![SomeDebris]
} deriving (Show)
testLevel :: Level
testLevel = Level
- { levelWidth = 10
- , levelHeight = 10
- } \ No newline at end of file
+ { levelWidth = 14
+ , levelHeight = 8
+ , debris = []
+ }
diff --git a/src/Player.hs b/src/Player.hs
index baf1cbe..59076dd 100644
--- a/src/Player.hs
+++ b/src/Player.hs
@@ -7,7 +7,7 @@ module Player ( Player(..)
import Data.Fixed
import Data.Typeable
-import Game (Tank(..))
+import Tank
import GLDriver (SomeEvent)
diff --git a/src/Render.hs b/src/Render.hs
index fddfbcb..e243580 100644
--- a/src/Render.hs
+++ b/src/Render.hs
@@ -6,6 +6,7 @@ module Render ( setup
import Paths_htanks
import Game
import Level
+import Tank
import Texture
import Control.Monad.State
@@ -89,13 +90,13 @@ render = do
texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat)
vertex $ Vertex2 0 lh
- texCoord $ TexCoord2 lw 0
+ texCoord $ TexCoord2 (lw/2) 0
vertex $ Vertex2 lw lh
- texCoord $ TexCoord2 lw lh
+ texCoord $ TexCoord2 (lw/2) (lh/2)
vertex $ Vertex2 lw 0
- texCoord $ TexCoord2 0 lh
+ texCoord $ TexCoord2 0 (lh/2)
vertex $ Vertex2 (0 :: GLfloat) (0 :: GLfloat)
forM_ tanklist $ \tank -> preservingMatrix $ do
diff --git a/src/Simulation.hs b/src/Simulation.hs
index 33465cc..65dc668 100644
--- a/src/Simulation.hs
+++ b/src/Simulation.hs
@@ -6,6 +6,7 @@ import Game
import Level
import MainLoop
import Player
+import Tank
import Control.Monad.State
import Data.Fixed
diff --git a/src/Tank.hs b/src/Tank.hs
new file mode 100644
index 0000000..21bc0da
--- /dev/null
+++ b/src/Tank.hs
@@ -0,0 +1,17 @@
+module Tank ( Tank(..)
+ ) where
+
+import Data.Fixed
+
+data Tank = Tank
+ { tankX :: !Micro
+ , tankY :: !Micro
+ , tankDir :: !Micro
+ , tankAim :: !Micro
+ , tankSpeed :: !Micro
+ , tankTurnspeed :: !Micro
+ , tankMoving :: !Bool
+ , tankBulletSpeed :: !Micro
+ , tankBulletBounces :: !Int
+ , tankBulletsLeft :: !Int
+ } deriving Show