Microsoft Small Basic

Program Listing: RQB683-6
' Sprite - Rocket
' Version 0.6
' Copyright © 2019 Nonki Takahashi. The MIT License.
' 2013-07-10 16:10:22 Shapes generated by Shapes 1.5b
' Program ID RQB683-6

SB_Workaround()
name = "Rocket"
Init()
Shapes_Init_Rocket()
scale = 1
Group_Add()

Sub Init
GraphicsWindow.Title = "Sprite - " + name
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
EndSub

Sub Group_Add
' Group | add shapes to a group
' param name - group name
' param shX, shY - origin of shape array
' param scale - to resize
' param shape[] - shape array
' param nGroup - number of group
' return nGroup - updated number of group
' return group - group array
Stack.PushValue("local", i)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
nGroup = nGroup + 1
grp = ""
grp["name"] = name
grp["x"] = shX
grp["y"] = shY
grp["angle"] = 0
grp["dir"] = 1
Shapes_CalcWidthAndHeight()
grp["width"] = shWidth
grp["height"] = shHeight
grp["cx"] = shWidth / 2
grp["cy"] = shHeight / 2
s = scale
grp["scale"] = s
For i = 1 To Array.GetItemCount(shape)
shp = shape[i]
GraphicsWindow.PenWidth = shp["pw"] * s
If shp["pw"] > 0 Then
GraphicsWindow.PenColor = shp["pc"]
EndIf
If Text.IsSubText("rect|ell|tri|text|btn", shp["func"]) Then
GraphicsWindow.BrushColor = shp["bc"]
EndIf
If Text.IsSubText("text|btn", shp["func"]) Then
If silverlight Then
fs = Math.Floor(shp["fs"] * 0.9)
Else
fs = shp["fs"]
EndIf
GraphicsWindow.FontSize = fs * s
GraphicsWindow.FontName = shp["fn"]
If shp["fb"] = "False" Then
GraphicsWindow.FontBold = "False"
Else
GraphicsWindow.FontBold = "True"
EndIf
EndIf
If shp["func"] = "rect" Then
shp["obj"] = Shapes.AddRectangle(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "ell" Then
shp["obj"] = Shapes.AddEllipse(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "tri" Then
shp["obj"] = Shapes.AddTriangle(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s, shp["x3"] * s, shp["y3"] * s)
ElseIf shp["func"] = "line" Then
shp["obj"] = Shapes.AddLine(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s)
ElseIf shp["func"] = "text" Then
shp["obj"] = Shapes.AddText(shp["text"])
EndIf
x = shp["x"]
y = shp["y"]
shp["rx"] = x
shp["ry"] = y
If sbd And (shp["func"] = "line") Then
shp["wx"] = x
shp["wy"] = y
ElseIf silverlight And Text.IsSubText("tri|line", shp["func"]) Then
_alpha = Math.GetRadians(shp["angle"])
SB_RotateWorkaround()
shp["wx"] = x
shp["wy"] = y
EndIf
If shp["func"] = "btn" Then
shp["obj"] = Controls.AddButton(shp["caption"], shX + x * s, shY + y * s)
Else
Shapes.Move(shp["obj"], shX + x * s, shY + y * s)
EndIf
If Text.IsSubText("rect|ell|tri|text", shp["func"]) And (shp["angle"] <> 0) And (shp["angle"] <> "") Then
Shapes.Rotate(shp["obj"], shp["angle"])
EndIf
shape[i] = shp
EndFor
grp["shape"] = shape
group[nGroup] = grp
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub

Sub Group_Move
' Group | move a group
' param group[i] - group To move
' param x, y - position To move
' return group[i] - updated group
Stack.PushValue("local", j)
grp = group[i]
s = grp["scale"]
grp["x"] = x
grp["y"] = y
shape = grp["shape"]
n = Array.GetItemCount(shape)
For j = 1 To n
shp = shape[j]
If sbd And (shp["func"] = "line") Then
_x = shp["wx"]
_y = shp["wy"]
ElseIf silverlight And Text.IsSubText("tri|line", shp["func"]) Then
_x = shp["wx"]
_y = shp["wy"]
Else
_x = shp["rx"]
_y = shp["ry"]
EndIf
Shapes.Move(shp["obj"], grp["x"] + _x * s, grp["y"] + _y * s)
EndFor
group[i] = grp
j = Stack.PopValue("local")
EndSub

Sub Math_CartesianToPolar
' Math | convert cartesian coodinate to polar coordinate
' param x, y - cartesian coordinate
' return r, a - polar coordinate
r = Math.SquareRoot(x * x + y * y)
If x = 0 And y > 0 Then
a = 90 ' [degree]
ElseIf x = 0 And y < 0 Then
a = -90
Else
a = Math.ArcTan(y / x) * 180 / Math.Pi
EndIf
If x < 0 Then
a = a + 180
ElseIf x > 0 And y < 0 Then
a = a + 360
EndIf
EndSub

Sub SB_RotateWorkaround
' Small Basic | Rotate workaround for Silverlight
' param x, y - original coordinate
' param _alpha - angle [radian]
' returns x, y - workaround coordinate
If shape[i]["func"] = "tri" Then
x1 = -Math.Floor(shape[i]["x3"] / 2)
y1 = -Math.Floor(shape[i]["y3"] / 2)
ElseIf shape[i]["func"] = "line" Then
x1 = -Math.Floor(Math.Abs(shape[i]["x1"] - shape[i]["x2"]) / 2)
y1 = -Math.Floor(Math.Abs(shape[i]["y1"] - shape[i]["y2"]) / 2)
EndIf
ox = x - x1
oy = y - y1
x = x1 * Math.Cos(_alpha) - y1 * Math.Sin(_alpha) + ox
y = x1 * Math.Sin(_alpha) + y1 * Math.Cos(_alpha) + oy
EndSub

Sub SB_Workaround
' Small Basic | workaround for Silverlight / SBD
' return silverlight - "True" if in remote
' return sbd - "True" if Small Basic Desktop
color = GraphicsWindow.GetPixel(0, 0)
sbd = "False"
If Text.GetLength(color) > 7 Then
silverlight = "True"
msWait = 300
Else
silverlight = "False"
_gw = GraphicsWindow.Width
_gh = GraphicsWindow.Height
If (_gw = 624) And (_gh = 441) Then
sbd = "True"
EndIf
EndIf
EndSub

Sub Shapes_CalcRotatePos2
param = ""
' Shapes | Calculate position for rotated shape
' param["x"], param["y"] - position of a shape
' param["width"], param["height"] - size of a shape
' param ["cx"], param["cy"] - center of rotation
' param ["angle"] - rotate angle
' return x, y - rotated position of a shape
_cx = param["x"] + param["width"] / 2
_cy = param["y"] + param["height"] / 2
x = _cx - param["cx"]
y = _cy - param["cy"]
Math_CartesianToPolar()
a = a + param["angle"]
x = r * Math.Cos(a * Math.Pi / 180)
y = r * Math.Sin(a * Math.Pi / 180)
_cx = x + param["cx"]
_cy = y + param["cy"]
x = _cx - param["width"] / 2
y = _cy - param["height"] / 2
EndSub

Sub Shapes_CalcWidthAndHeight
' Shapes | calculate total width and height of shapes
' param shape[] - shape array
' return shWidth, shHeight - total size of shapes
For i = 1 To Array.GetItemCount(shape)
shp = shape[i]
If shp["func"] = "tri" Or shp["func"] = "line" Then
xmin = shp["x1"]
xmax = shp["x1"]
ymin = shp["y1"]
ymax = shp["y1"]
If shp["x2"] < xmin Then
xmin = shp["x2"]
EndIf
If xmax < shp["x2"] Then
xmax = shp["x2"]
EndIf
If shp["y2"] < ymin Then
ymin = shp["y2"]
EndIf
If ymax < shp["y2"] Then
ymax = shp["y2"]
EndIf
If shp["func"] = "tri" Then
If shp["x3"] < xmin Then
xmin = shp["x3"]
EndIf
If xmax < shp["x3"] Then
xmax = shp["x3"]
EndIf
If shp["y3"] < ymin Then
ymin = shp["y3"]
EndIf
If ymax < shp["y3"] Then
ymax = shp["y3"]
EndIf
EndIf
shp["width"] = xmax - xmin
shp["height"] = ymax - ymin
EndIf
If i = 1 Then
shWidth = shp["x"] + shp["width"]
shHeight = shp["y"] + shp["height"]
Else
If shWidth < shp["x"] + shp["width"] Then
shWidth = shp["x"] + shp["width"]
EndIf
If shHeight < shp["y"] + shp["height"] Then
shHeight = shp["y"] + shp["height"]
EndIf
EndIf
shape[i] = shp
EndFor
EndSub

Sub Shapes_Init_Rocket
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 208 ' x offset
shY = 154 ' y offset
shape = ""
shape[1] = "func=tri;x=22;y=0;x1=70;y1=0;x2=0;y2=96;x3=140;y3=96;bc=#752424;pc=#000000;pw=2;"
shape[2] = "func=tri;x=0;y=194;x1=21;y1=0;x2=0;y2=79;x3=42;y3=79;bc=#6E6E6E;pc=#000000;pw=2;"
shape[3] = "func=tri;x=142;y=193;x1=20;y1=0;x2=0;y2=80;x3=41;y3=80;bc=#6E6E6E;pc=#000000;pw=2;"
shape[4] = "func=tri;x=52;y=189;x1=41;y1=0;x2=0;y2=70;x3=82;y3=70;bc=#1F1F1F;pc=#000000;pw=2;"
shape[5] = "func=rect;x=21;y=96;width=143;height=144;bc=#6E6E6E;pc=#000000;pw=2;"
shape[6] = "func=tri;x=73;y=192;x1=20;y1=0;x2=0;y2=81;x3=41;y3=81;bc=#6E6E6E;pc=#000000;pw=2;"
shape[7] = "func=ell;x=51;y=101;width=84;height=88;bc=#6E6E6E;pc=#000000;pw=2;"
shape[8] = "func=ell;x=59;y=110;width=68;height=71;bc=#217DBB;pc=#000000;pw=2;"
shape[9] = "func=ell;x=29;y=211;width=16;height=18;bc=#6E6E6E;pc=#000000;pw=2;"
shape[10] = "func=ell;x=56;y=213;width=16;height=17;bc=#6E6E6E;pc=#000000;pw=2;"
shape[11] = "func=ell;x=115;y=213;width=15;height=16;bc=#6E6E6E;pc=#000000;pw=2;"
shape[12] = "func=ell;x=140;y=213;width=12;height=15;bc=#6E6E6E;pc=#000000;pw=2;"
shape[13] = "func=ell;x=65;y=278;width=57;height=146;bc=#FF0F0F;pw=0;"
shape[14] = "func=ell;x=76;y=286;width=36;height=102;bc=#FF930F;pw=0;"
shape[15] = "func=ell;x=85;y=291;width=18;height=50;bc=#FFEF0F;pw=0;"
EndSub