Added bullet/tank collision; reduced tick count
This commit is contained in:
parent
a1294859c7
commit
5c34cd6941
5 changed files with 41 additions and 11 deletions
|
@ -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
|
||||
|
|
Reference in a new issue