Sprites and LTPB

General FreeBASIC programming questions.
Post Reply
NorbyDroid
Posts: 72
Joined: May 21, 2016 22:55

Sprites and LTPB

Post by NorbyDroid »

Back in 1998 Interplay/Presage/Stepping Stone came out with e programming language based on BASIC called "Learn to Program BASIC" and I have
always enjoyed using it. Especially the sprite features. I thought I would try and recreate LTPB commands and functions for FreeBasic.

I also created a small Fish Clock program to show some commands.

Without help I am unable to do any of the sound commands. Any help will be appreciated.

Image used in the code is from the Kenney website with lots of great assets under the Creative Commons CC0 license.
Here is a link to the image I used: https://www.kenney.nl/assets/fish-pack

Here is the Fish Clock program:

Code: Select all

#Include "Sprites.bi"

Dim As Integer Retina=01

Dim Shared As Integer SpriteSize
SpriteSize=64*(Retina+1)

Canvas.w=10*SpriteSize
Canvas.h=5*SpriteSize

Function HighTimer As Double
	Return Timer*1000
End Function

Sub InitBack(Tiles As FB.Image Ptr)
  Dim As Integer x1=16*SpriteSize
  Dim As Integer x2=17*SpriteSize

  Dim As Integer y1=4*SpriteSize
  Dim As Integer y2=2*SpriteSize

	For x As Integer=0 To Canvas.w\SpriteSize-1
    ' Water
		Put Canvas.BackImage, (SpriteSize*x, 0), Tiles, _
		           (x1, y1)-(x1+SpriteSize-1, y1+SpriteSize-1), Alpha

		Put Canvas.BackImage, (SpriteSize*x, SpriteSize), Tiles, _
		           (x2, y1)-(x2+SpriteSize-1, y1+SpriteSize-1), Alpha

    ' Sand
		Put Canvas.BackImage, (SpriteSize*x, 2*SpriteSize), Tiles, _
		           (0, y2)-(SpriteSize-1, y2+SpriteSize-1), Alpha

		Put Canvas.BackImage, (SpriteSize*x, 3*SpriteSize), Tiles, _
		           (0, y2)-(SpriteSize-1, y2+SpriteSize-1), Alpha

		Put Canvas.BackImage, (SpriteSize*x, 4*SpriteSize), Tiles, _
		           (0, y2)-(SpriteSize-1, y2+SpriteSize-1), Alpha
	Next
End Sub

Sub GetFish(MaxFish As Integer, Fish() As SpriteType, Tiles As FB.Image Ptr)
  For t As Integer=1 To MaxFish
    ' Add the fish from the tiles image to the Fish Sprite
    Dim As Integer y=4*SpriteSize

    For x As Integer=0 To 9
  	  ImageToFrames Fish(t), SpriteSize*x, y, _
  	                         SpriteSize, SpriteSize, Tiles
    Next

    For x As Integer=0 To 13
	    ImageToFrames Fish(t), SpriteSize*x, y+SpriteSize, _
	                           SpriteSize, SpriteSize, Tiles
    Next

    ImageToFrames Fish(t), 14*SpriteSize, y+SpriteSize, _
                           2*SpriteSize, SpriteSize, Tiles

    ImageToFrames Fish(t), 16*SpriteSize, y+SpriteSize, _
                           2*SpriteSize, SpriteSize, Tiles
  Next
End Sub

Sub InitFish(Fish As SpriteType)
  Fish.Start=HighTimer

 ' Choose a Random Fish
  Dim As Integer FishVal=Int(Fish.NumFrames*Rnd)
  SetSprite Fish, "Frame", FishVal
  SetSprite Fish, "Range", FishVal, FishVal

  ' Place the Fish at a location offscreen
  Dim As Integer t1=SpriteSize\2
  Dim As Integer t2=Canvas.h\t1-1
  SetSprite Fish, "to", -SpriteSize*Int(SpriteSize*Rnd), t2*Int(t1*Rnd)

  ' Choose how fast the fish swim
  CycleSprite Fish, "Speed", 8
End Sub

Sub Digital(x As Integer, y As Integer, Text As String, Numbers As SpriteType)
  For t As Integer=0 To Len(Text)-1
    Dim As Integer tAsc=Asc(Mid(Text, t+1, 1))

    If tAsc>47 And tAsc<58 Then
    	Put(SpriteSize*t+x, y), Numbers.Frame(tAsc-48), Alpha
    EndIf
  Next
End Sub

Sub DrawCanvas(MaxFish As Integer, Fish() As SpriteType, _
	             Speed As Integer, Numbers As SpriteType)

  ScreenLock
    Canvas.DrawCanvas
    
    For t As Integer=1 To MaxFish
      If Fish(t).Show Then
        Put(Fish(t).xSprite, Fish(t).ySprite), Fish(t).Frame(Fish(t).CurFrame), Alpha
      EndIf
    Next

    ' Digital Canvas.w-2*SpriteSize, 0, Str(Speed), Numbers
    Digital SpriteSize, 2*SpriteSize, Time, Numbers
  ScreenUnLock
End Sub

Sub Main(MaxFish As Integer, Fish() As SpriteType, _
	       Numbers As SpriteType, Tiles As FB.Image Ptr)

  For t As Integer=1 To MaxFish
    InitFish Fish(t)
    ShowSprite Fish(t)
  Next
  
  Dim As String fTime=Time
  Dim As Integer Speed, tFrames=0
   
  While _LTPB_TRUE_
  	Dim As Double Start=HighTimer

  	Dim As String Touch=InKey

	  If Touch=Chr(27) Then
      Exit Sub
	  EndIf
	  
    For t As Integer=1 To MaxFish
	    If HighTimer-Fish(t).Start>Fish(t).EndTImer Then
        'Start the Fish Timer (How fast they swim) 
	  	  Fish(t).Start=HighTimer

        ' Move the fish along
	  	  Fish(t).xSprite+=SpriteSize\4

        ' Fish Swam past the screen edge?
	  	  If Fish(t).xSprite>Canvas.w Then InitFish Fish(t)
	    EndIf
    Next
    
    While HighTimer-Start<16.6
      DrawCanvas MaxFish, Fish(), Speed, Numbers
 	  	Sleep 1, 1
    Wend
    
    tFrames+=1
    If fTime<>Time Then	Speed=tFrames: tFrames=0: fTime=Time
  Wend
End Sub

ScreenRes Canvas.w, Canvas.h, 32

' Load the Tile Sheet
Dim As FB.Image Ptr Tiles
If Retina=0 Then
  Tiles=LoadImage("FishTilesheet.png")
Else
  Tiles=LoadImage("FishTilesheet2.png")
EndIf

' Create the Background Image
Canvas.BackImage=ImageCreate(Canvas.w, Canvas.h, 32)
InitBack Tiles

' Create the Fish
Dim As Integer MaxFish=100
Dim As SpriteType Fish(MaxFish), Numbers
GetFish MaxFish, Fish(), Tiles

For x As Integer=0 To 9
	ImageToFrames Numbers, x*SpriteSize, 6*SpriteSize, _
	                       SpriteSize, SpriteSize, Tiles
Next

Main MaxFish, Fish(), Numbers, Tiles
Sleep

' Remove images
For t As Integer=1 To MaxFish
  FreeSprite Fish(t)
Next

FreeSprite Numbers
ImageDestroy Tiles
ImageDestroy Canvas.BackImage
Here is the Sprites.bi code:

Code: Select all

#Include Once "fbgfx.bi"
#Include Once "fbpng.bi"
#Include Once "vbcompat.bi"

#Define RGB_R(C) (CULng(C) Shr 16 And 255)
#Define RGB_G(C) (CULng(C) Shr  8 And 255)
#Define RGB_B(C) (CULng(C)        And 255)
#Define RGB_A(C) (CULng(C) Shr 24        )

