GraphicsWindow.Title = "Bowling Game 0.4a - Hit arrow keys."
Init()
GraphicsWindow.KeyDown = OnKeyDown
While "True"
InitBall()
Position() ' for the first throwing
ThrowBall()
SelectPins() ' to blow
BlowPins()
InitBall()
Position() ' for the second throwing
ThrowBall()
SelectPins() ' to blow
BlowPins()
InitPins()
EndWhile
Sub BlowPins
For t = 0 To 1000 Step delay
For i = 1 To 10
If fell[i] Then
x[i] = x[i] + dx[i]
y[i] = y[i] - 5
a[i] = a[i] + da[i]
Shapes.Move(pin[i], x[i], y[i])
Shapes.Rotate(pin[i], a[i])
EndIf
EndFor
If ye <= yb Then
MoveBall()
yb = yb - 2
EndIf
Program.Delay(delay)
EndFor
Shapes.HideShape(ball)
For i = 1 To 10
If fell[i] Then
Shapes.HideShape(pin[i])
EndIf
EndFor
EndSub
Sub Init
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
da = "1=-10;2=-8;3=8;4=-6;5=-6;6=6;7=-4;8=-4;9=4;10=4;"
dx = "1=-3;2=-4;3=4;4=-5;5=-3;6=5;7=-5;8=-4;9=4;10=5;"
GraphicsWindow.BackgroundColor = "LightGray"
' draw gutter
GraphicsWindow.BrushColor = "SaddleBrown"
color = GraphicsWindow.BrushColor
rate = 0.5
Colors_Init()
Color_Blacken()
GraphicsWindow.BrushColor = color
GraphicsWindow.FillTriangle(gw / 2, 0, -70, gh, gw + 70, gh)
' draw lane
ye = 170
GraphicsWindow.BrushColor = "SaddleBrown"
GraphicsWindow.FillTriangle(gw / 2, 0, 0, gh, gw, gh)
GraphicsWindow.BrushColor = "LightGray"
GraphicsWindow.FillRectangle(0, 0, gw, ye)
GraphicsWindow.BrushColor = "Black"
path = "http://www.nonkit.com/smallbasic.files/Pin.png"
i = 6
d = 3
For row = 4 To 1 Step -1
y = 100 - row * 10
For col = 1 To row
i = i + 1
pin[i] = Shapes.AddImage(path)
x = 249 + col * 60 - row * 30
Shapes.Move(pin[i], x, y)
EndFor
i = i - row - d
d = d - 1
shadow = Shapes.AddRectangle(366, 160)
Shapes.SetOpacity(shadow, 15)
Shapes.Move(shadow, 116, 52)
EndFor
shadow = ""
' draw wall
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "GreenYellow"
wall = Shapes.AddRectangle(gw, 52)
Shapes.Move(wall, 0, 0)
wall = Shapes.AddRectangle(116,160)
Shapes.Move(wall, 0, 52)
wall = Shapes.AddRectangle(149, 160)
Shapes.Move(wall, gw - 116, 52)
delay = 10 ' [ms]
EndSub
Sub InitBall
xb = gw / 2 ' ball position
yb = gh + 120
ab = 120 ' ball angle
DrawBall()
EndSub
Sub InitPins
For i = 1 To 10
Shapes.Move(pin[i], x0[i], y0[i])
Shapes.Rotate(pin[i], 0)
Shapes.ShowShape(pin[i])
EndFor
EndSub
Sub MoveBall
' param xs - ball start x position
xb = (gw / 2) * (1 - yb / gh) + xs * yb / gh
ab = ab - 4
DrawBall()
Program.Delay(delay)
EndSub
Sub OnKeyDown
keyDown = "True"
EndSub
Sub Position
Shapes.ShowShape(ball)
positioning = "True"
While positioning
If keyDown Then
If GraphicsWindow.LastKey = "Up" Then
positioning = "False"
ElseIf GraphicsWindow.LastKey = "Left" Then
If 0 <= xb - 10 Then
xb = xb - 10
DrawBall()
EndIf
ElseIf GraphicsWindow.LastKey = "Right" Then
If xb + 10 <= gw Then
xb = xb + 10
DrawBall()
EndIf
EndIf
keyDown = "False"
EndIf
EndWhile
EndSub
Sub SelectPins
For i = 1 To 10
If Math.Remainder(Math.GetRandomNumber(2), 2) = 0 Then
fell[i] = "True"
Else
fell[i] = "False"
EndIf
If x0[i] = "" Then
x0[i] = Shapes.GetLeft(pin[i])
EndIf
If y0[i] = "" Then
y0[i] = Shapes.GetTop(pin[i])
EndIf
x[i] = x0[i]
y[i] = y0[i]
a[i] = 0
EndFor
EndSub
Sub ThrowBall
Shapes.ShowShape(shadow)
xs = xb
For yb = gh - 1 To 208 Step -2
MoveBall()
EndFor
Shapes.HideShape(shadow)
EndSub
Sub Color_Blacken
' Color | Blacken given color
' param color - given color
' param rate - 0..1
' return color - color blackened
Color_NameToColor()
Color_ColorToRGB()
r = Math.Floor(r * (1 - rate))
g = Math.Floor(g * (1 - rate))
b = Math.Floor(b * (1 - rate))
color = GraphicsWindow.GetColorFromRGB(r, g, b)
EndSub
Sub Color_ColorToRGB
' Color | Convert color to RGB values
' param color - "#rrggbb" (hexadecimal values)
' return r, g, b - RGB values 0..255
sR = Text.GetSubText(color, 2, 2)
sG = Text.GetSubText(color, 4, 2)
sB = Text.GetSubText(color, 6, 2)
hex = sR
Math_Hex2Dec()
r = dec
hex = sG
Math_Hex2Dec()
g = dec
hex = sB
Math_Hex2Dec()
b = dec
EndSub
Sub Color_NameToColor
' Color | Convert color name to color
' param color - color name
' return color -"#rrggbb"
If Text.StartsWith(color, "#") Then
color = Text.ConvertToUpperCase(color)
Else
color = Text.ConvertToLowerCase(color)
color = colors[color]
EndIf
EndSub
Sub Math_Hex2Dec
' Math | Convert hexadecimal to decimal
' param hex
' return dec
dec = 0
len = Text.GetLength(hex)
For ptr = 1 To len
dec = dec * 16 + Text.GetIndexOf("123456789ABCDEF", Text.GetSubText(hex, ptr, 1))
EndFor
EndSub
Sub Text_Split
' Text | Split text to array by delimiter
' param txt - to split
' param delim - delimiter
' return arry - splitted
len = Text.GetLength(txt)
p = 1
n = 0
d = Text.GetIndexOf(Text.GetSubTextToEnd(txt, p), delim)
While (0 < d) And (p <= len)
n = n + 1
arry[n] = Text.GetSubText(txt, p, d - 1)
p = p + d
d = Text.GetIndexOf(Text.GetSubTextToEnd(txt, p), delim)
EndWhile
n = n + 1
arry[n] = Text.GetSubTextToEnd(txt, p)
EndSub