summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/HTanks.hs4
-rw-r--r--src/Simulation.hs5
-rw-r--r--src/Tank.hs3
3 files changed, 7 insertions, 5 deletions
diff --git a/src/HTanks.hs b/src/HTanks.hs
index 63e647d..c7cf8a8 100644
--- a/src/HTanks.hs
+++ b/src/HTanks.hs
@@ -32,8 +32,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 1 5
- , Tank 5.0 3.5 0 0 2 270 False 3 1 5
+ gameState = GameState {level = theLevel, tanks = [ Tank 5.0 5.0 0 0 2 270 False 3 1 5 1
+ , Tank 5.0 3.5 0 0 2 270 False 3 1 5 1
], bullets = [], textures = M.empty}
runGame gameState $ do
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
diff --git a/src/Tank.hs b/src/Tank.hs
index 21bc0da..2fbf612 100644
--- a/src/Tank.hs
+++ b/src/Tank.hs
@@ -14,4 +14,5 @@ data Tank = Tank
, tankBulletSpeed :: !Micro
, tankBulletBounces :: !Int
, tankBulletsLeft :: !Int
- } deriving Show
+ , tankLife :: !Int
+ } deriving (Eq, Show)