Declare Function MouseRect(x1 As Integer, y1 As Integer, _
                           x2 As Integer, y2 As Integer) As Boolean

Type ScreenType
  As Integer xPos, yPos, w, h

  As String ColorName
  As ULong ColorMain, ColorText
  
  As FB.Image Ptr BackImage
  
  Declare Sub DrawCanvas
End Type

Dim Shared Canvas As ScreenType

Sub ScreenType.DrawCanvas
	Put(0, 0), BackImage, Alpha
End Sub

Type MouseType
	As Integer Info, xRat, yRat, ButtonRat
End Type

Type SpriteType
  As String SprDir, SprName

  As Single Start, CurTimer, EndTimer

  As Boolean Idle, Show
 
  As Integer Flipped
  As Integer xStep, yStep
  As Integer Cycle, tCycle
  As Integer RangeS, RangeF
  As Integer NumSteps, Steps
  As Integer wSprite, hSprite
  As Integer xSprite, ySprite
  As Integer CurFrame, NumFrames
  As Integer GrabRat, xRat, yRat, ButtonRat

  As FB.Image Ptr Frame(255)
End Type

' Bitmap Support - Allows Sprites to be loaded from a bmp file
Function BMP_Load(ByRef Filename As Const String) As FB.Image Ptr
	Dim As Integer Filenum, bmpWidth, bmpHeight
	Dim As FB.Image Ptr Image
	
	If FileExists(Filename) Then
	  Filenum=FreeFile
		Open Filename For Binary As Filenum
		Get #Filenum, 19, bmpWidth
		Get #Filenum, 23, bmpHeight
		Close #Filenum
		
		Image=ImageCreate(bmpWidth, Abs(bmpHeight))
		BLoad Filename, Image
		
		Return Image
	Else
		Return 0
	EndIf
End Function

' Extract Tags from Text
Function Extract(Text As String, Tag As String) As String
 	Dim As Integer i=InStr(Text, Tag)+Len(Tag)
 	Return Right(Text, Len(Text)-i)
End Function

Function LoadImage(File As String) As FB.Image Ptr
	If FileExists(File) Then
		Dim As String Ext=UCase(Right(File, 3))

		If Ext="BMP" Then Return BMP_Load(File)
		If Ext="PNG" Then Return PNG_Load(File)
	EndIf
End Function

Function PixelString(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer) As String
  Dim Pixel As ULong
  Dim PixelStr As String
  
  For y As Integer=y1 To y2
  	For x As Integer=x1 To x2
   		Dim As ULong Pixel=Point(x, y)
   		Dim As Integer r=RGB_R(Pixel), g=RGB_G(Pixel), b=RGB_B(Pixel)

   		PixelStr=PixelStr+Chr(r)+Chr(g)+Chr(b)
  	Next
  Next

  Return PixelStr
End Function

' Load an Image file and convert it to Sprite frames
Sub FileToFrames(File As String, Sprite As SpriteType, w As Integer, h As Integer)
  If FileExists(File) Then
  	Dim As FB.Image Ptr Source=LoadImage(File)
    Dim As Integer iw, ih, Info=ImageInfo(Source, iw, ih)

    Dim As Integer tFrames=Sprite.NumFrames
    
    For y As Integer=0 To ih\h-1
  	  For x As Integer=0 To iw\w-1
  	  	Sprite.Frame(tFrames)=ImageCreate(w, h, 32)

  	  	Dim As Integer x1=x*w, y1=y*h
  		  Put Sprite.Frame(tFrames), (0, 0), Source, (x*w, y*h)-(x1+w-1, y1+h-1), Alpha
  		  tFrames+=1
  	  Next
    Next

    Sprite.NumFrames=tFrames
  EndIf
End Sub

' Place Image(s) into the Sprite
Sub ImageToFrames(Sprite As SpriteType, x As Integer, y As Integer, _
	                w As Integer, h As Integer, Source As FB.Image Ptr)

 	Sprite.Frame(Sprite.NumFrames)=ImageCreate(w, h, 32)
  Put Sprite.Frame(Sprite.NumFrames), (0, 0), Source, (x, y)-(x+w-1, y+h-1), Alpha
  Sprite.NumFrames+=1
End Sub

' Update the the current mouse information
Sub RatUpdate(Rat As MouseType)
  Rat.Info=GetMouse(Rat.xRat, Rat.yRat, , Rat.ButtonRat)

  If Rat.ButtonRat Then
    If Rat.ButtonRat And 1 Then Rat.ButtonRat=1
    If Rat.ButtonRat And 2 Then Rat.ButtonRat=2
    If Rat.ButtonRat And 4 Then Rat.ButtonRat=3
  EndIf
End Sub

#Include Once "LTPB.Bi"
Here is the LTPB.bi code:

Code: Select all

' Learn To Program BASIC for FreeBasic v0.1

#Ifndef __LTPB_BI__
#Define __LTPB_BI__

#Define _LTPB_TRUE_  1
#Define _LTPB_FALSE_ 0

Type Goo
  As Integer RangeS, RangeF
	As Integer xRat, yRat, Button
  As Integer CurFrame, NumFrames
  As Integer Cycle, Flipped, Show
  
  As String ColorName
	As ULong ColorMain, ClorText

	As FB.Image Ptr BackImage
End Type

' --------------------------------------------------------------------------------
' LTPB Commands and Functiuons
' --------------------------------------------------------------------------------

