From 5c34cd694117421e570b3a6cc3bb813e17e50b33 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 18 Mar 2010 09:14:32 +0100 Subject: Added bullet/tank collision; reduced tick count --- src/Collision.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/Collision.hs') diff --git a/src/Collision.hs b/src/Collision.hs index 9ad898b..a69dc10 100644 --- a/src/Collision.hs +++ b/src/Collision.hs @@ -1,5 +1,6 @@ module Collision ( collisionTankBorder , collisionBulletBullet + , collisionBulletTank ) where import Tank @@ -49,3 +50,23 @@ collisionBulletBullet :: (Bullet, Bullet) -> (Bullet, Bullet) -> Bool collisionBulletBullet (b1, b1') (b2, b2') = distancesq < (bulletDiameter^2) where distancesq = (bulletX b1' - bulletX b2')^2 + (bulletY b1' - bulletY b2')^2 + +collisionBulletTank :: (Bullet, Bullet) -> (Tank, Tank) -> Bool +collisionBulletTank (b, b') (tank, tank') = (not ((between bx minx maxx) && (between by miny maxy))) && ((between bx' minx maxx) && (between by' miny maxy)) + where + between x a b = x >= a && x <= b + + dir t = (fromRational . toRational . tankDir $ t)*pi/180 + cosd t = fromRational (round ((cos $ dir t)*1000000)%1000000) + sind t = fromRational (round ((sin $ dir t)*1000000)%1000000) + + rotp t (x, y) = ((cosd t)*x + (sind t)*y, -(sind t)*x + (cosd t)*y) + transp t (x, y) = (x - tankX t, y - tankY t) + + (bx, by) = (rotp tank) . (transp tank) $ (bulletX b, bulletY b) + (bx', by') = (rotp tank') . (transp tank') $ (bulletX b', bulletY b') + + minx = -tankLength/2 + maxx = tankLength/2 + miny = -tankWidth/2 + maxy = tankWidth/2 -- cgit v1.2.3