'These four sub routines get the x and y and the total pylons from DrawTrack and kick out a wall in a for loop
Sub DrawHorizontalWall
For i = 1 To TotalPylons
GraphicsWindow.FillRectangle((PylonX1 - PylonSpace) + PylonStep, PylonY1, PylonSize, PylonSize)
PylonStep = PylonStep + PylonSpace
EndFor
PylonStep = PylonSpace
EndSub
Sub DrawVerticalWall
For i = 1 To TotalPylons
GraphicsWindow.FillRectangle(PylonX1, (PylonY1 - PylonSpace) + PylonStep, PylonSize, PylonSize)
PylonStep = PylonStep + PylonSpace
EndFor
PylonStep = PylonSpace
EndSub
Sub DrawForwardAngle
For i = 1 To TotalPylons
GraphicsWindow.FillRectangle(PylonX1 + PylonStep, PylonY1 - PylonStep, PylonSize, PylonSize)
PylonStep = PylonStep + PylonSpace
EndFor
PylonStep = PylonSpace
EndSub
Sub DrawBackAngle
For i = 1 To TotalPylons
GraphicsWindow.FillRectangle(PylonX1 + PylonStep, PylonY1 + PylonStep, PylonSize, PylonSize)
PylonStep = PylonStep + PylonSpace
EndFor
PylonStep = PylonSpace
EndSub
'These three sub routines save all the info from DrawTrack so I can do a collision
Sub HorizontalWallPosition
For i = 1 To 1
WallPositionH[PositionNumber]["WallX1"] = PylonX1
WallPositionH[PositionNumber]["WallX2"] = PylonX1 + PylonSpace * TotalPylons
WallPositionH[PositionNumber]["WallY1"] = PylonY1
WallPositionH[PositionNumber]["WallY2"] = PylonY1 + PylonSize
EndFor
EndSub
Sub VerticalWallPosition
For i = 1 To 1
WallPositionV[PositionNumber]["WallX1"] = PylonX1
WallPositionV[PositionNumber]["WallX2"] = PylonX1 + PylonSize
WallPositionV[PositionNumber]["WallY1"] = PylonY1
WallPositionV[PositionNumber]["WallY2"] = PylonY1 + PylonSpace * TotalPylons
EndFor
EndSub
Sub AngleWallPosition
For i = 1 To TotalPylons
If (i = 1) Then
WallPositionA[PositionNumber][0]["Dim2Total"] = TotalPylons
WallPositionA[PositionNumber][0]["AngleNumber"] = AngleNumber
If (ForwardAngle) Then
WallPositionA[PositionNumber][0]["ForwardAngle"] = ForwardAngle
ElseIf (BackAngle) Then
WallPositionA[PositionNumber][0]["BackAngle"] = BackAngle
EndIf
EndIf
WallPositionA[PositionNumber][i]["WallX1"] = PylonX1 + PylonSpace * i
WallPositionA[PositionNumber][i]["WallX2"] = PylonX1 + PylonSize + PylonSpace * i
If (ForwardAngle) Then
WallPositionA[PositionNumber][i]["WallY1"] = PylonY1 - PylonSpace * i
WallPositionA[PositionNumber][i]["WallY2"] = PylonY1 + PylonSize - PylonSpace * i
Else
WallPositionA[PositionNumber][i]["WallY1"] = PylonY1 + PylonSpace * i
WallPositionA[PositionNumber][i]["WallY2"] = PylonY1 + PylonSize + PylonSpace * i
EndIf
EndFor
ForwardAngle = "False"
BackAngle = "False"
EndSub
'These 3 sub routines check to see if the car x and y and the wall x and y match. all the wall info is from the 3 different wall position arrays and is accessed through a loop
Sub CollisionHorizontal
For i = 1 To ArraySizeH
If (CarY <= WallPositionH[i]["WallY2"] And CarY >= WallPositionH[i]["WallY1"] And CarX + CarSize >= WallPositionH[i]["WallX1"] And CarX + CarSize <= WallPositionH[i]["WallX2"]) Then
CH = "True"
ElseIf (CarY <= WallPositionH[i]["WallY2"] And CarY >= WallPositionH[i]["WallY1"] And CarX >= WallPositionH[i]["WallX1"] And CarX <= WallPositionH[i]["WallX2"]) Then
CH = "True"
ElseIf (CarY + CarSize <= WallPositionH[i]["WallY2"] And CarY + CarSize >= WallPositionH[i]["WallY1"] And CarX + CarSize >= WallPositionH[i]["WallX1"] And CarX + CarSize <= WallPositionH[i]["WallX2"]) Then
CH = "True"
ElseIf (CarY + CarSize <= WallPositionH[i]["WallY2"] And CarY + CarSize >= WallPositionH[i]["WallY1"] And CarX >= WallPositionH[i]["WallX1"] And CarX <= WallPositionH[i]["WallX2"]) Then
CH = "True"
EndIf
EndFor
EndSub
Sub CollisionVertical
For i = 1 To ArraySizeV
If (CarX <= WallPositionV[i]["WallX2"] And CarX >= WallPositionV[i]["WallX1"] And CarY >= WallPositionV[i]["WallY1"] And CarY + CarSize <= WallPositionV[i]["WallY2"]) Then
CV = "True"
ElseIf (CarX + CarSize >= WallPositionV[i]["WallX1"] And CarX + CarSize <= WallPositionV[i]["WallX2"] And CarY + CarSize >= WallPositionV[i]["WallY1"] And CarY + CarSize <= WallPositionV[i]["WallY2"]) Then
CV = "True"
ElseIf (CarX >= WallPositionV[i]["WallX1"] And CarX <= WallPositionV[i]["WallX2"] And CarY + CarSize >= WallPositionV[i]["WallY1"] And CarY + CarSize <= WallPositionV[i]["WallY2"]) Then
CV = "True"
EndIf
EndFor
EndSub
Sub CollisionAngle
For i = 1 To ArraySizeA
For ii = 1 To WallPositionA[i][0]["Dim2Total"]
If (WallPositionA[i][0]["AngleNumber"] = 1 And WallPositionA[i][0]["ForwardAngle"]) Then
If (CarX >= WallPositionA[i][ii]["WallX1"] - CarSize And CarX <= WallPositionA[i][ii]["WallX2"] And CarY >= WallPositionA[i][ii]["WallY1"] - CarSize And CarY + CarSize <= WallPositionA[i][ii]["WallY2"] + CarSize) Then
CA = "True"
EndIf
ElseIf (WallPositionA[i][0]["AngleNumber"] = 1 And WallPositionA[i][0]["BackAngle"]) Then
If (CarX >= WallPositionA[i][ii]["WallX1"] - CarSize And CarX <= WallPositionA[i][ii]["WallX2"] And CarY >= WallPositionA[i][ii]["WallY1"] - CarSize And CarY <= WallPositionA[i][ii]["WallY2"] + CarSize) Then
CA = "True"
EndIf
ElseIf (WallPositionA[i][0]["AngleNumber"] = 2) Then
If (CarX + CarSize >= WallPositionA[i][ii]["WallX1"] And CarX + CarSize <= WallPositionA[i][ii]["WallX2"] + CarSize And CarY >= WallPositionA[i][ii]["WallY1"] - CarSize And CarY + CarSize <= WallPositionA[i][ii]["WallY2"] + CarSize) Then
CA = "True"
EndIf
EndIf
EndFor
EndFor
EndSub
'CollisionCheck runs through 3 different wall type sub routines to check for collision and, if so, sets CarSpeed to 1
Sub CollisionCheck
CollisionHorizontal()
CollisionVertical()
CollisionAngle()
If (CH Or CV Or CA) Then
CarSpeed = 1
Gear = 0
UpShift2 = "False"
UpShift3 = "False"
UpShift4 = "False"
Shapes.HideShape(ShiftMessage)
Shapes.HideShape(Gear1Message)
Shapes.HideShape(Gear2Message)
Shapes.HideShape(Gear3Message)
Shapes.HideShape(Gear4Message)
EndIf
EndSub
'This resets all the collisions after hitting a wall
Sub ResetCollision
CH = "False"
CV = "False"
CA = "False"
EndSub
'Main loop
Sub RunGame
GraphicsWindow.Show()
GraphicsWindow.KeyDown = OnKeyDown
GraphicsWindow.KeyUp = OnKeyUp
While GameRunning
Program.Delay(1000/Fps)
DriveCar()
If (Gear <> 0) Then
ChangeGear()
EndIf
CollisionCheck()
ResetCollision()
EndWhile
EndSub
'These 2 sub routines give a boolean value to GraphicsWindow.KeyDown and Up for whether the car is moving or not
Sub OnKeyDown
CarMove = "True"
EndSub
Sub OnKeyUp
CarMove = "False"
EndSub
'This steers and accelerates the car. It changes gears, too.
Sub DriveCar
LastCarAngle[rem] = CarAngle ' nonkit
rem = rem + 1 ' nonkit
If delay <= rem Then ' nonkit
rem = 0 ' nonkit
EndIf ' nonkit
If (CarMove) Then
'This Sets the angle for steering
If(GraphicsWindow.LastKey = LeftKey) Then
CarAngle = Math.Remainder(CarAngle - 5, 360)
ElseIf (GraphicsWindow.LastKey = RightKey) Then
CarAngle = Math.Remainder(CarAngle + 5, 360)
EndIf
'This sets the gears. The way it works, you have to wait for it to hit the max speed for each gear 1-4, and you can't skip gears.
If (GraphicsWindow.LastKey = AKey) Then
Gear = 1
GearDelay = 100
ElseIf (GraphicsWindow.LastKey = ZKey) Then
If (UpShift2) Then
Gear = 2
GearDelay = 100
Else
Gear = 0
CarSpeed = 1
EndIf
ElseIf (GraphicsWindow.LastKey = SKey) Then
If (UpShift3) Then
Gear = 3
GearDelay = 100
Else
Gear = 0
CarSpeed = 1
EndIf
ElseIf (GraphicsWindow.LastKey = XKey) Then
If (UpShift4) Then
Gear = 4
Else
Gear = 0
CarSpeed = 1
EndIf
EndIf
Shapes.Rotate(Car, CarAngle)
EndIf
If nodrift Then ' nonkit
LastCarAngle[rem] = CarAngle ' nonkit
EndIf ' nonkit
debug = "CarAngle=" + CarAngle ' nonkit
debug = debug + " LastCarAngle=" ' nonkit
debug = debug + LastCarAngle[rem] ' nonkit
GraphicsWindow.Title = debug ' nonkit
'This does the forward and turning motion
CarX = Math.Remainder(Shapes.GetLeft(Car) + (Math.Cos(Math.GetRadians(LastCarAngle[rem] - 180)) * CarSpeed) + GWinWidth, GWinWidth) ' nonkit
CarY = Math.Remainder(Shapes.GetTop(Car) + (Math.Sin(Math.GetRadians(LastCarAngle[rem] - 180)) * CarSpeed) + GWinHeight, GWinHeight) ' nonkit
Shapes.Move(Car, CarX, CarY)
EndSub
Sub ChangeGear
If (Gear = 1) Then
Shapes.ShowShape(Gear1Message)
Shapes.HideShape(Gear2Message)
Shapes.HideShape(Gear3Message)
Shapes.HideShape(Gear4Message)
If (GearDelay >= 67) Then
CarSpeed = Gear1Min
Shapes.HideShape(ShiftMessage)
ElseIf (GearDelay <= 67 And GearDelay >= 34) Then
CarSpeed = Gear1Min + 1
ElseIf (GearDelay <= 34 And GearDelay >= 1) Then
CarSpeed = Gear1Min + 2
Shapes.ShowShape(ShiftMessage)
UpShift2 = "True"
UpShift3 = "False"
UpShift4 = "False"
EndIf
ElseIf (Gear = 2) Then
Shapes.HideShape(Gear1Message)
Shapes.ShowShape(Gear2Message)
Shapes.HideShape(Gear3Message)
Shapes.HideShape(Gear4Message)
If (GearDelay >= 67) Then
CarSpeed = Gear2Min
Shapes.HideShape(ShiftMessage)
ElseIf (GearDelay <= 67 And GearDelay >= 34) Then
CarSpeed = Gear2Min + 1
ElseIf (GearDelay <= 34 And GearDelay >= 1) Then
CarSpeed = Gear2Min + 2
Shapes.ShowShape(ShiftMessage)
UpShift2 = "True"
UpShift3 = "True"
UpShift4 = "False"
EndIf
ElseIf (Gear = 3) Then
Shapes.HideShape(Gear1Message)
Shapes.HideShape(Gear2Message)
Shapes.ShowShape(Gear3Message)
Shapes.HideShape(Gear4Message)
If (GearDelay >= 67) Then
CarSpeed = Gear3Min
Shapes.HideShape(ShiftMessage)
ElseIf (GearDelay <= 67 And GearDelay >= 34) Then
CarSpeed = Gear3Min + 1
ElseIf (GearDelay <= 34 And GearDelay >= 1) Then
CarSpeed = Gear3Min + 2
Shapes.ShowShape(ShiftMessage)
UpShift2 = "True"
UpShift3 = "True"
UpShift4 = "True"
EndIf
ElseIf (Gear = 4) Then
Shapes.HideShape(Gear1Message)
Shapes.HideShape(Gear2Message)
Shapes.HideShape(Gear3Message)
Shapes.ShowShape(Gear4Message)
Shapes.HideShape(ShiftMessage)
CarSpeed = Gear4Min
EndIf
GearDelay = GearDelay - 1
EndSub