' All 236 LTPB Colors
Function LTPB_Colors(iColour As Integer) As uLong
  Select Case iColour
    Case 0: Return RGB(90,32,0)
  	Case 1: Return RGB(82,20,0)
    Case 2: Return RGB(66,8,0)
  	Case 3: Return RGB(57,4,0)
    Case 4: Return RGB(49,0,0)
    Case 5: Return RGB(255,251,255)
    Case 6: Return RGB(239,235,239)
    Case 7: Return RGB(222,219,222)
    Case 8: Return RGB(206,203,206)
    Case 9: Return RGB(189,186,189)
    Case 10: Return RGB(165,166,165)
    Case 11: Return RGB(148,150,148)
    Case 12: Return RGB(132,134,132)
    Case 13: Return RGB(115,117,115)
    Case 14: Return RGB(99,97,99)
    Case 15: Return RGB(82,81,82)
    Case 16: Return RGB(66,65,66)
    Case 17: Return RGB(49,48,49)
    Case 18: Return RGB(24,28,24)
    Case 19: Return RGB(8,12,8)
    Case 20: Return RGB(0,4,0)
    Case 21: Return RGB(239,199,57)
    Case 22: Return RGB(231,186,57)
    Case 23: Return RGB(222,178,49)
    Case 24: Return RGB(214,170,49)
    Case 25: Return RGB(206,158,41)
    Case 26: Return RGB(198,150,41)
    Case 27: Return RGB(189,142,41)
    Case 28: Return RGB(181,134,33)
    Case 29: Return RGB(173,125,33)
    Case 30: Return RGB(165,117,24)
    Case 31: Return RGB(156,109,24)
    Case 32: Return RGB(148,101,24)
    Case 33: Return RGB(140,93,16)
    Case 34: Return RGB(132,85,16)
    Case 35: Return RGB(123,77,16)
    Case 36: Return RGB(123,73,16)
    Case 37: Return RGB(206,154,0)
    Case 38: Return RGB(198,134,0)
    Case 39: Return RGB(189,117,0)
    Case 40: Return RGB(181,101,0)
    Case 41: Return RGB(173,85,0)
    Case 42: Return RGB(165,73,0)
    Case 43: Return RGB(156,60,0)
    Case 44: Return RGB(156,48,0)
    Case 45: Return RGB(148,48,0)
    Case 46: Return RGB(140,48,0)
    Case 47: Return RGB(132,48,0)
    Case 48: Return RGB(123,48,0)
    Case 49: Return RGB(115,48,0)
    Case 50: Return RGB(115,48,0)
    Case 51: Return RGB(107,48,0)
    Case 52: Return RGB(99,48,0)
    Case 53: Return RGB(99,255,255)
    Case 54: Return RGB(90,235,255)
    Case 55: Return RGB(82,219,255)
    Case 56: Return RGB(74,199,255)
    Case 57: Return RGB(66,174,255)
    Case 58: Return RGB(57,154,255)
    Case 59: Return RGB(49,125,255)
    Case 60: Return RGB(49,101,255)
    Case 61: Return RGB(49,0,255)
    Case 62: Return RGB(33,0,222)
    Case 63: Return RGB(24,0,198)
    Case 64: Return RGB(16,0,165)
    Case 65: Return RGB(8,0,140)
    Case 66: Return RGB(0,0,107)
    Case 67: Return RGB(0,0,82)
    Case 68: Return RGB(0,0,49)
    Case 69: Return RGB(66,130,189)
    Case 70: Return RGB(57,121,173)
    Case 71: Return RGB(49,113,165)
    Case 72: Return RGB(41,101,148)
    Case 73: Return RGB(33,93,132)
    Case 74: Return RGB(24,85,123)
    Case 75: Return RGB(24,77,107)
    Case 76: Return RGB(16,69,99)
    Case 77: Return RGB(140,174,140)
    Case 78: Return RGB(123,162,132)
    Case 79: Return RGB(107,154,115)
    Case 80: Return RGB(90,146,107)
    Case 81: Return RGB(82,134,99)
    Case 82: Return RGB(66,125,90)
    Case 83: Return RGB(57,117,82)
    Case 84: Return RGB(49,109,74)
    Case 85: Return RGB(255,170,107)
    Case 86: Return RGB(247,154,90)
    Case 87: Return RGB(239,142,82)
    Case 88: Return RGB(231,130,66)
    Case 89: Return RGB(222,113,57)
    Case 90: Return RGB(214,101,49)
    Case 91: Return RGB(206,89,41)
  	Case 92: Return RGB(206,77,33)
    Case 93: Return RGB(255,0,49)
    Case 94: Return RGB(239,4,49)
    Case 95: Return RGB(222,16,49)
    Case 96: Return RGB(214,24,49)
    Case 97: Return RGB(198,32,49)
    Case 98: Return RGB(181,40,49)
    Case 99: Return RGB(165,44,49)
    Case 100: Return RGB(156,48,49)
    Case 101: Return RGB(255,186,255)
    Case 102: Return RGB(255,174,247)
    Case 103: Return RGB(255,162,222)
    Case 104: Return RGB(255,150,206)
    Case 105: Return RGB(255,138,181)
    Case 106: Return RGB(255,125,148)
    Case 107: Return RGB(255,113,115)
    Case 108: Return RGB(255,117,99)
    Case 109: Return RGB(214,0,66)
    Case 110: Return RGB(198,0,49)
    Case 111: Return RGB(189,0,33)
    Case 112: Return RGB(173,0,24)
    Case 113: Return RGB(165,0,16)
    Case 114: Return RGB(148,0,8)
    Case 115: Return RGB(140,0,0)
    Case 116: Return RGB(123,0,0)
    Case 117: Return RGB(222,239,57)
    Case 118: Return RGB(206,207,49)
    Case 119: Return RGB(198,166,49)
    Case 120: Return RGB(181,142,33)
    Case 121: Return RGB(156,117,41)
    Case 122: Return RGB(148,105,33)
    Case 123: Return RGB(140,97,33)
    Case 124: Return RGB(99,48,0)
    Case 125: Return RGB(255,247,8)
    Case 126: Return RGB(247,211,8)
    Case 127: Return RGB(231,182,16)
    Case 128: Return RGB(222,154,16)
    Case 129: Return RGB(206,130,16)
    Case 130: Return RGB(198,105,16)
    Case 131: Return RGB(181,85,16)
    Case 132: Return RGB(173,69,24)
    Case 133: Return RGB(255,231,123)
    Case 134: Return RGB(247,223,107)
    Case 135: Return RGB(239,215,99)
    Case 136: Return RGB(239,211,90)
    Case 137: Return RGB(231,203,82)
    Case 138: Return RGB(222,199,74)
    Case 139: Return RGB(214,190,66)
    Case 140: Return RGB(214,186,57)
    Case 141: Return RGB(255,231,90)
    Case 142: Return RGB(247,219,74)
    Case 143: Return RGB(239,207,74)
    Case 144: Return RGB(239,195,74)
    Case 145: Return RGB(231,186,74)
    Case 146: Return RGB(222,178,74)
    Case 147: Return RGB(214,170,74)
    Case 148: Return RGB(214,166,74)
    Case 149: Return RGB(99,247,41)
    Case 150: Return RGB(66,223,24)
    Case 151: Return RGB(41,203,16)
    Case 152: Return RGB(16,182,8)
    Case 153: Return RGB(8,162,16)
    Case 154: Return RGB(0,142,16)
    Case 155: Return RGB(0,121,24)
    Case 156: Return RGB(0,101,24)
    Case 157: Return RGB(156,207,99)
    Case 158: Return RGB(140,190,74)
    Case 159: Return RGB(132,174,57)
    Case 160: Return RGB(123,158,41)
    Case 161: Return RGB(123,146,24)
    Case 162: Return RGB(115,130,8)
    Case 163: Return RGB(107,113,0)
    Case 164: Return RGB(99,101,0)
    Case 165: Return RGB(0,0,148)
    Case 166: Return RGB(0,52,198)
    Case 167: Return RGB(0,109,198)
    Case 168: Return RGB(0,166,198)
    Case 169: Return RGB(0,199,165)
    Case 170: Return RGB(0,182,90)
    Case 171: Return RGB(0,199,49)
    Case 172: Return RGB(0,243,0)
    Case 173: Return RGB(255,227,255)
    Case 174: Return RGB(255,219,239)
    Case 175: Return RGB(247,215,214)
    Case 176: Return RGB(247,223,214)
    Case 177: Return RGB(239,235,206)
    Case 178: Return RGB(222,235,198)
    Case 179: Return RGB(198,231,198)
    Case 180: Return RGB(189,227,206)
    Case 181: Return RGB(99,207,156)
    Case 182: Return RGB(90,211,173)
    Case 183: Return RGB(90,219,189)
    Case 184: Return RGB(82,227,214)
    Case 185: Return RGB(74,223,231)
    Case 186: Return RGB(66,203,239)
    Case 187: Return RGB(57,182,247)
    Case 188: Return RGB(49,154,255)
    Case 189: Return RGB(99,0,255)
    Case 190: Return RGB(132,0,231)
    Case 191: Return RGB(148,0,214)
    Case 192: Return RGB(165,0,189)
    Case 193: Return RGB(165,0,165)
    Case 194: Return RGB(140,0,115)
    Case 195: Return RGB(123,0,74)
    Case 196: Return RGB(99,0,49)
    Case 197: Return RGB(206,48,255)
    Case 198: Return RGB(247,40,247)
    Case 199: Return RGB(239,28,198)
    Case 200: Return RGB(231,24,148)
    Case 201: Return RGB(231,16,99)
    Case 202: Return RGB(222,8,41)
    Case 203: Return RGB(214,8,0)
    Case 204: Return RGB(206,48,0)
    Case 205: Return RGB(255,130,165)
    Case 206: Return RGB(239,101,140)
    Case 207: Return RGB(222,77,123)
    Case 208: Return RGB(214,56,107)
    Case 209: Return RGB(198,40,90)
    Case 210: Return RGB(181,20,74)
    Case 211: Return RGB(165,8,57)
    Case 212: Return RGB(156,0,49)
    Case 213: Return RGB(206,101,206)
    Case 214: Return RGB(198,89,189)
    Case 215: Return RGB(181,81,173)
    Case 216: Return RGB(173,69,156)
    Case 217: Return RGB(165,60,140)
    Case 218: Return RGB(148,52,132)
    Case 219: Return RGB(140,44,115)
    Case 220: Return RGB(132,40,99)
    Case 221: Return RGB(222,239,57)
    Case 222: Return RGB(206,207,49)
    Case 223: Return RGB(198,166,49)
    Case 224: Return RGB(189,150,49)
    Case 225: Return RGB(156,154,49)
    Case 226: Return RGB(181,142,33)
    Case 227: Return RGB(206,207,99)
    Case 228: Return RGB(198,170,90)
    Case 229: Return RGB(0,0,115)
    Case 230: Return RGB(255,0,0)
    Case 231: Return RGB(255,101,49)
    Case 232: Return RGB(255,223,74)
    Case 233: Return RGB(255,255,0)
    Case 234: Return RGB(255,247,247)
    Case 235: Return RGB(255,223,74)
  End Select
