diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2010-03-08 23:12:14 +0100 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2010-03-08 23:12:14 +0100 |
commit | e03de6bfe6b90f8862e405c3797503ccd2722e1b (patch) | |
tree | 3c2f5361385d31f0c263f740478fbe3d18d7db19 | |
parent | 907cb95dae83a25dabf377228f4d70a1cab3216f (diff) | |
download | htanks-e03de6bfe6b90f8862e405c3797503ccd2722e1b.tar htanks-e03de6bfe6b90f8862e405c3797503ccd2722e1b.zip |
Limit number of bullets/tank; save tank number with shoot
-rw-r--r-- | Game.hs | 26 | ||||
-rw-r--r-- | HTanks.hs | 15 |
2 files changed, 23 insertions, 18 deletions
@@ -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 @@ -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 |