Microsoft Small Basic

Program Listing: GKX860
' Challenge of the Month - December 2015 Community Suggestion (By JetFire3201)
' runnning stickman by NaochanON

GraphicsWindow.KeyDown=Onkeydown
Shapes_Init()
Shapes_Add()

Sub onkeydown
key= GraphicsWindow.LastKey
If Text.IsSubText("Right:Left",key) Then
ds="X="+KLST[key]+";y=0"
If lastkey<>key Then
counts=0
Lastangles=initangles
EndIf
Shapes_Move()
ElseIf Text.IsSubText("Up:Down",key) Then
ds="X=0;y="+KLST[key]
Shapes_Move()
EndIf
lastkey=Key
EndSub

Sub Shapes_Move
Multi=1.8
counts=counts+1
For i=1 To posnmb
x[i]=shapes.GetLeft(shp[i][1]) ' each position -X
y[i]=shapes.Gettop(shp[i][1]) ' each position -Y
If text.IsSubText(inmbs,":"+i+":") Then
x[i]=shapes.GetLeft(shp[i-1][pos[i-1]["NN"]]) ' upper arm/leg last number -X
y[i]=shapes.Gettop(shp[i-1][pos[i-1]["NN"]]) ' upper arm/leg last number -Y
EndIf
MM= Math.Ceiling(2*counts/div)
GraphicsWindow.Title=MM+" : "+counts
Dangle=PM[MM]*angles[Key][NMB[MM]][i]/div ' dθ/div
thisangle=Lastangles[i]+ Multi*Dangle ' current each angle
dx=pos[i]["wd"]*math.sin(math.GetRadians(thisangle))
dy=pos[i]["wd"]*math.cos(math.GetRadians(thisangle))
for j=1 To pos[i]["NN"]
Shapes.Move(shp[i][j],x[i]+ds["X"]+(j-1)*dx,y[i]+ds["Y"]+(j-1)*dy) ' arms / legs
EndFor
Lastangles[i]=thisangle
EndFor
if counts>div*2-1 Then
counts=0
EndIf
endsub

Sub Shapes_Init
X0 = 350
Y0 = 120
pos[1] = "x=0;y=0;wd=50;NN=1;angle=0;bc=#AABBFF;pc=#000000;pw=2;" ' Head
pos[2] = "x=19;y=50;wd=10;NN=10;angle=0;bc=#AABBFF;pc=#000000;pw=2;" ' body 50,12
pos[3] = "x=13;y=55;wd=10;NN=6;angle=0;bc=#AABBFF;pc=#000000;pw=2;" ' left arm upper 55,6
pos[4] = "x=13;y=115;wd=10;NN=5;angle=0;bc=#AABBFF;pc=#000000;pw=2;" ' left arm lower 55+10*6,6
pos[5] = "x=16;y=150;wd=10;NN=6;angle=0;bc=#AABBFF;pc=#000000;pw=2;" ' Left leg upper 50+10*12,6
pos[6] = "x=16;y=210;wd=10;NN=6;angle=0;bc=#AABBFF;pc=#000000;pw=2;" ' Left leg lower 50+10*12+10*6,5
pos[7] = "x=25;y=55;wd=10;NN=6;angle=0;bc=#AABBFF;pc=#000000;pw=2;" ' Right arm upper 55,6
pos[8] = "x=25;y=115;wd=10;NN=5;angle=0;bc=#AABBFF;pc=#000000;pw=2;" ' Right arm lower 55+10*6,5
pos[9] = "x=20;y=150;wd=10;NN=6;angle=0;bc=#AABBFF;pc=#000000;pw=2;" ' right leg upper 50+10*12,6
pos[10] = "x=20;y=210;wd=10;NN=6;angle=0;bc=#AABBFF;pc=#000000;pw=2;" ' right leg lower 50+10*12+10*6,5
'----------------------------------------------------------------------------------------------------------------
posnmb= Array.GetItemCount(pos)
KLST="Right=3;Left=-3;Up=-2;Down=2"
'------------------------------------ Left to Right direction -------------------------------------------------------
angles["Right"][1]="1=0;2=0;3=-90;4=-40;5=-80;6=-150;7=90;8=180;9=120;10=20" ' Right direction pause ***
angles["Right"][2]="1=0;2=0;3=90;4=180;5=120;6=20;7=-85;8=-40;9=-80;10=-150" ' Left direction pause ***
'------------------------------------ Right to Left direction -------------------------------------------------------
angles["Left"][1]="1=0;2=0;3=-60;4=-120;5=-80;6=-35;7=90;8=20;9=85;10=120" ' Right direction pause
angles["Left"][2]="1=0;2=0;3=90;4=20;5=85;6=120;7=-60;8=-120;9=-80;10=-35" ' Left direction pause
'----------------------------------------------------------------------------------------------------------------
div=20
Gravity=9.8
inmbs="2:4:6:8:10:"
PM="1=1;2=-1;3=1;4=-1"
NMB="1=1;2=1;3=2;4=2"
Lastangles="1=0;2=0;3=0;4=0;5=0;6=0;7=0;8=0;9=0;10=0" ' Standing pause
initangles=lastangles
EndSub

Sub Shapes_Add
GraphicsWindow.Width=1200
GraphicsWindow.Height=600
For i = 1 To Array.GetItemCount(pos)
GraphicsWindow.Penwidth = pos[i]["pw"]
GraphicsWindow.PenColor = pos[i]["pc"]
GraphicsWindow.BrushColor = pos[i]["bc"]
For j=1 To pos[i]["NN"]
shp[i][j]=Shapes.AddEllipse(pos[i]["wd"],pos[i]["wd"])
dx= pos[i]["wd"]*math.sin(math.GetRadians(pos[i]["angle"]))
dy= pos[i]["wd"]*math.cos(math.GetRadians(pos[i]["angle"]))
sx[i][j]= X0+pos[i]["x"]+(j-1)*dx
sy[i][j]= y0+pos[i]["y"]+(j-1)*dy
Shapes.Move(shp[i][j],sx[i][j] ,sy[i][j])
EndFor
EndFor
Shapes.Zoom( shp[1][1],0.5,1)
EndSub