End Function

' All 236 LTPB Color Names - Yes every color has a name.  Some quite funny
Function LTPB_ColorName(iColour As Integer) As String
  Select Case iColour
    Case 0: Return "Bullish Brown"
    Case 1: Return "Dirt Brown"
    Case 2: Return "Dark Brown"
    Case 3: Return "Really Dark Brown"
    Case 4: Return "Brownout Brown"
    Case 5: Return "Extremely Dark Brown"
    Case 6: Return "Some Say White"
    Case 7: Return "Sorta White"
    Case 8: Return "Way Light Gray"
    Case 9: Return "Light Gray"
    Case 10: Return "Gray"
    Case 11: Return "Earl Gray"
    Case 12: Return "House Gray"
  	Case 13: Return "TRUE Gray"
    Case 14: Return "Battleship Gray"
    Case 15: Return "Dark Gray"
    Case 16: Return "Darker Gray"
    Case 17: Return "Hair Gray"
    Case 18: Return "Shale Gray"
    Case 19: Return "Charcoal Gray"
    Case 20: Return "Almost Black"
    Case 21: Return "Black Is Black"
    Case 22: Return "Yellow"
    Case 23: Return "Darker Yellow"
    Case 24: Return "Light Gold"
    Case 25: Return "Gold"
    Case 26: Return "Sun Gold"
    Case 27: Return "Dark Gold"
    Case 28: Return "Brown Gold"
    Case 29: Return "Gold Brown"
    Case 30: Return "Dirty Gold"
    Case 31: Return "Gold Fever"
    Case 32: Return "Gold Rush"
    Case 33: Return "Gold Medal"
    Case 34: Return "Golden Image"
    Case 35: Return "Gold Record"
    Case 36: Return "Fools Gold"
    Case 37: Return "Solid Gold"
    Case 38: Return "Old Mustard"
    Case 39: Return "Mustard"
    Case 40: Return "Darkly Yellow"
    Case 41: Return "Shoe Bottom Brown"
    Case 42: Return "Last Week"
    Case 43: Return "Cafeteria Food"
    Case 44: Return "Quigiboo"
    Case 45: Return "Last Years Cafeteria"
    Case 46: Return "Brownish Brown"
    Case 47: Return "5 Week Lettuce"
    Case 48: Return "Caramel"
    Case 49: Return "Mud"
    Case 50: Return "Super Mud 2000"
    Case 51: Return "Mold"
    Case 52: Return "Mildew"
    Case 53: Return "Old Mold"
    Case 54: Return "Happy Sky"
    Case 55: Return "Sky Blue"
    Case 56: Return "Smurf Blue"
    Case 57: Return "Raving Blue"
    Case 58: Return "Light Blue"
    Case 59: Return "Steve's Smurf Blue"
    Case 60: Return "Fair to Middlin Blue"
    Case 61: Return "Navy Intel Blue"
    Case 62: Return "Deep Blue"
    Case 63: Return "Deeper Blue"
    Case 64: Return "Commie 64 Blue"
    Case 65: Return "Blue and Blue"
    Case 66: Return "Feelin' Blue"
    Case 67: Return "Royal Blue"
    Case 68: Return "Midnight Blue"
    Case 69: Return "Nameless Blue"
    Case 70: Return "Puddin Blue"
    Case 71: Return "Ocean Blue"
    Case 72: Return "Busy Blue"
    Case 73: Return "Me too blue"
    Case 74: Return "Baby Blue"
    Case 75: Return "Smelty Blue"
    Case 76: Return "Brian Fargo Blue"
    Case 77: Return "Color #77"
    Case 78: Return "Aquaman Aqua"
    Case 79: Return "Toilet Green"
    Case 80: Return "Refrigerator Life"
    Case 81: Return "Verdant Yet Mundane"
    Case 82: Return "Antibiotic Green"
    Case 83: Return "Fish Green"
    Case 84: Return "Disinfectant Green"
    Case 85: Return "Dark Disinfectant Green"
    Case 86: Return "Georgia Peach"
    Case 87: Return "Caucasian"
    Case 88: Return "Suntan"
    Case 89: Return "Dark Suntan"
    Case 90: Return "Nylon"
    Case 91: Return "Pamela Suntan"
    Case 92: Return "Dark Pamela Suntan"
    Case 93: Return "Georgia Peach at E3"
    Case 94: Return "Happy Red"
    Case 95: Return "Not So Happy Red"
    Case 96: Return "Red"
    Case 97: Return "Brick Red"
    Case 98: Return "Sunburn"
    Case 99: Return "Pamela Sunburn"
    Case 100: Return "Shameless Red"
    Case 101: Return "Shamefull Red"
    Case 102: Return "Elephant Pink"
    Case 103: Return "Nordic Pink"
    Case 104: Return "Froofy Pink"
    Case 105: Return "French Horn Pink"
    Case 106: Return "Pink"
    Case 107: Return "Less than Pink"
    Case 108: Return "Skin Cancer Pink"
    Case 109: Return "Grapefruit Pink"
    Case 110: Return "Tanning Salon Red"
    Case 111: Return "Sports Car Red"
    Case 112: Return "Witch Apple Red"
    Case 113: Return "Blood Red"
  	Case 114: Return "Disgruntled Pit Boss Red"
    Case 115: Return "Khan red"
    Case 116: Return "Coagulated Red"
    Case 117: Return "Xing Xing Red"
    Case 118: Return "Yer in Jail Yellow"
    Case 119: Return "Ochre"
    Case 120: Return "Closer to Ochre than 119"
    Case 121: Return "The Color Formerly Known as Ochre"
    Case 122: Return "Dandy Vomit"
    Case 123: Return "Teabag"
    Case 124: Return "Snail Meets Foot"
    Case 125: Return "Used Banana Slug"
    Case 126: Return "Old Yeller"
    Case 127: Return "Older Yeller"
    Case 128: Return "Racing Jacket Yellow"
    Case 129: Return "Old Butter Yellow"
    Case 130: Return "August"
    Case 131: Return "Butter Nut Brown"
    Case 132: Return "Bad Popcorn"
    Case 133: Return "Caramel Splendor"
    Case 134: Return "Earth"
    Case 135: Return "Wallflower"
    Case 136: Return "Wallflower's Cronie"
    Case 137: Return "Cauliflower"
    Case 138: Return "Scratch and Sniff"
    Case 139: Return "Sea Bass"
    Case 140: Return "Bad Cauliflower"
    Case 141: Return "Seasick"
    Case 142: Return "Granddaddy Sea Bass"
    Case 143: Return "London Fog"
    Case 144: Return "Mexico City"
    Case 145: Return "LA on a good day"
    Case 146: Return "Smog Alert 1"
    Case 147: Return "Smog Alert 2"
    Case 148: Return "Stay at Home"
    Case 149: Return "Leave Town"
    Case 150: Return "Lucky Charm Green"
    Case 151: Return "Vibrant Green"
    Case 152: Return "Algae Green"
    Case 153: Return "Spirulina Green"
    Case 154: Return "Backwash Green"
    Case 155: Return "Sprig o' Mint Green"
    Case 156: Return "Soylent Green"
    Case 157: Return "Merry Men Shorts Green"
    Case 158: Return "Wedding Candy Green"
    Case 159: Return "Bad Cake Frosting Green"
    Case 160: Return "Spirit of Bile Green"
    Case 161: Return "Irish Green"
    Case 162: Return "Snot Green"
    Case 163: Return "Chlorophyll Green"
    Case 164: Return "Chernobyl Green"
    Case 165: Return "With Envy"
    Case 166: Return "Air Force Blue"
    Case 167: Return "Blue Hawaii"
    Case 168: Return "Columbia Blue"
    Case 169: Return "Cumulus"
    Case 170: Return "Ice Pack Blue"
    Case 171: Return "Mouthwash Green"
    Case 172: Return "Putting Green"
    Case 173: Return "Derek's Secret Wall Panel"
    Case 174: Return "Sapphire White"
    Case 175: Return "Slightly Pinkish"
    Case 176: Return "Horse White"
    Case 177: Return "Often Called White"
    Case 178: Return "Desktop White"
    Case 179: Return "Lozenge Green"
    Case 180: Return "Window Green"
    Case 181: Return "Plexiglass Green"
    Case 182: Return "Fishbowl Green"
    Case 183: Return "Sea Green"
    Case 184: Return "Imelda Shoe Blue"
    Case 185: Return "Braindead Blue"
    Case 186: Return "Saphhire"
    Case 187: Return "Fluffy Blue"
    Case 188: Return "Barbacide Blue"
    Case 189: Return "Medium Blue"
    Case 190: Return "Eye Blue"
    Case 191: Return "Broken Toe Purple"
    Case 192: Return "Grape"
    Case 193: Return "Big Stupid Dinosaur Purple"
    Case 194: Return "Paul's Wardobe, circa 82"
    Case 195: Return "Wizard Purple"
    Case 196: Return "Cotes du Rhone"
    Case 197: Return "Shamelss Bruise Purple"
    Case 198: Return "Sea Badger Purple"
    Case 199: Return "Fantasy Dream #4"
    Case 200: Return "Wedding in Reno Purple"
    Case 201: Return "Pepto"
    Case 202: Return "Watermelon"
    Case 203: Return "Lollipop"
    Case 204: Return "Fake Blood Red"
    Case 205: Return "Autumnal Splendor"
    Case 206: Return "Pink"
    Case 207: Return "Disco Shoe Pink"
    Case 208: Return "Valentine Pink"
    Case 209: Return "Bunny Slippers"
    Case 210: Return "Cute Rodent Pink"
    Case 211: Return "Warm Fuzzy"
    Case 212: Return "Darker Warm Fuzzy"
    Case 213: Return "Broken Heart"
    Case 214: Return "Not Chartreuse"
    Case 215: Return "Burgundy but lighter"
    Case 216: Return "Isnt this Magenta?"
    Case 217: Return "Definitely Not Indigo"
    Case 218: Return "Cheap Virtual Pet Purple"
    Case 219: Return "Wicked Lipstick Purple"
    Case 220: Return "Stop holding your breath"
    Case 221: Return "Red Wine"
    Case 222: Return "Goldfish Shoe Yellow"
    Case 223: Return "Aged Goldfish"
    Case 224: Return "Decaying Goldfish"
    Case 225: Return "Dishwater"
    Case 226: Return "Grilled Banana"
    Case 227: Return "Orange - Sorta"
    Case 228: Return "Business Suit"
    Case 229: Return "Plaid"
    Case 230: Return "Top Secret Badge Blue"
    Case 231: Return "Angry Revolutionary Red"
    Case 232: Return "Neon Orange"
    Case 233: Return "Boring Academic Yellow"
    Case 234: Return "Oncoming Headlight Yellow"
    Case 235: Return "REALLY White"
  End Select
