summaryrefslogtreecommitdiffstats
path: root/HTanks.hs
diff options
context:
space:
mode:
Diffstat (limited to 'HTanks.hs')
-rw-r--r--HTanks.hs15
1 files changed, 9 insertions, 6 deletions
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