Shooting is possible now
This commit is contained in:
parent
335c10654f
commit
907cb95dae
1 changed files with 13 additions and 4 deletions
17
HTanks.hs
17
HTanks.hs
|
@ -160,14 +160,23 @@ simulationStep = do
|
|||
oldplayers <- gets players
|
||||
oldtanks <- lift $ gets tanks
|
||||
|
||||
let pt = unzip $ map updateTank' $ zip oldplayers oldtanks
|
||||
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
|
||||
, shootY = posy tank
|
||||
, shootDir = aim tank
|
||||
, shootSpeed = tankShootSpeed tank
|
||||
, bouncesLeft = tankShootBounces tank
|
||||
}) shootingtanks
|
||||
|
||||
modify $ \state -> state {players = fst pt}
|
||||
lift $ modify $ \state -> state {tanks = snd pt, shoots = map (execState updateShoot) $ shoots state}
|
||||
|
||||
modify $ \state -> state {players = p}
|
||||
lift $ modify $ \state -> state {tanks = t, 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
|
||||
in (p, t)
|
||||
in (p, t, shoot)
|
||||
|
||||
|
||||
handleEvents :: Main ()
|
||||
|
|
Reference in a new issue