Sub GenerateLevel
Games = Games + 1
GameBoard = ""
GameBoard[2][2] = 0
Score = 0
endsquare = 0
BoxesToGo = GenerateMinPoints
GenerateBorders()
GenerateIllegals()
GeneratePoints()
DrawUI()
If Games = 1 Then
ShowHelp()
EndIf
SpawnPlayer()
EndSub
Sub GenerateBorders
For GenerateBordersXVar = 0 To 30
For GenerateBordersYVar = 0 To 30
If GenerateBordersXVar = 1 Or GenerateBordersXVar = DrawUI_MinBoxes Then
GameBoard[GenerateBordersXVar][GenerateBordersYVar] = 1
ElseIf GenerateBordersYVar = 1 or GenerateBordersYVar = DrawUI_MinBoxes Then
GameBoard[GenerateBordersXVar][GenerateBordersYVar] = 1
EndIf
EndFor
EndFor
EndSub
Sub GeneratePoints '
For GeneratedPointsVar = 1 To GenerateMinPoints
RandomX = Math.GetRandomNumber(DrawUI_MinBoxes)
RandomY = Math.GetRandomNumber(DrawUI_MinBoxes)
If GameBoard[RandomX][RandomY] = "" Or GameBoard[RandomX][RandomY] = 0 Then
If GameBoard[RandomX][RandomY] <> 2 And GameBoard[RandomX][RandomY] <> 3 And GameBoard[RandomX][RandomY] <> 4 And GameBoard[RandomX][RandomY] <> 1 Then
If LDCall.Function2(AccessFunction,RandomX,RandomY) > 1 then
GameBoard[RandomX][RandomY] = 3
Elseif LDCall.Function2(AccessFunction,RandomX,RandomY) = 1 and endsquare = 0 Then
endsquare = 1
GameBoard[RandomX][RandomY] = 4
EndIf
EndIf
Sub GenerateIllegals
For GeneratedIllegalsVar = 1 To GenerateMinIllegals
RandomX = Math.GetRandomNumber(DrawUI_MinBoxes)
RandomY = Math.GetRandomNumber(DrawUI_MinBoxes)
If GameBoard[RandomX][RandomY] = "" Or GameBoard[RandomX][RandomY] = 0 Then
If LDCall.Function2(AccessFunction,RandomX,RandomY) >= 1 And GameBoard[RandomX][RandomY] <> 1 And GameBoard[RandomX][RandomY] <> 2 And GameBoard[RandomX][RandomY] <> 3 And GameBoard[RandomX][RandomY] <> 4 then
GameBoard[RandomX][RandomY] = 1
EndIf
Else
GeneratedIllegalsVar = GeneratedIllegalsVar - 1
EndIf
EndFor
EndSub
Sub DrawUI ' Draws Basic UI
DrawNumbers()
For UIx = 1 To DrawUI_MinBoxes
For UIy = 1 To DrawUI_MinBoxes
CurrentCell = GameBoard[UIx][UIy]
If CurrentCell = 1 Then
GraphicsWindow.BrushColor = "Black"
ElseIf CurrentCell = 2 then
Sub ShowHelp
MSG = " Hello!"+ClLF+"Welcome to Turtle. Turtle is a game developed in Small Basic." + ClLF + "Here are the controls : " +ClLF
MSG = MSG + ClLF + "W - Up " + ClLF + "A - Left " + ClLF + "S - Down " + ClLF + "D - Right " + ClLF + "F1 - Show this screen" + ClLF + "F5 - Generate a new level " +ClLF
GraphicsWindow.ShowMessage(MSG , "Help")
EndSub
'_________________________________________________________________________________________________________________________________
' Player Controls
'_________________________________________________________________________________________________________________________________
Sub GameOverCheck
If BoxesToGo = 0 then
EndTime = Clock.ElapsedMilliseconds
Tick()
Timer.Pause()
GraphicsWindow.ShowMessage("You have won!", " Game Over :)")
ElseIf LDCall.Function2(AccessFunction,TurtleFx,TurtleFY) = 0 Then
EndTime = Clock.ElapsedMilliseconds
Tick()
Timer.Pause()
GraphicsWindow.ShowMessage("You are Trapped", " Game Over :(")
EndIf
EndSub