End Function

' Abs (Function)
' The Abs function returns the absolute value of any integer. That is, negative
' numbers are returned as positives.

' AND (Logical Operator)
' When doing comparisons, like in an If command or a While command, the
' expression evaluated for TRUE or FALSE is a boolean expression. Boolean
' expressions can be combined using Logical Operators. AND is one such logical
' operator. It can be used to create an expression that is made up of two other
' expressions. If expression 1 is TRUE AND expression 2 is TRUE, then the full
' expression is considered to be TRUE. If either one of the other expressions is
' FALSE, or if both are FALSE, then the full expression is FALSE.

' ArcCos (Function)
' The ArcCos function computes the arc cosine of an angle, expressed in radians.
' ArcCos can only receive values between -1 and 1.

' ArcSin (Function)
' The ArcSin Function returns the arc sine of an angle, expressed in radians.
' ArcSin can only receive values between -1 and 1.

' ArcTan (Function)
' The ArcTan Function returns the arc tangent of an angle, expressed in radians.
' ArcTan can only receive values between -1 and 1.

' Asc (Function)
' The ASC function returns the ASCII numeric value of the first character in a
' string.

' LTPB Command
' The Background command places a graphic image in the run window.
Sub Background(BackFile As String)
  If FileExists(BackFile) Then
	  Dim As String Ext=UCase(Right(BackFile, 3))
    If Ext="BMP" Then Canvas.BackImage=BMP_Load(BackFile)
    If Ext="PNG" Then Canvas.BackImage=PNG_Load(BackFile)

    Put(0, 0), Canvas.BackImage, Alpha
  EndIf
End Sub

' LTPB Command
' The Banner command scrolls a string across the middle of the run window.
Sub Banner(Text As String)

End Sub

' LTPB Function
' The Button function returns a value of TRUE when the mouse button is clicked.
Function Button As Boolean
	Dim Rat As MouseType
  RatUpdate Rat: Return Rat.ButtonRat
End Function

' Chr$ (Function)
' The Chr$ function will return the character represented by the given ASCII
' code.

' Circle (Command)
' The Circle command will draw a circle on the screen of a given size. The color
' of the circle is the color specified by the Color command.

' LTPB Function
' The ClickRect function will return TRUE if the last place the mouse button was
' clicked falls within the given rectangle.
Function ClickRect(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer) As Boolean
  Dim Rat As MouseType
  RatUpdate Rat

  If Rat.ButtonRat And MouseRect(x1, y1, x2, y2)<>0 Then _
    Return _LTPB_TRUE_ Else Return _LTPB_FALSE_
End Function

' Cls (Command)
' The CLS command will clear the output window. This will remove all text and
' graphics, and position the text cursor in the upper left-hand corner.

' LTPB Command
' The Color command is used to set the current drawing color that will be used
' for points, lines, rectangles, and circles. There are 236 colors available to
' use, and each color has an associated number.
Sub LTPB_Color(iColour As Integer)
	Canvas.ColorMain=LTPB_Colors(iColour)
End Sub

' Cos (Function)
' The Cos function computes the Cosine of an angle. If you have learned
' trigonometry in school, then you may have learned about sines, cosines, and
' tangents.

' LTPB Command
' A sprite set can contain one or more frames or images. Often, these images are
' meant to be shown in sequence in order to produce animation. The CycleSprite
' command begins changing the displayed frame of a sprite in sequence.
Sub CycleSprite(SprName As SpriteType, Options As String="", Opt1 As Integer=0)
  SprName.Cycle=_LTPB_TRUE_
  If UCase(Options)="SPEED" Then SprName.EndTimer=(60\Opt1)*16.6
End Sub

' Data (Command)
' The Data statement allows you to provide information to the program that it can
' refer to later. The information given to a program can be either numbers or
' strings. Information is retrieved from the Data statements by using the Read
' command.

