diff options
Diffstat (limited to 'src/Simulation.hs')
-rw-r--r-- | src/Simulation.hs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/Simulation.hs b/src/Simulation.hs index 7b2505f..c092ad5 100644 --- a/src/Simulation.hs +++ b/src/Simulation.hs @@ -105,7 +105,7 @@ updateBullet game = do simulationStep :: Main () simulationStep = do oldplayers <- gets players - game <- lift get + game <- gets gameState let oldtanks = tanks game (p, t, s) <- liftIO $ liftM unzip3 $ mapM (updateTank' game) $ zip oldplayers oldtanks @@ -121,17 +121,16 @@ simulationStep = do , bulletTank = n }) shootingtanks - modify $ \state -> state {players = p} - lift $ modify $ \state -> - let thebullets = map (runState $ updateBullet state) $ bullets state - 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) + modify $ \state -> + let thebullets = map (runState $ updateBullet . gameState $ state) $ bullets $ gameState state + leftbullets = collideBullets $ zipWith (\(left, bullet') bullet -> (left, bullet, bullet')) thebullets $ bullets $ gameState state + bt = hitBullets $ liftM2 (\(b, (_, b')) (t, t') -> (b, b', t, t')) (zip (bullets $ gameState state) leftbullets) (zip (tanks $ gameState 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 newtanks2 [0..] - in state {tanks = thetanks, bullets = newbullets ++ (map snd . filter fst $ leftbullets2)} + in state {players = p, gameState = (gameState state) {tanks = thetanks, bullets = newbullets ++ (map snd . filter fst $ leftbullets2)}} where collideBullets [] = [] |