diff options
Diffstat (limited to 'src/Simulation.hs')
-rw-r--r-- | src/Simulation.hs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/Simulation.hs b/src/Simulation.hs index 5d2b47b..7b2505f 100644 --- a/src/Simulation.hs +++ b/src/Simulation.hs @@ -93,7 +93,8 @@ updateBullet game = do dir = bulletDir bullet bounces = bulletBouncesLeft bullet - (newx, dir2, bounces2) = if x < 0 then (-x, (signum dir)*180 - dir, bounces-1) else if x > lw then (2*lw-x, (signum dir)*180 - dir, bounces-1) else (x, dir, bounces) + sg = if dir < 0 then -1 else 1 + (newx, dir2, bounces2) = if x < 0 then (-x, sg*180 - dir, bounces-1) else if x > lw then (2*lw-x, sg*180 - dir, bounces-1) else (x, dir, bounces) (newy, dir3, bounces3) = if y < 0 then (-y, -dir2, bounces2-1) else if y > lh then (2*lh-y, -dir2, bounces2-1) else (y, dir2, bounces2) put bullet {bulletX = newx, bulletY = newy, bulletDir = dir3, bulletBouncesLeft = bounces3} @@ -107,8 +108,8 @@ simulationStep = do game <- lift get let oldtanks = tanks game - let (p, t, s) = unzip3 $ map (updateTank' game) $ zip oldplayers oldtanks - ts = zip3 t s [0..] + (p, t, s) <- liftIO $ liftM unzip3 $ mapM (updateTank' game) $ zip oldplayers oldtanks + let ts = zip3 t s [0..] shootingtanks = map (\(tank, _, n) -> (tank, n)) $ filter (\(tank, shoot, _) -> shoot && (tankBulletsLeft tank) > 0) $ ts newtanks = map (\(tank, shoot, _) -> if (shoot && (tankBulletsLeft tank) > 0) then tank {tankBulletsLeft = (tankBulletsLeft tank) - 1} else tank) $ ts newbullets = map (\(tank, n) -> Bullet @@ -145,8 +146,9 @@ simulationStep = do hitBullets [] = [] hitBullets ((b, b', t, t'):xs) = (collisionBulletTank (b, b') (t, t'), b', t'):(hitBullets xs) - updateTank' game (player, tank) = let (p, angle, move, aangle, shoot) = playerUpdate player tank - t = execState (updateTank game angle move aangle) tank - in if (tankLife tank > 0) then (p, t, shoot) else (player, tank, False) + updateTank' game (player, tank) = do + (p, angle, move, aangle, shoot) <- playerUpdate player tank + let t = execState (updateTank game angle move aangle) tank + return $ 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 |