' Dim (Command)
' The Dim statement is what you use to declare an array. An array is a list of
' data elements that can be either strings or numbers. The Dim statement lets you
' create this list, and how large it will be. ‘Dim’ is short for dimension, or
' size.

' LTPB Command
' DrawText is a command that allows you more control over font, size, and style
' than the normal Print command does.

' Here’s a list of all the tags you can use:
' Mark the beginning or end of tags with: @
' Specify one of these fonts:
' HELVETICA
' TIMES
' COURIER

' Specify the point size for the font using any whole number, like:
' 10
' 12
' 24
' 33
' 72
' (etc.)

' Specify a font style:
' BOLD
' ITALIC
' UNDERLINE

' Specify one of the following colors by name:
' RED
' BLUE
' BLACK
' GREEN

' Specify any Learn To Program BASIC color by color number:
' COLOR 72
' COLOR 21
' COLOR 133
' (etc.)

' Specify a new line (line feed): LF
' "micro-linefeed" two pixels down: #
' You separate each tag with a comma. You can combine attributes in any logical
' combination. Like this:

' DrawText "@16,HELVETICA,COLOR 100,ITALIC,UNDERLINE@This is a test!" At 100,100
Sub LTPB_Drawtext(Options As String)
	
End Sub

' Else (Command)
' The Else command is an optional extension to the If statement, provided that
' the If statement is in block format. The If command is in block format if there
' is no statement immediately following the Then command on the same line. See
' the If command reference for more information about the block format.

' End (Command)
' The program stops running when it encounters an End statement. The End
' statement is used to mark the end of execution for a program. This is not
' necessarily at the end of the written code.

' Endif (Command)
' The EndIf command is used to mark the end of an If statement that is in block
' format. Block format allows you to specify more than one statement to be
' executed as a result of the If function. See the If reference for more
' information about the block format.

' FALSE (Predefined Value)
' In Learn To Program BASIC, FALSE is defined to be the value 0. A TRUE/FALSE
' expression (known as a Boolean expression) is considered FALSE if the
' expression results in zero, and TRUE if the value of the expression is not
' zero. TRUE and FALSE are pre-defined to the values of one and zero because it’s
' easier to understand programs that have names that define what they mean, and
' these values are used often in this way.

' FileClose (Command)
' FileClose will close an opened file. Files that are opened with FileOpen must
' be closed when you are through with them.

' FileOpen (Command)
' This command opens up a file on your hard drive for reading and writing. It
' requires a filename and then a comma, followed by one or more of these
' keywords:

' NEW: Create the new file; if EXIST not present, return an error if it already
' exists

' EXIST: Open an existing file; if NEW not present, return an error if it
' doesn’t exist

' APPEND: Add to the end of an existing file 0-9: Specify a file reference to
' identify this file

' A file that is created will appear in the User folder, where Learn To Program
' BASIC is installed on your hard drive. Only files in the User folder can be
' opened.

' FileRead (Command)
' The FileRead statement reads data in from an opened file. It accepts a single
' string or numeric variable, and optionally a file reference. If a file
' reference isn’t provided, it defaults to zero. If a string variable is
' provided, then the next line of data in the file will be read up to a carriage
' return. If a numeric variable is provided, a number must be read in from the
' file or an error will occur. In other words, string variables can read in all
' types of data from a file, but number variables can only read in numbers.

' FileWrite (Command)
' FileWrite writes data to a file. If a previously made file was opened with the
' Append parameter, this command will add data on to the end of the file.
' Otherwise, it will erase any existing data and start from the beginning.

' LTPB Command
' The FillCircle command will draw a solid circle on the screen of a given size.
' The color of the circle is the color specified by the Color command.
Sub FillCircle(x As Integer, y As Integer, r As Double)
	Circle(x, y), r, Canvas.ColorMain, , , , f
End Sub

' LTPB Command
' The FillRect command will draw a solid rectangle on the screen between two
' coordinate points. The color of the rectangle is the color specified by the
' Color command.
Sub LTPB_FillRect(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer)
	Line(x1, y1)-(x2, y2), Canvas.ColorMain, bf
End Sub

' For (Command)
' A For / Next loop is a very common type of loop used in BASIC. A loop is a
' section of code that executes over and over until some condition causes the
' loop to stop repeating. A For / Next loop is a loop designed to execute a
' certain number of times.

' LTPB Command
' The FreeSound command will release the memory used by a previous LoadSound
' command. You normally do not need to use this command, because all loaded
' sounds are freed automatically when the program ends. However, if you feel you
' can use more memory (for other sounds or sprites, for example) by freeing up a
' loaded sound that is no longer used, you might want to use this command.
Sub FreeSound
	
End Sub

' LTPB Command
' The FreeSprite command will "unload" a sprite from memory that was loaded by
' the LoadSprite command.
Sub FreeSprite(SprName As SpriteType)
  For t As Integer=0 To SprName.NumFrames
    ImageDestroy SprName.Frame(t)
  Next
End Sub

' LTPB Command
' This function will return the current frame number being displayed by a sprite.
' Sprite frame numbers start with zero.
Function GetSpriteFrame(SprName As SpriteType) As Integer
  Return SprName.CurFrame
End Function

' LTPB Command
' This function will return the total number of frames that make up a sprite.
' Sprites may contain one or more frames. Sprite frame numbers start with zero.
Function GetSpriteNumFrames(SprName As SpriteType) As Integer
  Return SprName.numFrames-1
End Function

' Gosub Command
' The Gosub command is used to call a subroutine. A subroutine is a section of
' code that can be repeated over and over. You call a subroutine by using the
' Gosub command.

' Goto (Command)
' Goto is a command that will cause the program to jump to somewhere else in the
' code and start running. The location to jump to is defined by a label. Unlike
' the Gosub command, the code will not return. The program simply begins
' execution at the new label.

' LTPB Command
' The HideSprite command is used to "turn off" a sprite so that it is no longer
' visible. You can turn it back on again with ShowSprite.
Sub HideSprite(SprName As SpriteType)
  SprName.Show=_LTPB_FALSE_
End Sub

' Home (Command)
' The Home command positions the text cursor to the upper-left corner without
' clearing the screen. This is equivalent to the command Position 0,0.

' If (Command)
' The If statement is the principal decision maker of BASIC. It evaluates an
' expression to see if its TRUE or FALSE. If the expression is TRUE, the
' statement following the Then command is executed. If the expression is FALSE,
' then the statement is skipped.

' Inkey$ Function
' The Inkey$ function will return the last key pressed on the keyboard.

' Input (Command)
' The Input command will present a cursor to the user and wait for a response to
' be typed from the keyboard. The user completes his entry by pressing the Enter
' (Return) key. The result is stored into a variable.

' Instr (Function)
' The InStr function is used to tell if a small string is part of a larger
' string, and where. It’s like a search command. InStr returns the position from
' the start of the larger string that the smaller string is found. If the smaller
' string is not part of the larger string, a zero is returned.

' Int (Function)
' The Int function returns the integer value of a number. An integer is a value
' that does not have a fractional part. In other words, if you have a value like
' 8.125 then it’s integer part is 8. A value of 5429.9999 has an integer value of
' 5429.

' LTPB Function
' The PlaySound and LoopSound functions return a channel value. This identifies
' which sound channel the sound was played on. You can tell whether or not a
' sound channel is still playing the last sound it was given with the
' IsChannelPlaying function.
Function IsChannelPlaying As Boolean
	Return 0
End Function

