From 83f0606ea9dfd6b493097dc97330055dff4a2867 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 24 Jun 2011 21:50:32 +0200 Subject: Added Transformable class to simplify collision calculation --- src/Game.hs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/Game.hs') diff --git a/src/Game.hs b/src/Game.hs index 5af2ad2..16b04d8 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -1,26 +1,36 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} module Game ( Bullet(..) + , bulletX + , bulletY , GameState(..) ) where import Level import Tank - -import Control.Monad -import Control.Monad.State -import Data.Fixed +import Transformable +import Vector data Bullet = Bullet - { bulletX :: !Micro - , bulletY :: !Micro - , bulletDir :: !Micro - , bulletSpeed :: !Micro + { bulletPos :: !Vertex + , bulletDir :: !Vector + , bulletSpeed :: !Coord , bulletBouncesLeft :: !Int , bulletTank :: !Int } deriving (Eq, Show) +bulletX :: Bullet -> Coord +bulletX = vertexX . bulletPos + +bulletY :: Bullet -> Coord +bulletY = vertexY . bulletPos + +instance Transformable Bullet where + t >< b = b { bulletPos = pos, bulletDir = dir } where + pos = t >< bulletPos b + dir = t >< bulletDir b + data GameState = GameState { level :: !Level , tanks :: ![Tank] -- cgit v1.2.3