Hit tanks will die now.
This commit is contained in:
parent
5c34cd6941
commit
736ad91b32
3 changed files with 7 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -14,4 +14,5 @@ data Tank = Tank
|
|||
, tankBulletSpeed :: !Micro
|
||||
, tankBulletBounces :: !Int
|
||||
, tankBulletsLeft :: !Int
|
||||
} deriving Show
|
||||
, tankLife :: !Int
|
||||
} deriving (Eq, Show)
|
||||
|
|
Reference in a new issue