summaryrefslogtreecommitdiffstats
path: root/src/Simulation.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Simulation.hs')
-rw-r--r--src/Simulation.hs20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/Simulation.hs b/src/Simulation.hs
index 3cf4fec..ca335f2 100644
--- a/src/Simulation.hs
+++ b/src/Simulation.hs
@@ -16,8 +16,8 @@ import Data.Maybe
import Data.VectorSpace
-updateAngle :: Vector -> Tank -> Tank
-updateAngle dir tank = tank {tankDir = rotate newangle >< Vector 1 0}
+updateAngle :: Rotation -> Tank -> Tank
+updateAngle dir tank = tank { tankDir = fromAngle newangle }
where
oldangle = toAngle . tankDir $ tank
angle = toAngle dir
@@ -44,12 +44,14 @@ updateAngle dir tank = tank {tankDir = rotate newangle >< Vector 1 0}
newangle = angle180 + turn
-approx :: Vector -> Vector -> Bool
-approx (Vector x1 y1) (Vector x2 y2) = x1 `approx'` x2 && y1 `approx'` y2
+approx :: Rotation -> Rotation -> Bool
+approx r1 r2 = c1 `approx'` c2 && s1 `approx'` s2
where
approx' a b = (abs (a-b)) < 0.000001
+ Vector c1 s1 = toVector r1
+ Vector c2 s2 = toVector r2
-updateTank :: GameState -> Maybe Vector -> Bool -> Maybe Vector -> State Tank ()
+updateTank :: GameState -> Maybe Rotation -> Bool -> Maybe Rotation -> State Tank ()
updateTank game dir move aim = do
when (isJust dir) $
modify $ updateAngle $ fromJust dir
@@ -64,7 +66,7 @@ updateTank game dir move aim = do
moved = tankMoving tank
when (isNothing dir || (isJust dir && (tdir `approx` fromJust dir) || moved)) $
- put $ translateV (tdir ^* (tspeed/100)) >< tank {tankMoving = True}
+ put $ ((toVector tdir) ^* (tspeed/100)) >< tank {tankMoving = True}
when (not move) $ do
modify $ \tank -> tank {tankMoving = False}
@@ -75,11 +77,11 @@ updateTank game dir move aim = do
updateBullet :: GameState -> Bullet -> (Bullet, Bool)
-updateBullet game bullet = (bullet {bulletPos = Vertex x' y', bulletDir = Vector dx' dy', bulletBouncesLeft = bounces3}, bounces3 >= 0)
+updateBullet game bullet = (bullet {bulletPos = Vertex x' y', bulletDir = fromVector $ Vector dx' dy', bulletBouncesLeft = bounces3}, bounces3 >= 0)
where
speed = bulletSpeed bullet
- d@(Vector dx dy) = bulletDir bullet
- Vertex x y = translateV (d ^* (speed/100)) >< bulletPos bullet
+ d@(Vector dx dy) = toVector $ bulletDir bullet
+ Vertex x y = (d ^* (speed/100)) >< bulletPos bullet
bounces = bulletBouncesLeft bullet
lw = fromIntegral . levelWidth . level $ game
lh = fromIntegral . levelHeight . level $ game