Microsoft Small Basic

Program Listing: VLP541-0
' mahreen miangul ID VLP541
' Duck Shoot Multiple KeyBoard
' JanUary/1st/2019
' Flip_Horizontal supported by Nonki Takahashi (VLP541-0)

GraphicsWindow.top= -2.0
GraphicsWindow.left= 80
GraphicsWindow.Title = "mahreen miangul"
GraphicsWindow.backgroundcolor = "black"
GraphicsWindow.Width = 1280
GraphicsWindow.Height = 666

GraphicsWindow.KeyDown = onkeyDown
'=============================Makesprite()============================
SPRITE_init()
Add_Shapes()
' ============================== Aircraft Animation======================
dZ = 0.1
zoom = 1
sprite = 5
For ii=1 to 4 '<----****
ddx[ii]=-(2+Math.GetRandomNumber(50)/10) '<----****
Flip_Holizontal()
endfor '<----****
ddy=0
bdx=0
bdy=30
bdy2=20 ' - initial ball2 moving speed-Y
CNMB="6:1" ' Cannon shapes number=6 repeat =1
shoot="False"
'shoot2="False"
zm=1
shootNMB=10 '<----****
' ============================== Cannon Animation ==============================
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor= "Red"
For i=1 to 4 '<----****
ANMB="5:"+i '<----****
Ball[i]=Shapes.AddEllipse(10,20) '<----****
Shapes.Move(Ball[i],shapes.GetLeft(shp[ANMB][9])+10,shapes.Gettop(shp[ANMB][9])+30) '<----****
Shapes.HideShape(Ball[i]) '<----****
sht[i]="False" '<----****
endfor '<----****
GraphicsWindow.BrushColor= "snow"
For i=1 to 10 '<----****
Ball2[i]=Shapes.AddEllipse(10,20) '<----****
Shapes.Move(Ball2[i],shapes.GetLeft(shp[CNMB][14]),shapes.Gettop(shp[CNMB][14])) '<----****
Shapes.HideShape(Ball2[i]) '<----****
sht2[i]="False" '<----****
endfor '<----****

' ==============================Cannon Animation and Blinkig 1======================
While "True" '
NN=NN+1 '<----****
If Math.Remainder(NN,7)=0 Then '<----****
For k=1 To Array.GetItemCount(s[6])
For L=1 To Array.GetItemCount(shape[6])-2 '
Shapes.Rotate(SHP["6:"+k][L],Shape[6][L]["angle"])
EndFor
EndFor
EndIf
DuckBlinking() '<----****
DuckFire() '<----****
CannonFire() '<----****
If Math.Remainder(NN,11)=0 Then '<----****
For k=1 To Array.GetItemCount(s[6])
For L=1 To Array.GetItemCount(shape[6])-2 '
Shapes.Rotate(SHP["6:"+K][L], 0)
EndFor
EndFor
EndIf
Program.Delay(25)
EndWhile

Sub DuckBlinking
'============================Duck Blinking Program=======================
zoom = zoom - dZ
sprite = 5
For ii=1 To 4 '<----****
ANMB="5:"+ii '<----****
ss = s[sprite][ii]
For i = 1 To Array.GetItemCount(shape[5])
If Array.ContainsValue(shape[5][i], "eye") Or Array.ContainsValue(shape[5][i], "wing1") Or Array.ContainsValue(shape[5][i], "wing2") Then
Shapes.Zoom(shp[ANMB][i], 1, zoom)
EndIf
If Array.ContainsValue(shape[5][i], "wing1") Or Array.ContainsValue(shape[5][i], "wing2") Then
Shapes.Move(shp[ANMB][i], Shapes.GetLeft(shp[ANMB][i]), Shapes.GetTop(shp[ANMB][i])+dZ*20*ss)
EndIf
Shapes.Move(shp[ANMB][i],Shapes.GetLeft(shp[ANMB][i])+ddx[ii],Shapes.GetTop(shp[ANMB][i])+ddy)'<----****
EndFor
ax[ANMB] = ax[ANMB] + ddx[ii]
'============================Aircraft Reverse Moving=====X,Y Direction=============
cycleX[ii]= shapes.GetLeft(shp[ANMB][9]) '<----****
cycley[ii]= shapes.Gettop(shp[ANMB][9]) '<----****
If cycleX[ii]<-100 Or cycleX[ii]>GraphicsWindow.Width+100 Then'<----****
ddx[ii]=-ddx[ii] '<----****
Flip_Holizontal()
EndIf
endfor '<----****
If zoom = 0.1 Or zoom = 1 Then
dZ = -dZ
EndIf
EndSub

