summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2010-03-08 23:12:14 +0100
committerMatthias Schiffer <matthias@gamezock.de>2010-03-08 23:12:14 +0100
commite03de6bfe6b90f8862e405c3797503ccd2722e1b (patch)
tree3c2f5361385d31f0c263f740478fbe3d18d7db19
parent907cb95dae83a25dabf377228f4d70a1cab3216f (diff)
downloadhtanks-e03de6bfe6b90f8862e405c3797503ccd2722e1b.tar
htanks-e03de6bfe6b90f8862e405c3797503ccd2722e1b.zip
Limit number of bullets/tank; save tank number with shoot
-rw-r--r--Game.hs26
-rw-r--r--HTanks.hs15
2 files changed, 23 insertions, 18 deletions
diff --git a/Game.hs b/Game.hs
index c782465..1f85376 100644
--- a/Game.hs
+++ b/Game.hs
@@ -17,23 +17,25 @@ import qualified Data.Map as M
data Tank = Tank
- { posx :: !Micro
- , posy :: !Micro
- , dir :: !Micro
- , aim :: !Micro
- , speed :: !Micro
- , turnspeed :: !Micro
- , moving :: !Bool
- , tankShootSpeed :: !Micro
+ { posx :: !Micro
+ , posy :: !Micro
+ , dir :: !Micro
+ , aim :: !Micro
+ , speed :: !Micro
+ , turnspeed :: !Micro
+ , moving :: !Bool
+ , tankShootSpeed :: !Micro
, tankShootBounces :: !Int
+ , shootsLeft :: !Int
} deriving Show
data Shoot = Shoot
- { shootX :: !Micro
- , shootY :: !Micro
- , shootDir :: !Micro
- , shootSpeed :: !Micro
+ { shootX :: !Micro
+ , shootY :: !Micro
+ , shootDir :: !Micro
+ , shootSpeed :: !Micro
, bouncesLeft :: !Int
+ , shootTank :: !Int
} deriving Show
data GameState = GameState
diff --git a/HTanks.hs b/HTanks.hs
index ace90d3..1937693 100644
--- a/HTanks.hs
+++ b/HTanks.hs
@@ -47,8 +47,8 @@ main = do
[ SomePlayer $ DefaultPlayer S.empty 0 0 False
, SomePlayer $ CPUPlayer 0
]}
- gameState = GameState {level = theLevel, tanks = [ Tank 5.0 5.0 0 0 2 270 False 3 2
- , Tank 5.0 3.5 0 0 2 270 False 3 2
+ gameState = GameState {level = theLevel, tanks = [ Tank 5.0 5.0 0 0 2 270 False 3 2 5
+ , Tank 5.0 3.5 0 0 2 270 False 3 2 5
], shoots = [], textures = M.empty}
runGame gameState $ do
@@ -161,18 +161,21 @@ simulationStep = do
oldtanks <- lift $ gets tanks
let (p, t, s) = unzip3 $ map updateTank' $ zip oldplayers oldtanks
- shootingtanks = map fst $ filter snd $ zip t s
- newshoots = map (\tank -> Shoot
- {shootX = posx tank
+ ts = zip3 t s [0..]
+ shootingtanks = map (\(tank, _, n) -> (tank, n)) $ filter (\(tank, shoot, _) -> shoot && (shootsLeft tank) > 0) $ ts
+ newtanks = map (\(tank, shoot, _) -> if shoot then tank {shootsLeft = (shootsLeft tank) - 1} else tank) $ ts
+ newshoots = map (\(tank, n) -> Shoot
+ { shootX = posx tank
, shootY = posy tank
, shootDir = aim tank
, shootSpeed = tankShootSpeed tank
, bouncesLeft = tankShootBounces tank
+ , shootTank = n
}) shootingtanks
modify $ \state -> state {players = p}
- lift $ modify $ \state -> state {tanks = t, shoots = map (execState updateShoot) (shoots state ++ newshoots)}
+ lift $ modify $ \state -> state {tanks = newtanks, shoots = map (execState updateShoot) (shoots state ++ newshoots)}
where
updateTank' (player, tank) = let (p, angle, move, aangle, shoot) = playerUpdate player tank
t = execState (updateTank angle move aangle) tank