Limit number of bullets/tank; save tank number with shoot

This commit is contained in:
Matthias Schiffer 2010-03-08 23:12:14 +01:00
parent 907cb95dae
commit e03de6bfe6
2 changed files with 23 additions and 18 deletions

View file

@ -26,6 +26,7 @@ data Tank = Tank
, moving :: !Bool
, tankShootSpeed :: !Micro
, tankShootBounces :: !Int
, shootsLeft :: !Int
} deriving Show
data Shoot = Shoot
@ -34,6 +35,7 @@ data Shoot = Shoot
, shootDir :: !Micro
, shootSpeed :: !Micro
, bouncesLeft :: !Int
, shootTank :: !Int
} deriving Show
data GameState = GameState

View file

@ -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
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