' LTPB Function
' The KeyDown function is used to test to see if a specific key is being pressed
' or not at the time the function is executed.
Function LTPB_KeyDown As Boolean
' For special keys, use a string that consists of one of these identifiers:
' "shift" "f4" "ins" "curright" "pad1"
' "control" "f5" "del" "numlock" "pad2"
' "space" "f6" "home" "pad/" "pad3"
' "enter" "f7" "end" "pad*" "pad4"
' "backspace" "f8" "pgup” "pad-" "pad5"
' "escape" "f9" "pgdn" "pad+" "pad6"
' "f1" "f10" "curup" "pad." "pad7"
' "f2" "f11" "curdown" "padenter" "pad8"
' "f3" "f12" "curleft" "pad0" "pad9"
	
	Return 0
End Function

' Left$ (Function)
' The Left$ function will pull characters off of the left hand side of string,
' and return the resulting string.

' Len (Function)
' The Len function returns the length of a string.

' Let (Command)
' The Let command assigns a value to a variable.

' Line (Command)
' The Line command will draw a line between two coordinates.

' LTPB Function
' The LoadSound function will load a sound file into memory, but does not play it
' yet. It can be played later with the PlaySound or LoopSound functions.
Function LoadSound As Boolean
	Return 0
End Function

' LTPB Command
' The LoadSprite function will load a sprite set from disk and put it into the
' computer's memory so that it may be used with other sprite commands, such as
' SetSprite. The LoadSprite function returns a value that is used To uniquely
' identify the sprite. This value is called the sprite reference.
Sub LoadSprite(SprFile As String)
  If FileExists(SprFile) Then

  EndIf
End Sub

' LTPB Function
' The LoopSound command is very similar to the PlaySound command, except that
' this command will play the sound repeatedly until either the program ends, or a
' StopChannel command ends playback on the channel it is playing on. See the
' description of the PlaySound command for more information.
Function LoopSound As Boolean
	Return 0
End Function

' LTPB Function
' The Lower$ function will convert a string to all lower case letters.
Function Lower(Text As String) As String
	Return LCase(Text)
End Function

' LTPB Command
' MakeSprite is an advanced command that you can use to create your own sprite
' and background files.
Sub MakeSprite(SpriteFile As String, x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer, _
	             TransColor As ULong, Options As String)

  Dim As String Header
  Dim As String SaveData=PixelString(x1, y1, x2, y2)

  ' Number of Frames
  ' Width and Hight
  ' Sprite Frame Pixels
  
	If UCase(Options)="REPLACE" Then
		Dim As Integer ff=FreeFile
		Open SpriteFile For Binary As #ff
		  Header="SIF"+Chr(1)+Chr(x2-x1)+Chr(y2-y1)
		  Put #ff, , Header+SaveData
		Close #ff
	Else
		If FileExists(SpriteFile) Then
			Dim As Integer ff=FreeFile
		  Open SpriteFile For Binary As #ff
		    Dim As String Header=Space(Lof(ff))
		    Get #ff, , Header
		  Close #ff
		EndIf
		
		' Increment the Frame Counter
		Mid(Header, 4, 1)=Chr(Asc(Mid(Header, 4, 1))+1)
		
	  Dim As Integer ff=FreeFile
    Open SpriteFile For Binary As #ff
		  Put #ff, , Header+SaveData
		Close #ff
	EndIf
End Sub

' Mid$ (Function)
' The Mid$ function will return a number of characters from a specified string
' variable. The string variable, the starting character, and the number of
' characters to pull are identified in the MID$ expression.
 
' Mod (Operator)
' Mod returns the leftover remainder of a quotient. This remainder is expressed
' as an integer. For example, 10 divided by 3 is equal to 3, with a remainder of
' 1.

' LTPB Function
' The RatRect function returns a value of TRUE when the mouse cursor is located
' in the specified rectangle.
Function MouseRect(x1 As Integer, y1 As Integer, _
                   x2 As Integer, y2 As Integer) As Boolean

  Dim Rat As MouseType
  RatUpdate Rat

  If (Rat.xRat>=x1 And Rat.xRat<=x2) And (Rat.yRat>=y1 And Rat.yRat<=y2) Then _
    Return _LTPB_TRUE_ Else Return _LTPB_FALSE_
End Function

' LTPB Function
' The MouseX function returns the X coordinate value of the current mouse
' location.
Function MouseX As Integer
  Dim Rat As MouseType
  RatUpdate Rat: Return Rat.xRat
End Function

' LTPB Function
' The MouseY function returns the Y coordinate value of the current mouse
' location.
Function MouseY As Integer
  Dim Rat As MouseType
  RatUpdate Rat: Return Rat.yRat
End Function

' Movie (Command)
' The Movie command displays a QuickTime file in the run window. The movie played
' always occupies the entire run window.

' Next (Command)
' The Next Command advances the counting variable in a For/Next loop expression.
' The Next command always works in conjunction with the For command.

' OR (Logical Operator)
' When doing comparisons, like in an If command or a While command, the
' expression evaluated for TRUE or FALSE is a boolean expression. Boolean
' expressions can be combined using Logical Operators. OR is one such logical
' operator. It can be used to create an expression that is made up of two other
' expressions. If expression 1 is TRUE OR expression 2 is TRUE, then the full
' expression is considered to be TRUE. If both expressions are FALSE, then the
' full expression is FALSE.

' LTPB Command
' PasteSprite allows you to put a sprite onto the background layer of the Run
' Window. Normally, sprites "float" above the other graphics on the screen. If
' you use the PasteSprite command, though, you can "draw" an image of the sprite
' on the same layer as your backgrounds, Lines, Circles, and Rects.
Sub PasteSprite(SprName As SpriteType)
  Put(SprName.xSprite, SprName.ySprite), SprName.Frame(SprName.CurFrame), Alpha
End Sub

' LTPB Function
' PGet returns the color value of any specified pixel coordinate. So, you could
' have a background image shown in the run window, and if you wanted to check the
' color of a pixel in that image, you could use the PGet function.
Function PGet(x As Integer, y As Integer) As Integer
	For t As Integer=1 To 235
		If LTPB_Colors(t)=Point(x, y) Then Return t
	Next
End Function

' LTPB Function
' The Random function generates a random number. The number generated lies within
' a range, specified by an upper and lower boundary.
Function LTPB_Random(Start As Integer, Finish As Integer) As Integer
	Dim As Integer Length=Finish-Start
	Return Int(Length*Rnd)
End Function

' LTPB Function
' PlaySound plays a sound from memory, so it can respond faster. The computer
' does not have to spend the time finding the file on the disk before it can play
' it. This makes it ideal for sound effects that you want to play several times
' in the same program.
Function LTPB_PlaySound As Boolean
	Return 0
End Function

' LTPB Command
' The Position command places text at specified location in the run window. That
' is, when you output text to the run window, it doesn’t always have to appear in
' the upper-left corner of the run window. You can place it anywhere you like
' with the Position command.
Sub Position(x As Integer, y As Integer)
	Locate y, x: Print "";
End Sub

' Print (Command)
' The Print command prints a value, variable, or string in the run window.
' Strings are always enclosed in quotation marks, whereas values and variables
' are not.

' PSet (Command)
' The PSet command places one pixel in the run window at a specified location.
' The location specified is done so with an X,Y coordinate value.

' Read (Command)
' The Read command grabs the next piece of data from the Data statements, and
' places it into a variable. This is how Data statements get used by your
' program.

' LTPB Command
' The Rect command will draw a rectangle on the screen between two coordinate
' points. The color of the rectangle is the color specified by the Color command.
Sub Rect(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer)
	Line(x1, y1)-(x2, y2), Canvas.ColorMain, b
End Sub

' Rem (Command)
' A Rem command is used to enter a comment into the program. The command ‘Rem’ is
' short for the word ‘Remark’.

' LTPB Command
' ResumeUpdate is used to restore output to the screen after a SuspendUpdate
' command is given. See SuspendUpdate for an explanation of this technique.
Sub ResumeUpdate
	ScreenUnLock
End Sub

' Restore (Command)
' The Restore command will “rewind” the Data statements, resetting them so that
' the next Read statement will once again read from the first piece of data in
' the list.

