Microsoft Small Basic

Program Listing: CHW085-0
Sub initialize
GraphicsWindow.Width=640
GraphicsWindow.Height=480
GraphicsWindow.Title="Golf"
GraphicsWindow.BackgroundColor=Brown
GraphicsWindow.MouseDown=MouseDown
GraphicsWindow.MouseUp=MouseUp
GraphicsWindow.BrushColor="Gold"
GraphicsWindow.PenColor="Orange"
sopa=Shapes.AddRectangle(10,50)
GraphicsWindow.BrushColor="Black"
GraphicsWindow.PenColor="Black"
velx=0
vely=0
fade=100
irisrad=50
rad=200
power=0
maxLevel=2
speedx=0
speedy=0
EndSub
Sub settingUp
levels=1
Level[1][0]="tttttttsvttttttt"
Level[1][1]="t tvvt t"
Level[1][2]="t b tvvt h t"
Level[1][3]="t tvvt t"
Level[1][4]="t tvvt t"
Level[1][5]="t tvvt t"
Level[1][6]="t tvvt t"
Level[1][7]="t tttt t"
Level[1][8]="t t"
Level[1][9]="t t"
Level[1][10]="t t"
Level[1][11]="tttttttttttttttt"

Level[2][0]="vvvvvvvvvvvvvvvv"
Level[2][1]="vvvvvvvvvvvvvvvv"
Level[2][2]="tttttvvvsvvttttt"
Level[2][3]="t tttttttt h t"
Level[2][4]="t t"
Level[2][5]="t t"
Level[2][6]="t t"
Level[2][7]="t b tttttttt t"
Level[2][8]="tttttvvvvvvttttt"
Level[2][9]="vvvvvvvvvvvvvvvv"
Level[2][10]="vvvvvvvvvvvvvvvv"
Level[2][11]="vvvvvvvvvvvvvvvv"
EndSub
Sub level
Brown=GraphicsWindow.GetColorFromRGB(150,90,50)
DarkBrown=GraphicsWindow.GetColorFromRGB(100,50,30)
For i=0 To 16
For j=0 To 12
If Text.GetSubText(Level[levels][j],i,1)="t" Then
GraphicsWindow.BrushColor=DarkBrown
GraphicsWindow.PenColor=DarkBrown
Tile[i][j]=Shapes.AddRectangle(40,40)
Tilex[i]=i*40-40
Tiley[j]=j*40
Shapes.Move(Tile[i][j],Tilex[i],Tiley[j])
EndIf
If Text.GetSubText(Level[levels][j],i,1)="h" Then
GraphicsWindow.BrushColor="Green"
GraphicsWindow.FillRectangle(i*40-40,j*40,40,40)
GraphicsWindow.BrushColor="Black"
GraphicsWindow.PenColor="Lime"
hole=Shapes.AddEllipse(30,30)
hx=i*40-35
hy=j*40+5
Shapes.Move(hole,hx,hy)
EndIf
If Text.GetSubText(Level[levels][j],i,1)=" " Then
GraphicsWindow.BrushColor="Green"
GraphicsWindow.FillRectangle(i*40-40,j*40,40,40)
EndIf
If Text.GetSubText(Level[levels][j],i,1)="v" Then
GraphicsWindow.BrushColor="Black"
GraphicsWindow.FillRectangle(i*40-40,j*40,40,40)
EndIf
If Text.GetSubText(Level[levels][j],i,1)="s" Then
GraphicsWindow.FontSize=20
Pow=Controls.AddTextBox(i*40-40,j*40)
Controls.SetSize(Pow,40,40)
EndIf
EndFor
EndFor
For i=0 To 16
For j=0 To 16
If Text.GetSubText(Level[levels][j],i,1)="b" Then
GraphicsWindow.BrushColor="Green"
GraphicsWindow.FillRectangle(i*40-40,j*40,40,40)
GraphicsWindow.BrushColor="White"
GraphicsWindow.PenColor="Gray"
Ball=Shapes.AddEllipse(20,20)
x=i*40-30
y=j*40+10
Shapes.Move(ball,x,y)
EndIf
EndFor
EndFor
EndSub
Sub CheckColission
For i=0 To 16
For j=0 To 12
Tilex[i][j]=Shapes.GetLeft(Tile[i][j])
Tiley[i][j]=Shapes.GetTop(Tile[i][j])
If x+20>Tilex[i][j] and xTiley[i][j] and y plusx=x+20-Tilex[i][j]
plusy=y+20-Tiley[i][j]
collided="True"
If x+20=Tilex[i][j]+plusx or x=Tilex[i][j]+40-plusx Then
speedx=-velx
kx=speedx*0.01
kx=Math.Abs(kx)
EndIf
If y+20=Tiley[i][j]+plusy or y+vely=Tiley[i][j]+40-plusy Then
speedy=-vely
ky=speedy*0.01
ky=Math.Abs(ky)
EndIf
EndIf
EndFor
EndFor
dist=Math.SquareRoot(Math.Power(x-hx,2)+Math.Power(y-hy,2))
If dist<13 Then
fade=fade-10
k=Math.Abs((velx+vely)/2)
Shapes.SetOpacity(ball,fade)
If fade<10 Then
Shapes.Remove(ball)
If levels levels=levels+1
GraphicsWindow.Clear()
level()
initialize()
Else
GraphicsWindow.Clear()
GraphicsWindow.ShowMessage("Congrulations!","You WON!")
Program.End()
EndIf
EndIf
EndIf
EndSub
Sub MouseDown
down="True"
up="False"
EndSub
Sub MouseUp
down="False"
up="True"
EndSub
Sub getAngle
dx = GraphicsWindow.MouseX - x
dy = GraphicsWindow.MouseY - y
If (dx = 0) Then
angle = Math.Pi/2
If (dy < 0) Then
angle = -angle
EndIf
Else
angle = Math.ArcTan(dy/dx)
EndIf
If (dx < 0) Then
angle = angle+Math.Pi
EndIf
EndSub
Sub drawPower
Controls.SetTextBoxText(Pow,power)
EndSub
Sub movement
Shapes.Rotate(sopa,açı)
posx=Shapes.GetLeft(Ball)+irisrad/2
posy=Shapes.GetTop(Ball)+irisrad/2-15
distfromcenter = 50+(power*25)
yOnEyeball = Math.Sin(angle)*Math.Min(rad/2-irisrad/2,distfromcenter/3)
xOnEyeball = Math.Cos(angle)*Math.Min(rad/2-irisrad/2,distfromcenter/3)+5
Shapes.Move(sopa,posx+xOnEyeball-irisrad/2,posy+yOnEyeball-irisrad/2)
EndSub
settingUp()
level()
initialize()
While 1=1

x=x+velx
y=y+vely
CheckColission()
If collided Then
velx=speedx
vely=speedy
collided="False"
EndIf

kx=velx*0.01
ky=vely*0.01

velx=velx-kx
vely=vely-ky

If Mouse.IsLeftButtonDown And down And power<5 And notMoving Then
power=power+0.05
EndIf
If up And notMoving Then
velx=power*Math.Cos(angle)*-1
vely=power*Math.Sin(angle)*-1
notMoving="False"
power=0
EndIf
If math.Abs(velx)<0.01 And math.Abs(vely)<0.01 Then
notMoving="True"
Else
notMoving="False"
EndIf
If notMoving Then
Shapes.SetOpacity(sopa,100)
getAngle()
movement()
açı = Math.GetDegrees(angle)+15
Else
Shapes.SetOpacity(sopa,0)
EndIf
drawPower()
Shapes.Move(ball,x,y)
Program.Delay(10)
EndWhile