Any help to stop this would be greatly appreciated.
Here is my code
Expand|Select|Wrap|Line Numbers
- Dim Player1angle As Single
- Dim Player1ratio As Double 'Y/X or (y2-y1)/(x2-x1)
- Dim P1Xhigher As String
- Dim P1YHigher As String
- Dim P1X As Double
- Dim P1Y As Double
- Dim Player2angle As Double
- Const Pi As Single = 3.14159
- Const Rad As Single = Pi / 180
- Private Const D_THETA = 3.14159265 / 12
- Private Theta As Single
- Private R1 As Single
- Private R2 As Single
- Private Cx1 As Single
- Private Cy1 As Single
- Dim TmeToEnd As Boolean
- Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
- Dim Keys(255) As Boolean
- Private Sub StartButton_Click()
- Player1Controls.Visible = False
- Player2Controls.Visible = False
- Title.Visible = False
- StartButton.Visible = False
- Timer1.Enabled = True
- Call Main
- End Sub
- Private Sub Timer1_Timer()
- 'Player1.Y1 = Player1.Y1 + 10
- 'Player1.Y2 = Player1.Y2 + 10
- Player2.Y1 = Player2.Y1 + 10
- Player2.Y2 = Player2.Y2 + 10
- If P2Bullet.Visible = True Then
- End If
- End Sub
- Public Function ArcTan(x As Double) As Double
- 'Inverse Tangent
- On Error Resume Next
- ArcTan = Atn(x) '* (180 / Pi)
- On Error GoTo 0
- End Function
- Public Function DegToRad(Degrees As Single) As Single
- 'DegToRad = Degrees / 180 * Pi
- DegToRad = Degrees * Rad
- End Function
- Public Function RadToDeg(Radians As Single) As Single
- 'RadToDeg = Radians * 180 / Pi
- RadToDeg = Radians / Rad
- End Function
- Public Sub Main()
- Do
- 'Show and refresh the form
- Me.Refresh
- If Keys(vbKeyUp) Then
- dx = Player1.X2 - Player1.X1
- dy = Player1.Y2 - Player1.Y1
- R1 = Sqr(dx * dx + dy * dy) + 100
- P1Y = (dy / R1)
- P1X = (dx / R1)
- Player1.X1 = Player1.X1 - (5 * P1X)
- Player1.X2 = Player1.X2 - (5 * P1X)
- Player1.Y1 = Player1.Y1 - (5 * P1Y)
- Player1.Y2 = Player1.Y2 - (5 * P1Y)
- End If
- If Keys(vbKeyDown) Then
- dx = Player1.X2 - Player1.X1
- dy = Player1.Y2 - Player1.Y1
- R1 = Sqr(dx * dx + dy * dy) + 100
- Cx1 = Player1.X1
- Cy1 = Player1.Y1
- P1Y = (dy / R1)
- P1X = (dx / R1)
- Player1.X1 = Player1.X1 + (5 * P1X)
- Player1.X2 = Player1.X2 + (5 * P1X)
- Player1.Y1 = Player1.Y1 + (5 * P1Y)
- Player1.Y2 = Player1.Y2 + (5 * P1Y)
- End If
- If Keys(vbKeyLeft) Then
- dx = Player1.X2 - Player1.X1
- dy = Player1.Y2 - Player1.Y1
- R1 = Sqr(dx * dx + dy * dy)
- Cx1 = Player1.X1
- Cy1 = Player1.Y1
- Theta = Theta - (D_THETA / 100)
- Player1.X2 = Cx1 + Cos(Theta) * R1
- Player1.Y2 = Cy1 + Sin(Theta) * R1
- End If
- If Keys(vbKeyRight) Then
- dx = Player1.X2 - Player1.X1
- dy = Player1.Y2 - Player1.Y1
- R1 = Sqr(dx * dx + dy * dy)
- Cx1 = Player1.X1
- Cy1 = Player1.Y1
- Theta = Theta + (D_THETA / 100)
- Player1.X2 = Cx1 + Cos(Theta) * R1
- Player1.Y2 = Cy1 + Sin(Theta) * R1
- End If
- If P1Bullet.Visible = True Then
- dx = P1Bullet.X2 - P1Bullet.X1
- dy = P1Bullet.Y2 - P1Bullet.Y1
- R1 = Sqr(dx * dx + dy * dy) + 100
- Cx1 = Player1.X1
- Cy1 = Player1.Y1
- P1Y = (dy / R1)
- P1X = (dx / R1)
- P1Bullet.X1 = P1Bullet.X1 + (5 * P1X)
- P1Bullet.X2 = P1Bullet.X2 + (5 * P1X)
- P1Bullet.Y1 = P1Bullet.Y1 + (5 * P1Y)
- P1Bullet.Y2 = P1Bullet.Y2 + (5 * P1Y)
- End If
- DoEvents
- Loop Until TmeToEnd
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- 'Mark the program to end
- TimeToEnd = True
- End Sub
- Private Sub Form_KeyDown(KeyCode As Integer, Shift As _
- Integer)
- 'The key KeyCode is pressed now...
- Keys(KeyCode) = True
- End Sub
- Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
- 'The key KeyCode is NOT pressed now...
- Keys(KeyCode) = False
- End Sub