' Return (Command)
' Return will return from a subroutine, sending the program back to the line
' following the Gosub command that called the subroutine.

' Right$ (Function)
' The Right$ function will pull characters off of the right hand side of string,
' and return the resulting string.

' SetDrawLayer (Command)
' The SetDrawLayer command will allow you to take advantage of the
' multiple-layered screen that Learn To Program BASIC uses.

' LTPB Command
' The SetSprite command manipulates a loaded sprite set. This command can adjust
' several properties of a sprite, including position, it's current frame, the
' range of frames it will cycle through, and whether it is flipped or not. These
' properties are enabled using the To, Frame, Range, Flipped and Normal words.
Sub SetSprite(SprName As SpriteType, Options As String, Opt1 As Integer, Opt2 As Integer=0)
  Options=UCase(Options)

  Select Case Options
  	Case "TO"
  		SprName.xSprite=Opt1: SprName.ySprite=Opt2
  	
  	Case "FRAME"
  		SprName.CurFrame=Opt1
  	
  	Case "RANGE"
  		SprName.RangeS=Opt1: SprName.RangeF=Opt2
  	
  	Case "FLIP"
  	  If Right(Options, 1)="H" Then SprName.Flipped=1: 'FlipSprite 0
  	  If Right(Options, 1)="V" Then SprName.Flipped=2: 'FlipSprite 180
  	  
  	Case "NORMAL"
  		' FlipSprite 180*SprName.Flipped
  End Select
End Sub

' SetTextLayer (Command)
' The SetTextLayer command will allow you to put text onto the background,
' instead of the independent text layer it normally appears in.

' LTPB Command
' Makes a sprite visible on the screen. This can be used in conjunction with the
' HideSprite command to control when a sprite is displayed.
Sub ShowSprite(SprName As SpriteType)
  SprName.Show=_LTPB_TRUE_
End Sub

' Sin (Function)
' The Sin function computes the sine of an angle. If you have learned
' trigonometry in school, then you may have learned about sines, cosines, and
' tangents.

' Sleep (Command)
' The Sleep command will put a delay in your program. It is followed by a number
' which is the length of the delay, in tenths of a second. So the statement:
' Sleep 20 Would cause the computer to pause (or ‘go to sleep’), for 2 seconds.

' Sound (Command)
' Using this command will play a digitized sound file through your computer. The
' file must be in the AIFF sound file format. The file name must contain the
' extension .AIF in order for it to appear in the Choose It box.
Sub Sound(SoundFile As String)

End Sub

' LTPB Function
' The SpriteHitPoint function will test if a sprite is touching a point on the
' screen. It accepts the sprite set number and the X/Y coordinates of the point
' to be checked as arguments. If the point lies within the sprite, then the
' function will return TRUE. If not, the returned value is FALSE.
Function SpriteHitPoint(SprName As SpriteType, x As Integer, y As Integer) As Boolean
  If (x>=SprName.xSprite And x<=SprName.xSprite+SprName.wSprite) And  _
     (y>=SprName.ySprite And y<=SprName.ySprite+SprName.hSprite) Then _
    Return _LTPB_TRUE_ Else Return _LTPB_FALSE_
End Function

' LTPB Function
' The SpriteHitSprite function will test if any two sprites have collided with
' one another. If the sprites overlap, then the function will return TRUE. If
' not, the returned value will be FALSE.
Function SpriteHitSprite(SprName1 As SpriteType, SprName2 As SpriteType) As Boolean
  Dim As Integer x1=SprName1.xSprite
  Dim As Integer y1=SprName1.ySprite
  Dim As Integer x2=SprName1.xSprite+SprName1.wSprite
  Dim As Integer y2=SprName1.ySprite+SprName1.hSprite

  Dim As Integer x3=SprName2.xSprite
  Dim As Integer y3=SprName2.ySprite
  Dim As Integer x4=SprName2.xSprite+SprName2.wSprite
  Dim As Integer y4=SprName2.ySprite+SprName2.hSprite

  If x2>=x3 Or x1<=x4 Or y2>=y3 Or y1<=y4 Then _
  	Return _LTPB_TRUE_ Else Return _LTPB_FALSE_
End Function

' Sqr (Function)
' This is a math function that will return the square root of any positive
' number.

' LTPB Command
' StopChannel will stop any current sound playback on the given sound channel.
' This can be used to stop a sound short, or to end a looping sound.
Sub StopChannel
	
End Sub

' LTPB Command
' The StopSprite command will halt the effects of a CycleSprite command. Use the
' two commands together to control the animation of a sprite.
Sub StopSprite(SprName As SpriteType)
  SprName.Cycle=_LTPB_FALSE_
End Sub

' Str$ (Function)
' The Str$ function will accept a number as an argument and return that number as
' a string. This is useful if you need to pass the text of the number into
' functions that are meant to work on strings and not number values.

' LTPB Command
' When you put something in the Run Window with a graphic command, or a text or
' sprite command, the image is recorded in memory as well as displayed on the
' screen. SuspendUpdate will allow you to ‘turn off’ the output to the screen so
' that you can draw or print several things without them appearing yet. When you
' issue a ResumeUpdate command, everything you drew will appear at once.
Sub SuspendUpdate
	ScreenLock
End Sub

' Tan (Function)
' The Tan function computes the tangent of an angle. If you have learned
' trigonometry in school, then you may have learned about sines, cosines, and
' tangents.

' LTPB Command
' The TextColor command will change the color of all text printed with the Print
' and Banner commands. Use this to lend variety to your printed text. To change
' the color of graphics, use the Color command.
Sub TextColor(iColour As Integer)
	Canvas.ColorText=LTPB_Colors(iColour)
End Sub

' Then (Command)
' Then is used in conjunction with the If command to create an If/Then statement.
' For details on usage, see the If command.

' To
' The ‘TO’ keyword is used as part of a few different commands, such as For,
' Line, Rect, and SetSprite. To is not a command per se. Instead, it is a
' supporting keyword that is used within the syntax of these other commands.

' TRUE (Predefined Value)
' In Learn To Program BASIC, TRUE is defined to be the value 1. In fact, a
' TRUE/FALSE expression (known as a boolean expression) is considered TRUE if the
' value of the expression is not zero. TRUE and FALSE are predefined to the
' values of one and zero because it’s easier to understand programs that have
' names that define what they mean, and these values are used often in this way.

' LTPB Function
' Upper$ is a function that will convert a string into all upper-case text.
Function Upper(Text As String) As String
	Return UCase(Text)
End Function

' Val (Function)
' Val will convert a string into a number. The statement Val("1500") would return
' the number 1500, because the string represents a valid number. The command
' Val("Tiger") will return a 0 because the word "Tiger" is not a number.

' Wend (Command)
' Wend closes up the bottom of a While/Wend loop. For more information and an
' example, see While.

' While (Command)
' The While command defines the first part of a While/Wend loop. An expression
' follows the While command. The computer will repeatedly execute whatever it
' finds between the While and the Wend commands for as long as this expression
' remains TRUE. This is known as a Conditional Loop.

' XOR (Logical Operator)
' When doing comparisons, like in an If command or a While command, the
' expression evaluated for TRUE or FALSE is a boolean expression. Boolean
' expressions can be combined using Logical Operators. XOR is one such logical
' operator. It can be used to create an expression that is made up of two other
' expressions.

#EndIf __LTPB_BI__
angros47
Posts: 2329
Joined: Jun 21, 2005 19:04

Re: Sprites and LTPB

Post by angros47 »

NorbyDroid wrote: Dec 18, 2023 15:35 Without help I am unable to do any of the sound commands. Any help will be appreciated.
Can my sfx library help? https://www.freebasic.net/wiki/ExtLibsfx

I don't know how sound worked in LTPB, if you tell me more maybe I can help you implementing something similar.
Post Reply