GraphicsWindow.Title = "Bowling Anime 0.3 - Hit arrow keys."
Init()
path = "http://www.nonkit.com/smallbasic.files/Ball.png"
GraphicsWindow.KeyDown = OnKeyDown
While "True"
x = gw / 2
y = gh + 120
a = 120
DrawBall()
positioning = "True"
While positioning
If keyDown Then
If GraphicsWindow.LastKey = "Up" Then
positioning = "False"
ElseIf GraphicsWindow.LastKey = "Left" Then
If 0 <= x - 10 Then
x = x - 10
DrawBall()
EndIf
ElseIf GraphicsWindow.LastKey = "Right" Then
If x + 10 <= gw Then
x = x + 10
DrawBall()
EndIf
EndIf
keyDown = "False"
EndIf
EndWhile
x0 = x
For y = gh - 1 To 212 Step -1
x = (gw / 2) * (1 - y / gh) + x0 * y / gh
a = a - 2
DrawBall()
Program.Delay(10)
EndFor
For i = 1 To 10
If Math.Remainder(Math.GetRandomNumber(2), 2) = 0 Then
fell[i] = "True"
Else
fell[i] = "False"
EndIf
y0[i] = Shapes.GetTop(pin[i])
x0[i] = Shapes.GetLeft(pin[i])
x[i] = x0[i]
y[i] = y0[i]
a[i] = 0
EndFor
For t = 0 To 1000 Step 20
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
Shapes.HideShape(pin[i])
Program.Delay(20)
EndFor
For i = 1 To 10
If fell[i] Then
Shapes.ShowShape(pin[i])
Shapes.Move(pin[i], x0[i], y0[i])
Shapes.Rotate(pin[i], 0)
EndIf
EndFor
EndWhile
Sub DrawBall
scale = y / 212
If shadow = "" Then
GraphicsWindow.BrushColor = "Black"
shadow = Shapes.AddEllipse(78, 20)
Shapes.SetOpacity(shadow, 50)
EndIf
Shapes.Move(shadow, x - 39, y - 10)
Shapes.Zoom(shadow, scale, scale)
If ball = "" Then
ball = Shapes.AddImage(path)
EndIf
Shapes.Move(ball, x - 39, y - 33 * scale - 39)
Shapes.Zoom(ball, scale, scale)
Shapes.Rotate(ball, a)
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
Color_Blacken()
GraphicsWindow.BrushColor = color
GraphicsWindow.FillTriangle(gw / 2, 0, -70, gh, gw + 70, gh)
' draw lane
GraphicsWindow.BrushColor = "SaddleBrown"
GraphicsWindow.FillTriangle(gw / 2, 0, 0, gh, gw, gh)
GraphicsWindow.BrushColor = "LightGray"
GraphicsWindow.FillRectangle(0, 0, gw, 140)
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)
EndSub
Sub OnKeyDown
keyDown = "True"
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
' returns 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