Public Sub Collision()
For X = 1 To MaxBullets
With Bullet(X)
'makes sure it is visible, has moved, and can move
If .Visible = True And .Moved = True And .Move = True Then
'Gets rid of bullets outside of the arena (move to collision
If .Left > ArenaWidth Then
BulletCollideEffects (X), ArenaWidth - .Width, .Top, plat(1), True
ElseIf .Left < 0 Then
BulletCollideEffects (X), 0, .Top, plat(1), True
ElseIf .Top < 0 Then
BulletCollideEffects (X), .Left, 0, plat(1), False
ElseIf .Top > ArenaHeight Then
BulletCollideEffects (X), .Left, ArenaHeight - .Height, plat(1), False
End If
If .Xinertia = 0 Then .Xinertia = 1 'prevent divide by 0
M = .Yinertia / .Xinertia 'find slope
If M = 0 Then M = 0.001 'prevent divide by 0
'y intercept for top left (b) and bottom right(bb)
B = (.Top - .Yinertia) - (M * (.Left - .Xinertia))
BB = ((.Top + .Height) - .Yinertia) - (M * ((.Left + .Width) - .Xinertia))
For Y = 1 To PlatCount
If plat(Y).Visible Then
'finds the point where it passes each side
Ty = plat(Y).Top
Tx = (B - Ty) / -M
Tbx = (BB - Ty) / -M
Hy = plat(Y).Top + plat(Y).Height
Hx = (B - Hy) / -M
Hbx = (BB - Hy) / -M
Lx = plat(Y).Left
Ly = M * Lx + B
Lby = M * Lx + BB
Wx = plat(Y).Left + plat(Y).Width
Wy = M * Wx + B
Wby = M * Wx + BB
'makes sure that it crosses the line inside the block
If Ly >= plat(Y).Top And Ly <= plat(Y).Top + plat(Y).Height And .Left >= Lx And .Left - .Xinertia <= Lx Then
BulletCollideEffects (X), Lx - .Width, (Ly), plat(Y), True
ElseIf Wy >= plat(Y).Top And Wy <= plat(Y).Top + plat(Y).Height And .Left <= Wx And .Left - .Xinertia >= Wx Then
BulletCollideEffects (X), (Wx), (Wy), plat(Y), True
ElseIf Lby >= plat(Y).Top And Lby <= plat(Y).Top + plat(Y).Height And .Left >= Lx And .Left - .Xinertia <= Lx Then
BulletCollideEffects (X), Lx - .Width, Lby - .Height, plat(Y), True
ElseIf Wby >= plat(Y).Top And Wby <= plat(Y).Top + plat(Y).Height And .Left <= Wx And .Left - .Xinertia >= Wx Then
BulletCollideEffects (X), (Wx), Wby - .Height, plat(Y), True
End If
If Tx >= plat(Y).Left And Tx <= plat(Y).Left + plat(Y).Width And .Top >= Ty And .Top - .Yinertia <= Ty Then
BulletCollideEffects (X), (Tx), Ty - .Height, plat(Y), False
ElseIf Hx >= plat(Y).Left And Hx <= plat(Y).Left + plat(Y).Width And .Top <= Hy And .Top - .Yinertia >= Hy Then
BulletCollideEffects (X), (Hx), (Hy), plat(Y), False
ElseIf Tbx >= plat(Y).Left And Tbx <= plat(Y).Left + plat(Y).Width And .Top >= Ty And .Top - .Yinertia <= Ty Then
BulletCollideEffects (X), Tbx - .Width, Ty - .Height, plat(Y), False
ElseIf Hbx >= plat(Y).Left And Hbx <= plat(Y).Left + plat(Y).Width And .Top <= Hy And .Top - .Yinertia >= Hy Then
BulletCollideEffects (X), Hbx - .Width, (Hy), plat(Y), False
End If
End If
Next Y
For Y = 1 To PlayerCount
If player(Y).Visible Then
'finds the point where it passes each side
Ty = player(Y).Top
Tx = (B - Ty) / -M
Tbx = (BB - Ty) / -M
Hy = player(Y).Top + player(Y).Height
Hx = (B - Hy) / -M
Hbx = (BB - Hy) / -M
Lx = player(Y).Left
Ly = M * Lx + B
Lby = M * Lx + BB
Wx = player(Y).Left + player(Y).Width
Wy = M * Wx + B
Wby = M * Wx + BB
'makes sure that it crosses the line inside the block
If Ly >= player(Y).Top And Ly <= player(Y).Top + player(Y).Height And .Left >= Lx And .Left - .Xinertia <= Lx Then
BulletCollideEffects (X), Lx - .Width, (Ly), player(Y), True
ElseIf Wy >= player(Y).Top And Wy <= player(Y).Top + player(Y).Height And .Left <= Wx And .Left - .Xinertia >= Wx Then
BulletCollideEffects (X), (Wx), (Wy), player(Y), True
ElseIf Lby >= player(Y).Top And Lby <= player(Y).Top + player(Y).Height And .Left >= Lx And .Left - .Xinertia <= Lx Then
BulletCollideEffects (X), Lx - .Width, Lby - .Height, player(Y), True
ElseIf Wby >= player(Y).Top And Wby <= player(Y).Top + player(Y).Height And .Left <= Wx And .Left - .Xinertia >= Wx Then
BulletCollideEffects (X), (Wx), Wby - .Height, player(Y), True
End If
If Tx >= player(Y).Left And Tx <= player(Y).Left + player(Y).Width And .Top >= Ty And .Top - .Yinertia <= Ty Then
BulletCollideEffects (X), (Tx), Ty - .Height, player(Y), False
ElseIf Hx >= player(Y).Left And Hx <= player(Y).Left + player(Y).Width And .Top <= Hy And .Top - .Yinertia >= Hy Then
BulletCollideEffects (X), (Hx), (Hy), player(Y), False
ElseIf Tbx >= player(Y).Left And Tbx <= player(Y).Left + player(Y).Width And .Top >= Ty And .Top - .Yinertia <= Ty Then
BulletCollideEffects (X), Tbx - .Width, Ty - .Height, player(Y), False
ElseIf Hbx >= player(Y).Left And Hbx <= player(Y).Left + player(Y).Width And .Top <= Hy And .Top - .Yinertia >= Hy Then
BulletCollideEffects (X), Hbx - .Width, (Hy), player(Y), False
End If
End If
Next Y
End If
If Bullet(X).Type = 1 Then
For Y = 1 To PlayerCount
If collide(Bullet(X), player(Y)) = True And Bullet(X).Belong <> (Y) And Bullet(X).Visible = True Then
player(Y).Xinertia = Bullet(X).Xinertia
player(Y).Yinertia = Bullet(X).Yinertia
player(Y).Life = player(Y).Life - GT(1).Power
End If
Next Y
End If
If .Visible And .Kiboshed Then
For Y = 1 To PlayerCount
If player(Y).OnFire = False And player(Y).Visible And collide(player(Y), Bullet(X)) And GT(.Type).Explode Then
CenterX = .Left + (.Width / 2)
CenterY = .Top + (.Height / 2)
CenterX2 = player(Y).Left + (player(Y).Width / 2)
CenterY2 = player(Y).Top + (player(Y).Height / 2)
'absolute of cursor position
XXX = Abs(CenterX2 - CenterX)
YYY = Abs(CenterY - CenterY2)
'Makes sure you do not divide by 0
If XXX = 0 Then
Angle = 0
Else
'find angle
Angle = Atn(YYY / XXX)
End If
'finds absolute x and y aim
XXX = RR * Cos(Angle)
YYY = RR * Sin(Angle)
'Sets result aiming co-ordinates
player(Y).Xinertia = Sgn(CenterX2 - CenterX) * XXX / 20
player(Y).Yinertia = (Sgn(CenterY2 - CenterY) * YYY) / 20
'other effects
player(Y).OnFire = True
player(Y).Firetime = 40
player(Y).Life = player(Y).Life - 10
End If
Next Y
End If
End With
Next X