Microsoft Small Basic
Program Listing:
Embed this in your website
<object id='sbapp' data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='640' height='480'> <param name='source' value='http://smallbasic.com/program/ClientBin/SBWeb.xap'/> <param name='onError' value='onSilverlightError' /> <param name='background' value='white' /> <param name='minRuntimeVersion' value='3.0.40624.0' /> <param name='autoUpgrade' value='true' /> <param name='initParams' value='programId=HQB587' /> </object>
' Invador game ver1.0 by NaochanON
'
gui
(
)
GraphicsWindow
.
MouseMove
=
onmousemove
GraphicsWindow
.
MouseDown
=
onmousedown
While
"true"
EShooting
(
)
EnemyPosition
(
)
EnemyBullet
(
)
EHit_check
(
)
shooting
(
)
Hit_check
(
)
GraphicsWindow
.
Title
=
" You hit "
+
Hit
+
" times"
+
" You are Hit "
+
Eht
+
" times Elapsedtime= "
+
Math
.
Floor
(
(
Clock
.
ElapsedMilliseconds
-
t0
)
/
100
)
/
10
+
" sec"
Program
.
Delay
(
20
)
endwhile
sub
EnemyPosition
' Enemy position
If
Shapes
.
GetLeft
(
enemy
[
1
]
)
<
-
60
Or
1020
<
Shapes
.
GetLeft
(
enemy
[
1
]
)
Then
Retry
:
PM
=
2
-
math
.
GetRandomNumber
(
3
)
If
PM
=
0
Then
Goto
Retry
EndIf
turn
=
500
+
math
.
GetRandomNumber
(
400
)
*
PM
' set random turning point
Shapes
.
Animate
(
enemy
[
1
]
,
turn
,
dy
,
3000
)
' Enemy position
Shapes
.
Animate
(
enemy
[
2
]
,
turn
,
dy
,
3000
)
endif
Shapes
.
Move
(
enemy
[
1
]
,
Shapes
.
GetLeft
(
enemy
[
1
]
)
+
PM
+
acs
,
dy
)
' Enemy position
Shapes
.
Move
(
enemy
[
2
]
,
Shapes
.
GetLeft
(
enemy
[
2
]
)
+
PM
+
acs
,
dy
)
endsub
Sub
EShooting
' Enemy shooting
dXpe
=
math
.
Abs
(
Shapes
.
GetLeft
(
enemy
[
1
]
)
-
Shapes
.
GetLeft
(
player
[
1
]
)
)
' distance from player and enmy
If
30
<
dxpe
and
dxpe
<=
45
And
flag
=
0
Then
' if distance is from 38 to 40
MM
=
MM
+
1
acs
=
5
*
(
Shapes
.
GetLeft
(
enemy
[
1
]
)
-
Shapes
.
GetLeft
(
player
[
1
]
)
)
/
dxpe
If
MM
=
21
Then
dy
=
dy
+
10
' enemy Y level down
MM
=
1
EndIf
edb
[
MM
]
=
1
' bullet ON
flag
=
1
' Flag .... avoid continuous shooting
Else
flag
=
0
EndIf
Shapes
.
Move
(
rect
[
MM
]
,
shapes
.
GetLeft
(
enemy
[
1
]
)
+
20
,
dy
+
20
)
' set bullet
Shapes
.
showShape
(
rect
[
MM
]
)
' visible
endsub
Sub
EnemyBullet
For
M
=
1
To
20
Shapes
.
Move
(
rect
[
M
]
,
Shapes
.
GetLeft
(
rect
[
M
]
)
,
Shapes
.
Gettop
(
rect
[
M
]
)
*
edb
[
M
]
+
8
)
' bullet moves Y+8
Shapes
.
SetOpacity
(
rect
[
M
]
,
100
*
edb
[
M
]
)
if
Shapes
.
Gettop
(
rect
[
M
]
)
>
700
Then
edb
[
M
]
=
0
Shapes
.
Move
(
rect
[
M
]
,
Shapes
.
GetLeft
(
enemy
[
1
]
)
+
20
,
dy
+
20
)
' set bullet
EndIf
EndFor
EndSub
Sub
EHit_check
EHit
=
"False"
For
L
=
1
To
20
If
EHit
=
"False"
And
math
.
Abs
(
Shapes
.
GetLeft
(
rect
[
L
]
)
*
edb
[
L
]
-
Shapes
.
GetLeft
(
player
[
1
]
)
-
13
)
<
13
and
math
.
Abs
(
Shapes
.
Gettop
(
rect
[
L
]
)
*
edb
[
L
]
-
shapes
.
Gettop
(
player
[
1
]
)
)
<
15
then
EHit
=
"True"
For
N
=
1
To
3
Shapes
.
HideShape
(
player
[
N
]
)
' hide player
endfor
Shapes
.
Animate
(
msg2
,
-
300
,
300
,
3000
)
' You are HIT message
Program
.
Delay
(
3000
)
EHt
=
Eht
+
1
Shapes
.
Move
(
msg2
,
1400
,
100
)
For
N
=
1
To
3
Shapes
.
showShape
(
player
[
N
]
)
' Show player
endfor
erasebullet
(
)
' erase bullets
L
=
20
' avoid check
EndIf
endfor
EndSub
Sub
shooting
' Player shooting
acs
=
0
For
K
=
1
To
10
Shapes
.
Move
(
ball
[
k
]
,
Shapes
.
GetLeft
(
ball
[
k
]
)
,
Shapes
.
Gettop
(
ball
[
k
]
)
-
4
*
db
[
k
]
)
' bullet moves Y-4
If
(
shapes
.
Gettop
(
ball
[
k
]
)
-
Shapes
.
Gettop
(
enemy
[
1
]
)
)
<
85
and
math
.
Abs
(
Shapes
.
GetLeft
(
ball
[
k
]
)
-
Shapes
.
GetLeft
(
enemy
[
1
]
)
)
<
55
Then
' if bullet approaches to enemy
acs
=
(
Shapes
.
GetLeft
(
enemy
[
1
]
)
-
Shapes
.
GetLeft
(
ball
[
k
]
)
)
/
5
' enemy escape speedy
EndIf
if
Shapes
.
Gettop
(
ball
[
k
]
)
<
-
5
Then
Shapes
.
Move
(
ball
[
k
]
,
Shapes
.
GetLeft
(
player
[
2
]
)
,
625
)
' set bullet
db
[
k
]
=
0
shapes
.
HideShape
(
ball
[
k
]
)
EndIf
Hit_check
(
)
EndFor
EndSub
Sub
Hit_check
If
math
.
Abs
(
Shapes
.
GetLeft
(
ball
[
k
]
)
-
Shapes
.
GetLeft
(
enemy
[
2
]
)
-
12.5
)
<
12.5
and
math
.
Abs
(
Shapes
.
Gettop
(
ball
[
k
]
)
-
shapes
.
Gettop
(
enemy
[
2
]
)
-
7.5
)
<
7.5
then
PHit
=
"True"
RX
=
Shapes
.
GetLeft
(
enemy
[
2
]
)
RY
=
Shapes
.
Gettop
(
enemy
[
2
]
)
EndIf
If
PHit
=
"True"
then
erasebullet
(
)
Shapes
.
Animate
(
msg
,
1300
,
300
,
3000
)
' HIT message
Program
.
Delay
(
3000
)
PHit
=
"False"
Hit
=
hit
+
1
Shapes
.
Move
(
msg
,
-
300
,
100
)
Shapes
.
Move
(
enemy
[
1
]
,
Shapes
.
GetLeft
(
enemy
[
1
]
)
+
10
,
dy
)
' Enemy position
Shapes
.
Move
(
enemy
[
2
]
,
Shapes
.
GetLeft
(
enemy
[
2
]
)
+
10
,
dy
)
warp
(
)
enemymake
(
)
' new enemy making
K
=
10
' avoid check
EndIf
EndSub
Sub
onmousedown
' bullet shooting
NN
=
NN
+
1
db
[
NN
]
=
1
Shapes
.
ShowShape
(
ball
[
NN
]
)
Shapes
.
Move
(
ball
[
NN
]
,
Shapes
.
GetLeft
(
player
[
2
]
)
,
645
)
' bullet appears
If
NN
=
10
Then
STP
=
2
+
Math
.
GetRandomNumber
(
3
)
scatter
(
)
dy
=
dy
+
10
NN
=
0
EndIf
EndSub
Sub
onmousemove
MX
=
GraphicsWindow
.
MouseX
MY
=
GraphicsWindow
.
MouseY
For
i
=
1
To
3
Shapes
.
Move
(
player
[
i
]
,
MX
+
7
*
i
-
15
,
Shapes
.
Gettop
(
player
[
i
]
)
)
' player moves
EndFor
EndSub
Sub
scatter
For
i
=
1
To
300
Step
stp
Shapes
.
Animate
(
star
[
i
]
,
Math
.
GetRandomNumber
(
1400
)
,
Math
.
GetRandomNumber
(
400
)
+
400
*
Math
.
Floor
(
i
/
150
)
,
500
)
' star randomposition
EndFor
endsub
Sub
warp
For
i
=
1
To
300
Shapes
.
Animate
(
star
[
i
]
,
RX
,
RY
,
2000
)
' star randomposition
EndFor
Program
.
Delay
(
1500
)
stp
=
1
scatter
(
)
endsub
Sub
erasebullet
For
K
=
1
To
20
Shapes
.
HideShape
(
ball
[
k
]
)
Shapes
.
HideShape
(
rect
[
k
]
)
db
[
K
]
=
0
edb
[
K
]
=
0
EndFor
MM
=
0
endsub
Sub
gui
Hit
=
0
Eht
=
0
color
=
"1=Red;2=Green;3=Yellow;4=Cyan;5=Blue;6=Pink;7=khaki"
GraphicsWindow
.
Left
=
50
GraphicsWindow
.
Top
=
20
GraphicsWindow
.
Width
=
1000
GraphicsWindow
.
Height
=
700
GraphicsWindow
.
BackgroundColor
=
"Black"
Mouse
.
HideCursor
(
)
'----------------------- back stars ------------------------------
For
i
=
1
To
300
GraphicsWindow
.
PenColor
=
GraphicsWindow
.
GetRandomColor
(
)
dr
=
3
+
Math
.
GetRandomNumber
(
7
)
star
[
i
]
=
Shapes
.
AddEllipse
(
DR
,
DR
)
EndFor
stp
=
1
' Initial scatter step number
scatter
(
)
' background stars
'------------------------ Enemy -----------------------------------
enemymake
(
)
'------------------------ Player -----------------------------------
GraphicsWindow
.
BrushColor
=
"Cyan"
GraphicsWindow
.
PenColor
=
"lightcyan"
player
[
2
]
=
shapes
.
AddEllipse
(
10
,
35
)
Shapes
.
Move
(
player
[
2
]
,
300
,
645
)
GraphicsWindow
.
BrushColor
=
"Yellow"
GraphicsWindow
.
PenColor
=
"Yellow"
player
[
1
]
=
shapes
.
AddEllipse
(
8
,
20
)
Shapes
.
Move
(
player
[
1
]
,
293
,
660
)
player
[
3
]
=
shapes
.
AddEllipse
(
8
,
20
)
Shapes
.
Move
(
player
[
3
]
,
308
,
660
)
'------------------------ Hit message -----------------------------------
GraphicsWindow
.
FontSize
=
30
msg
=
Shapes
.
AddText
(
" You Hit !!!!!!! "
)
Shapes
.
Move
(
msg
,
-
300
,
100
)
msg2
=
Shapes
.
AddText
(
" You are Hit XD XD "
)
Shapes
.
Move
(
msg2
,
1400
,
200
)
'--------------------------- bullet --------------------------------
For
k
=
1
to
10
db
[
k
]
=
0
ball
[
k
]
=
Shapes
.
AddEllipse
(
5
,
8
)
Shapes
.
Move
(
ball
[
k
]
,
304
,
645
)
Shapes
.
HideShape
(
ball
[
k
]
)
endfor
'--------------------------- bullet2 --------------------------------
GraphicsWindow
.
BrushColor
=
"Cyan"
GraphicsWindow
.
PenColor
=
"Cyan"
For
L
=
1
to
20
rect
[
L
]
=
Shapes
.
AddRectangle
(
7
,
10
)
Shapes
.
Move
(
rect
[
L
]
,
Shapes
.
GetLeft
(
enemy
[
1
]
)
+
22.5
,
0
)
Shapes
.
HideShape
(
rect
[
L
]
)
endfor
flag
=
0
t0
=
clock
.
ElapsedMilliseconds
EndSub
Sub
enemymake
CN
=
Math
.
GetRandomNumber
(
7
)
GraphicsWindow
.
BrushColor
=
color
[
CN
]
GraphicsWindow
.
PenColor
=
color
[
CN
]
Shapes
.
Remove
(
enemy
[
1
]
)
enemy
[
1
]
=
shapes
.
AddEllipse
(
45
,
15
)
Shapes
.
Move
(
enemy
[
1
]
,
500
,
0
)
Shapes
.
Remove
(
enemy
[
2
]
)
enemy
[
2
]
=
Shapes
.
AddTriangle
(
10
,
10
,
35
,
10
,
22.5
,
25
)
Shapes
.
Move
(
enemy
[
2
]
,
500
,
0
)
PM
=
1
' Plus minus
turn
=
520
' Initial turning point
dy
=
0
' Initial Y-step
NN
=
0
' Initial bullet number (player)
MM
=
0
' Initial bullet number ( enemy)
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.