Sub DuckFire
' ===========================BallFire=======================================
bn= Math.GetRandomNumber(10) '<----****
For i=1 To 4 '<----****
If sht[i]="True" Then '<----****
Shapes.ShowShape(Ball[i]) '<----****
shapes.Move(Ball[i] ,shapes.GetLeft(ball[i])+bdx/2,shapes.Gettop(ball[i])+bdy/2) '<----****
If shapes.Gettop(ball[i])>700 Then '<----****
sht[i]="False" '<----****
GraphicsWindow.Title="You Hit !!!!!! Total "
Shapes.Move(Ball[i],shapes.GetLeft(shp["5:"+bn/2][9])+10,shapes.Gettop(shp["5:"+bn/2][9])+30)'<----****
Shapes.HideShape(Ball[i]) '<----****
EndIf
'==========================Collision Check Here=================================
Cannon_X=shapes.GetLeft(shp[CNMB][5])
Cannon_Y=shapes.GetTop(shp[CNMB][5])
ballX=shapes.GetLeft(ball[i]) '<----****
bally=shapes.GetTop(ball[i]) '<----****
If (Cannon_X GraphicsWindow.Title="Duck Hit Cannon!!!!!!"
Sound.PlayChimeAndWait()
sht[i]="False" '<----****
Shapes.Move(Ball[i],shapes.GetLeft(shp["5:"+i][9])+10,shapes.Gettop(shp["5:"+i][9])+30)'<----****
Shapes.HideShape(Ball[i]) '<----****
EndIf
EndIf
EndFor
EndSub

Sub CannonFire
For j=1 To shootNMB '<----****
If sht2[j] Then '<----****
shapes.Move(Ball2[j] ,shapes.GetLeft(ball2[j] )+angle/4,shapes.Gettop(ball2[j] )-bdy2) '<----****
If shapes.Gettop(ball2[j] )<-100 Then '<----****
sht2[j] ="False" '<----****
Shapes.Move(Ball2[j] ,shapes.GetLeft(shp[CNMB][14]),shapes.Gettop(shp[CNMB][14])) '<----****
Shapes.HideShape(Ball2[j] ) '<----****
EndIf
endif
' Collision Check Here
ballX2=shapes.GetLeft(ball2[j] ) '<----****
bally2=shapes.GetTop(ball2[j] ) '<----****
For k=1 to 4
cycleX=shapes.GetLeft(shp["5:"+k][5]) '<----****
cycley= shapes.Gettop(shp["5:"+k][5]) '<----****
If (cycleX GraphicsWindow.Title="Cannon Hit Duck!!!!!!!!!!!"
Sound.PlayChimeAndWait()
sht2[j]="False" '<----****
Shapes.Move(Ball2[j] ,shapes.GetLeft(shp[CNMB][14]),shapes.Gettop(shp[CNMB][14])) '<----****
Shapes.HideShape(Ball2[j] ) '<----****
K=4 '<----****
EndIf
EndFor
EndFor
EndSub

' ==================KeyBoard Aniation Keys S, W, A, T, X,Z,F , SpaceBar works===========================
Sub OnKeyDown
key= GraphicsWindow.LastKey
'If shoot2="False" Then
L1415=(shape[6][14]["height"]+shape[6][15]["height"])/2*s[6][1]
cx14= Shapes.GetLeft(shp[CNMB][14])+shape[6][14]["width"]/2*s[6][1]
cy14= Shapes.Gettop(shp[CNMB][14])+shape[6][14]["height"]/2*s[6][1]
If Key = "X" Then
angle=angle+1
Shapes.Rotate(shp[CNMB][14],angle)
X15= L1415*math.Sin(Math.GetRadians(angle))+cx14-shape[6][15]["width"]/2*s[6][1]
y15= -L1415*math.cos(Math.GetRadians(angle))+cy14-shape[6][15]["height"]/2*s[6][1]
Shapes.Move(shp[CNMB][15],x15,y15)
Shapes.Rotate(shp[CNMB][15],angle)
ElseIf Key = "Z" Then
angle=angle-1
Shapes.Rotate(shp[CNMB][14],angle)
X15= L1415*math.Sin(Math.GetRadians(angle))+cx14-shape[6][15]["width"]/2*s[6][1]
y15= -L1415*math.cos(Math.GetRadians(angle))+cy14-shape[6][15]["height"]/2*s[6][1]
Shapes.Move(shp[CNMB][15],x15,y15)
Shapes.Rotate(shp[CNMB][15],angle)
elseIf Key="F" Then
MM=MM+1 '<----****
Shapes.ShowShape(Ball2[MM]) '<----****
Shapes.Move(Ball2[MM],shapes.GetLeft(shp[CNMB][14]),shapes.Gettop(shp[CNMB][14])) '<----****
Shapes.Rotate(Ball2[MM],angle) '<----****
sht2[MM]="True" '<----****
If mm=shootNMB then '<----****
mm=0 '<----****
EndIf '<----****
EndIf
'EndIf
PMXY= text.GetCharacterCode(key)
If PMXY=76 Or PMXY=82 Then ' Left Arrow : 76 Right Arrow : 82
dX= (PMXY-79)/3*5 ' <-- (82-76)/2=3 ,82-3=79 , dX=+5 or -5
dY=0
Move_index()
ElseIf PMXY=68 Or PMXY=85 Then ' Up Arrow : 85 Down Arrow : 68
dY= (76.5-PMXY)/8.5*5 ' <-- (85-68)/2=8.5, 85-8.5=76.5, dY=+5 or -5
dx=0
Move_index()
EndIf
EndSub

' ======================Move Sprite on Screen===================================
Sub move_index
For N=1 To 15 ''<----****
Shapes.Move(shp[CNMB][N],Shapes.GetLeft(shp[CNMB][N])+dX,Shapes.Gettop(shp[CNMB][N])+dY)'<----****
EndFor
EndSub

' ==============================Add Sprites=========================================
Sub Add_Shapes
For M=1 To Array.GetItemCount(s)
For N=1 To Array.GetItemCount(s[M])
ss=s[M][N]
_shx=shx[M][N]
_shY=shY[M][N]
_shape=shape[M]
NMB=M+":"+N
For i=1 To Array.GetItemCount(_shape)
GraphicsWindow.PenWidth = _shape[i]["pw"]
GraphicsWindow.BrushColor = _shape[i]["bc"]
GraphicsWindow.penColor = _shape[i]["pc"]
If _shape[i]["func"]="ell" Then
shp[NMB][i] = Shapes.AddEllipse(_shape[i]["width"]*ss, _shape[i]["height"]*ss)
ElseIf _shape[i]["func"]="rect" Then
shp[NMB][i] = Shapes.AddRectangle(_shape[i]["width"]*ss, _shape[i]["height"]*ss)
ElseIf _shape[i]["func"]="tri" Then
shp[NMB][i] = Shapes.Addtriangle(_shape[i]["x1"]*ss, _shape[i]["y1"]*ss,_shape[i]["x2"]*ss, _shape[i]["y2"]*ss, _shape[i]["x3"]*ss, _shape[i]["y3"]*ss)
ElseIf _shape[i]["func"]="line" Then
shp[NMB][i] = Shapes.Addline(_shape[i]["x1"]*ss, _shape[i]["y1"]*ss,_shape[i]["x2"]*ss, _shape[i]["y2"]*ss)
EndIf
Shapes.Animate(shp[NMB][i], _shape[i]["x"]*ss+_shX, _shape[i]["y"]*ss+_shY, 500)
Shapes.Rotate(shp[NMB][i], _Shape[i]["angle"])
EndFor
EndFor
EndFor
EndSub

Sub Flip_Holizontal
' param sprite - sprite number
' param ii - copy number
' param ddx[ii] - direction
FNMB = sprite + ":" + ii
If ax[FNMB] = "" Then
xmin = ""
xmax = ""
For i = 1 To Array.GetItemCount(shape[sprite])
_shp = shape[sprite][i]
x = shapes.GetLeft(shp[FNMB][i])
If _shp["width"] = "" Then
_xmin = ""
_xmax = ""
If _shp["func"] = "line" Then
jmax = 2
ElseIf _shp["func"] = "tri" Then
jmax = 3
EndIf
For j = 1 To jmax
If (_xmin = "") Or (_shp["x" + j] < _xmin) Then
_xmin = _shp["x" + j]
EndIf
If (_xmax = "") Or (_xmax < _shp["x" + j]) Then
_xmax = _shp["x" + j]
EndIf
EndFor
_shp["width"] = _xmax - _xmin
EndIf
cx = x + _shp["width"] / 2 * s[sprite][ii]
If (xmin = "") Or (cx - _shp["width"] / 2 * s[sprite][ii] < xmin) Then
xmin = cx - _shp["width"] / 2 * s[sprite][ii]
EndIf
If (xmax = "") Or (xmax < cx + _shp["width"] / 2 * s[sprite][ii]) Then
xmax = cx + _shp["width"] / 2 * s[sprite][ii]
EndIf
shape[sprite][i] = _shp
EndFor
ax[FNMB] = (xmin + xmax) / 2
EndIf
For i = 1 To Array.GetItemCount(shape[sprite])
_shp = shape[sprite][i]
x = shapes.GetLeft(shp[FNMB][i])
cx = x + _shp["width"] / 2 * s[sprite][ii]
If cx < ax[FNMB] Then
_dx = ax[FNMB] - cx
cx = ax[FNMB] + _dx
Else
_dx = cx - ax[FNMB]
cx = ax[FNMB] - _dx
EndIf
x = cx - _shp["width"] / 2 * s[sprite][ii]
Shapes.Move(shp[FNMB][i],x,shapes.Gettop(shp[FNMB][i]))
If 0 < ddx[ii] Then
Shapes.Rotate(shp[FNMB][i],_shp["angle"])
Else
Shapes.Rotate(shp[FNMB][i],-_shp["angle"])
EndIf
EndFor
EndSub

Sub SPRITE_init
' 14 Trees
s[1]="1=0.8;2=.8;3=.8;4=.8;5=.8;6=.8;7=.8;8=.8;9=.8;"
shX[1]="1=-0;2=100;3=280;4=200;5=644;6=777;7=866;8=966;9=1088;"
shY[1]="1=200;2=170;3=100;4=140;5=100;6=80;7=70;8=80;9=100;" '
' 18 Apples
s[2] ="1=0.2;2=0.2;3=0.2;4=0.2;5=0.2;6=0.2;7=0.2;8=0.2;9=0.2;10=0.2;"
shX[2] ="1=-60;2=60;3=140;4=600;5=700;6=800;7=900;8=1000;9=1080;10=240"
shY[2] ="1=360;2=300;3=270;4=240;5=220;6=240;7=220;8=240;9=220;10=240"
' House '
s[3] = "1=0.28"
shX[3] ="1=522"
shY[3] ="1=488"
' Ladder
s[4] ="1=0.6" ' scale
shx[4] ="1= 380" ' initial x -position
shy[4] ="1= 180" ' initial y-position
' Duck
s[5] = "1=0.4;2=0.4;3=0.4;4=0.4"
shX[5]= "1=1000;2=888;3=666;4=444"
shY[5]= "1=35;2=25;3=15;4=30"
shape[5][1] = "func=rect;x=101;y=12;width=16;height=43;angle=45;bc=#00CA54;pc=#000000;pw=1;id=neck;"
shape[5][2] = "func=ell;x=98;y=1;width=56;height=24;bc=#DFCA54;pc=#000000;pw=1;id=head;"
shape[5][3] = "func=ell;x=128;y=7;width=15;height=10;bc=#DF3954;pc=#000000;pw=1;id=eye;"
shape[5][4] = "func=tri;x=52;y=6;x1=15;y1=0;x2=0;y2=56;x3=30;y3=56;angle=4;bc=#DFCA54;pc=#000000;pw=1;id=wing1;"
shape[5][5] = "func=line;x=9;y=67.5;x1=0;y1=0;x2=49.01;y2=0;angle=-1.17;pc=#DF3954;pw=2;id=leg1;"
shape[5][6] = "func=line;x=-2.23;y=74;x1=0;y1=0;x2=13.45;y2=0;angle=-48.01;pc=#DF3954;pw=2;id=leg2;"
shape[5][7] = "func=ell;x=0;y=39;width=108;height=31;bc=#DFCA54;pc=#000000;pw=1;id=body;"
shape[5][8] = "func=tri;x=31;y=0;x1=15;y1=0;x2=0;y2=56;x3=30;y3=56;angle=349;bc=#DF8754;pc=#000000;pw=1;id=wing2;"
shape[5][9] = "func=ell;x=143;y=16;width=29;height=9;angle=13;bc=#DF8754;pc=#000000;pw=1;id=mouth;"
' Cannon
s[6] ="1=0.5"
shX[6] ="1=50"
shY[6] ="1=545"
shape[6][1] = "func=rect;x=90;y=45;width=20;height=44;bc=red;pw=0;"
shape[6][2] = "func=rect;x=105;y=45;width=20;height=44;bc=green;pw=0;"
shape[6][3] = "func=rect;x=127;y=45;width=20;height=44;bc=yellow;pw=0;"
shape[6][4] = "func=rect;x=147;y=43;width=20;height=55;bc=blue;pw=0;"
shape[6][5] = "func=rect;x=33;y=30;width=55;height=68;bc=darkslategray=0;"
shape[6][6] = "func=rect;x=44;y=44;width=33;height=33;bc=snow;pw=0;"
shape[6][7] = "func=ell;x=46;y=46;width=30;height=30;bc=darkslategray;pw=0;"
shape[6][8] = "func=rect;x=0;y=150;width=330;height=90;bc=darkslategray;pw=0;"
shape[6][9] = "func=ell;x=0;y=80;width=210;height=140;bc=darkslategray;pw=0;"
shape[6][10]="func=ell;x=40;y=120;width=33;height=22;angle=-50;bc=snow;pw=0.5"
shape[6][11]="func=ell;X=130;Y=120;width=33;height=22;angle=50;bc=mediumslateblue;pw=0.5"
shape[6][12]="func=rect;X=40;Y=180;width=33;height=22;angle=40;bc=mediumslateblue;pc=darkslategray;pw=0"
shape[6][13]="func=rect;X=130;Y=180;width=33;height=22;angle=-40;bc=snow;pc=darkslategray;pw=0"
shape[6][14]="func=rect;X=210;Y=50;width=40;height=100;angle=0;bc=darkslategray;pc=black;pw=2" '<------ cannon for ball2
shape[6][15]="func=rect;x=204;y=20;width=50;height=30;angle=0;bc=darkslategray;pc=black;pw=2" '<------ cannon for ball2
' Tree
s[7]="1=0.8;2=.8;3=.8;4=.8;"
shX[7]="1=10;2=150;3=920;4=1100"
shY[7]="1=300;2=300;3=330;4=330" ' 5,6,13,14
shape[7]=shape[1]
'Apple
s[8] ="1=0.2;2=0.2;3=0.2;4=0.2;5=0.2;6=0.2;7=.2;8=.2;"
shX[8] ="1=140;2=650;3=-80;4=0;5=100;6=740;7=920;8=1100"
shY[8] ="1=444;2=420;3=440;4=420;5=420;6=420;7=480;8=460"
EndSub