From 736ad91b328c23287b6065f6dc8f75c424d84b8b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 18 Mar 2010 09:22:21 +0100 Subject: Hit tanks will die now. --- src/Simulation.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/Simulation.hs') diff --git a/src/Simulation.hs b/src/Simulation.hs index c9810b3..5d2b47b 100644 --- a/src/Simulation.hs +++ b/src/Simulation.hs @@ -126,8 +126,9 @@ simulationStep = do leftbullets = collideBullets $ zipWith (\(left, bullet') bullet -> (left, bullet, bullet')) thebullets $ bullets state bt = hitBullets $ liftM2 (\(b, (_, b')) (t, t') -> (b, b', t, t')) (zip (bullets state) leftbullets) (zip (tanks state) newtanks) leftbullets2 = map (\(left, bullet) -> (left && (all (\(c, b, _) -> (b /= bullet) || (not c)) bt), bullet)) leftbullets + newtanks2 = map (\tank -> tank {tankLife = (tankLife tank) - (sum . map (\(c, _, t) -> if (t == tank && c) then 1 else 0) $ bt)}) newtanks - thetanks = map (\(tank, n) -> tank {tankBulletsLeft = (tankBulletsLeft tank) + (countLostTankBullets n leftbullets2)}) $ zip newtanks [0..] + thetanks = map (\(tank, n) -> tank {tankBulletsLeft = (tankBulletsLeft tank) + (countLostTankBullets n leftbullets2)}) $ zip newtanks2 [0..] in state {tanks = thetanks, bullets = newbullets ++ (map snd . filter fst $ leftbullets2)} @@ -146,6 +147,6 @@ simulationStep = do updateTank' game (player, tank) = let (p, angle, move, aangle, shoot) = playerUpdate player tank t = execState (updateTank game angle move aangle) tank - in (p, t, shoot) + in if (tankLife tank > 0) then (p, t, shoot) else (player, tank, False) countLostTankBullets n (x:xs) = (if ((not . fst $ x) && (n == (bulletTank . snd $ x))) then 1 else 0) + (countLostTankBullets n xs) countLostTankBullets n [] = 0 -- cgit v1.2.3