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=VJQ222' /> </object>
GraphicsWindow
.
Width
=
Desktop
.
Width
-
100
GraphicsWindow
.
Height
=
Desktop
.
Height
-
125
GraphicsWindow
.
MouseDown
=
OnMouseDown
GraphicsWindow
.
MouseMove
=
OnMouseMove
GraphicsWindow
.
BrushColor
=
"Black"
GraphicsWindow
.
CanResize
=
"No"
GraphicsWindow
.
Top
=
13.5
GraphicsWindow
.
Left
=
50
BallCount
=
5
NumOfTanksAllowedOut
=
10
Money
=
50
TankImg
=
"http://sean.alyrica.net/TD/Tank.png"
NumOfTanks
=
10
TankWidth
=
100
TankHeight
=
40
TankPriceInc
=
10
IntTankSpeed
=
2
TankMaxVar
=
10
TankCost
=
10
IntTankHealth
=
1000
TankHealthInc
=
1000
TankHealthIncAcc
=
1500
MoneyText
=
Shapes
.
AddText
(
"You Have "
+
Money
+
"$"
)
Shapes
.
Move
(
MoneyText
,
GraphicsWindow
.
Width
-
100
,
10
)
Img
=
ImageList
.
LoadImage
(
"http://www.sean.alyrica.net/TD/Background.Png"
)
For
i10
=
1
to
GraphicsWindow
.
Width
Step
175
For
i11
=
1
To
GraphicsWindow
.
Height
Step
125
GraphicsWindow
.
DrawImage
(
Img
,
i10
,
i11
)
EndFor
EndFor
NumOfTurretTypes
=
6
'<-- This MUST be set to the number of turrets Types!!!
'------Turret Properties--------------------------------------------------------------------
TurretPic
[
1
]
[
"Base"
]
[
"Path"
]
=
"http://sean.alyrica.net/TD/Base.Png"
'The Stationary part Pic
TurretPic
[
1
]
[
"Top"
]
[
"Path"
]
=
"http://sean.alyrica.net/TD/Top.Png"
'The Turning part Pic
TurretPic
[
1
]
[
"Projectile"
]
[
"Path"
]
=
"Ball"
'Set to Ball For Ball Or The file path for a img
TurretProp
[
1
]
[
"Name"
]
=
"Type 1 Turret"
'Turret Name
TurretProp
[
1
]
[
"BallSize"
]
=
5
'Ball Size (If Projectile is set to Ball)
TurretProp
[
1
]
[
"BallColor"
]
=
"Black"
'Ball Color (If Projectile is set to Ball)
TurretProp
[
1
]
[
"Price"
]
=
25
'Cost in $
TurretProp
[
1
]
[
"Speed"
]
=
100
'Velocity
TurretProp
[
1
]
[
"ROF"
]
=
500
'Rate Of Fire. In Millseconds Length in between fireing
TurretProp
[
1
]
[
"Damage"
]
=
400
'The Damage it does to the tank when it fires
TurretProp
[
1
]
[
"Range"
]
=
200
'------------------------------------------------------------------------------------------------
TurretPic
[
2
]
[
"Base"
]
[
"Path"
]
=
"http://sean.alyrica.net/TD/Base2.Png"
'The Stationary part Pic
TurretPic
[
2
]
[
"Top"
]
[
"Path"
]
=
"http://sean.alyrica.net/TD/Top2.Png"
'The Turning part Pic
TurretPic
[
2
]
[
"Projectile"
]
[
"Path"
]
=
"Ball"
'Set to Ball For Ball Or The file path for a img
TurretProp
[
2
]
[
"Name"
]
=
"Type 2 Turret"
'Turret Name
TurretProp
[
2
]
[
"BallSize"
]
=
10
'Ball Size (If Projectile is set to Ball)
TurretProp
[
2
]
[
"BallColor"
]
=
"Blue"
'Ball Color (If Projectile is set to Ball)
TurretProp
[
2
]
[
"Price"
]
=
50
'Cost in $
TurretProp
[
2
]
[
"Speed"
]
=
125
'Velocity
TurretProp
[
2
]
[
"ROF"
]
=
1250
'Rate Of Fire. In Millseconds Length in between fireing
TurretProp
[
2
]
[
"Damage"
]
=
1000
'The Damage it does to the tank when it fires
TurretProp
[
2
]
[
"Range"
]
=
200
'-------------------------------------------------------------------------------------------------
TurretPic
[
3
]
[
"Base"
]
[
"Path"
]
=
"http://sean.alyrica.net/TD/Base3.Png"
'The Stationary part Pic
TurretPic
[
3
]
[
"Top"
]
[
"Path"
]
=
"http://sean.alyrica.net/TD/Top4.Png"
'The Turning part Pic
TurretPic
[
3
]
[
"Projectile"
]
[
"Path"
]
=
"http://sean.alyrica.net/TD/Missile2.Png"
'Set to Ball For Ball Or The file path for a img
TurretProp
[
3
]
[
"Name"
]
=
"Type 1 Missile Launcher"
'Turret Name
TurretProp
[
3
]
[
"BallSize"
]
=
15
'Ball Size (If Projectile is set to Ball)
TurretProp
[
3
]
[
"BallColor"
]
=
"Red"
'Ball Color (If Projectile is set to Ball)
TurretProp
[
3
]
[
"Price"
]
=
150
'Cost in $
TurretProp
[
3
]
[
"Speed"
]
=
100
'Velocity
TurretProp
[
3
]
[
"ROF"
]
=
1550
'Rate Of Fire. In Millseconds Length in between fireing
TurretProp
[
3
]
[
"Damage"
]
=
2000
'The Damage it does to the tank when it fires
TurretProp
[
3
]
[
"Range"
]
=
300
'--------------------------------------------------------------------------------------------------
TurretPic
[
4
]
[
"Base"
]
[
"Path"
]
=
"http://sean.alyrica.net/TD/Base3.Png"
'The Stationary part Pic
TurretPic
[
4
]
[
"Top"
]
[
"Path"
]
=
"http://sean.alyrica.net/TD/Top5.Png"
'The Turning part Pic
TurretPic
[
4
]
[
"Projectile"
]
[
"Path"
]
=
"Ball"
'Set to Ball For Ball Or The file path for a img
TurretProp
[
4
]
[
"Name"
]
=
"Type 2 Missile Launcher"
'Turret Name
TurretProp
[
4
]
[
"BallSize"
]
=
15
'Ball Size (If Projectile is set to Ball)
TurretProp
[
4
]
[
"BallColor"
]
=
"Orange"
'Ball Color (If Projectile is set to Ball)
TurretProp
[
4
]
[
"Price"
]
=
500
'Cost in $
TurretProp
[
4
]
[
"Speed"
]
=
200
'Velocity
TurretProp
[
4
]
[
"ROF"
]
=
1000
'Rate Of Fire. In Millseconds Length in between fireing
TurretProp
[
4
]
[
"Damage"
]
=
5000
'The Damage it does to the tank when it fires
TurretProp
[
4
]
[
"Range"
]
=
310
'--------------------------------------------------------------------------------------------------
TurretPic
[
5
]
[
"Base"
]
[
"Path"
]
=
"http://sean.alyrica.net/TD/Base4.Png"
'The Stationary part Pic
TurretPic
[
5
]
[
"Top"
]
[
"Path"
]
=
"http://sean.alyrica.net/TD/TopAir.Png"
'The Turning part Pic
TurretPic
[
5
]
[
"Projectile"
]
[
"Path"
]
=
"Ball"
'Set to Ball For Ball Or The file path for a img
TurretProp
[
5
]
[
"Name"
]
=
"Rapid Fire Turret"
'Turret Name
TurretProp
[
5
]
[
"BallSize"
]
=
10
'Ball Size (If Projectile is set to Ball)
TurretProp
[
5
]
[
"BallColor"
]
=
"Red"
'Ball Color (If Projectile is set to Ball)
TurretProp
[
5
]
[
"Price"
]
=
700
'Cost in $
TurretProp
[
5
]
[
"Speed"
]
=
150
'Velocity
TurretProp
[
5
]
[
"ROF"
]
=
250
'Rate Of Fire. In Millseconds Length in between fireing
TurretProp
[
5
]
[
"Damage"
]
=
1500
'The Damage it does to the tank when it fires
TurretProp
[
5
]
[
"Range"
]
=
310
'--------------------------------------------------------------------------------------------------
TurretPic
[
6
]
[
"Base"
]
[
"Path"
]
=
"http://sean.alyrica.net/TD/Base4.Png"
'The Stationary part Pic
TurretPic
[
6
]
[
"Top"
]
[
"Path"
]
=
"http://sean.alyrica.net/TD/Top6.Png"
'The Turning part Pic
TurretPic
[
6
]
[
"Projectile"
]
[
"Path"
]
=
"Ball"
'Set to Ball For Ball Or The file path for a img
TurretProp
[
6
]
[
"Name"
]
=
"Heavy Turret"
'Turret Name
TurretProp
[
6
]
[
"BallSize"
]
=
10
'Ball Size (If Projectile is set to Ball)
TurretProp
[
6
]
[
"BallColor"
]
=
"Yellow"
'Ball Color (If Projectile is set to Ball)
TurretProp
[
6
]
[
"Price"
]
=
1000
'Cost in $
TurretProp
[
6
]
[
"Speed"
]
=
150
'Velocity
TurretProp
[
6
]
[
"ROF"
]
=
1500
'Rate Of Fire. In Millseconds Length in between fireing
TurretProp
[
6
]
[
"Damage"
]
=
10500
'The Damage it does to the tank when it fires
TurretProp
[
6
]
[
"Range"
]
=
250
Img5
=
ImageList
.
LoadImage
(
"http://sean.alyrica.net/TD/TopWreck.Png"
)
Img6
=
ImageList
.
LoadImage
(
"http://sean.alyrica.net/TD/BaseWreck.Png"
)
For
i
=
1
To
NumOfTurretTypes
ImgTop
[
i
]
=
ImageList
.
LoadImage
(
TurretPic
[
i
]
[
"Top"
]
[
"Path"
]
)
ImgBase
[
i
]
=
ImageList
.
LoadImage
(
TurretPic
[
i
]
[
"Base"
]
[
"Path"
]
)
GraphicsWindow
.
DrawImage
(
ImgBase
[
i
]
,
i
*
40
,
10
)
GraphicsWindow
.
DrawImage
(
ImgTop
[
i
]
,
i
*
40
,
5
)
GraphicsWindow
.
DrawText
(
i
*
40
+
5
,
40
,
TurretProp
[
i
]
[
"Price"
]
+
" $"
)
EndFor
AddTanks
(
)
GraphicsWindow
.
ShowMessage
(
"To grab a turret, click on it and place it where you want. if you want to see how many kills it has, put your cursor over it."
,
"Tankinator"
)
BeginGameTime
=
Clock
.
ElapsedMilliseconds
While
Out
<
NumOfTanksAllowedOut
Program
.
Delay
(
5
)
OldTimeStart2
=
Timestart2
Timestart2
=
Clock
.
ElapsedMilliseconds
TimeElapsed2
=
Timestart2
-
OldTimeStart2
If
TimeElapsed2
/
20
<
5
Then
TankSpeed
=
TimeElapsed2
/
(
20
-
intTankSpeed
)
EndIf
GraphicsWindow
.
Title
=
"Out = "
+
Out
Shapes
.
SetText
(
MoneyText
,
"You Have "
+
Money
+
"$"
)
If
(
Kills
+
OutThisRound
)
>=
NumOfTanks
Then
Kills
=
0
AddTanks
(
)
EndIf
MoveTanks
(
)
SetAim
(
)
CalcXY
(
)
EndWhile
For
i12
=
1
to
TurretNum
Kills
=
Kills
+
TurretKills
[
i12
]
EndFor
Score
=
Math
.
Round
(
(
Clock
.
ElapsedMilliseconds
-
BeginGameTime
)
*
Kills
/
1000
)
GraphicsWindow
.
ShowMessage
(
"You Lost :( Your score was "
+
Score
,
"Tower Defence"
)
While
1
=
1
Program
.
Delay
(
5
)
For
i1
=
1
To
TurretNum
If
GraphicsWindow
.
MouseX
>
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"x"
]
And
GraphicsWindow
.
MouseX
<
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"x"
]
+
30
And
GraphicsWindow
.
MouseY
>
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"y"
]
And
GraphicsWindow
.
MouseY
<
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"y"
]
+
30
Then
Shapes
.
ShowShape
(
RangeCir
[
i1
]
)
Shapes
.
ShowShape
(
KillsText
[
i1
]
)
Shapes
.
ShowShape
(
TurretName
[
i1
]
)
Else
Shapes
.
HideShape
(
RangeCir
[
i1
]
)
Shapes
.
HideShape
(
KillsText
[
i1
]
)
Shapes
.
HideShape
(
TurretName
[
i1
]
)
EndIf
EndFor
EndWhile
Sub
Fire
Sf
=
Sf
+
1
If
Sf
>
BallCount
Then
'<--- If the number of shots fired is more than the number of balls that can possible be on the screen, Then set it to One
Sf
=
1
EndIf
If
Ball
[
Turret2Fire
]
[
Sf
]
=
""
Then
ProjCaps
=
Text
.
ConvertToUpperCase
(
BallPath
[
Turret2Fire
]
)
If
ProjCaps
=
"BALL"
Then
Color
=
GraphicsWindow
.
BrushColor
GraphicsWindow
.
BrushColor
=
BallColor
[
Turret2Fire
]
Ball
[
Turret2Fire
]
[
Sf
]
=
Shapes
.
AddEllipse
(
BallSize
[
Turret2Fire
]
,
BallSize
[
Turret2Fire
]
)
GraphicsWindow
.
BrushColor
=
Color
EndIf
If
ProjCaps
<>
"BALL"
And
ProjCaps
<>
""
Then
Ball
[
Turret2Fire
]
[
Sf
]
=
Shapes
.
AddImage
(
BallPath
[
Turret2Fire
]
)
EndIf
EndIf
Ang
[
Turret2Fire
]
[
sf
]
=
Angle2Fire
V
=
TurretProp
[
TurretType
[
Turret2Fire
]
]
[
"Speed"
]
Vh
[
Turret2Fire
]
[
sf
]
=
Math
.
GetDegrees
(
Math
.
Cos
(
Math
.
GetRadians
(
Ang
[
Turret2Fire
]
[
sf
]
-
90
)
)
)
*
v
Vv
[
Turret2Fire
]
[
sf
]
=
Math
.
GetDegrees
(
Math
.
Sin
(
Math
.
GetRadians
(
Ang
[
Turret2Fire
]
[
sf
]
-
90
)
)
)
*
v
Time
[
Turret2Fire
]
[
sf
]
=
0
TimeFire
[
Turret2Fire
]
[
sf
]
=
0
EndSub
Sub
OnMouseDown
If
ObjectMove
<>
""
Then
ObjectMove
=
""
Mousex
=
Math
.
Round
(
GraphicsWindow
.
MouseX
/
30
)
*
30
Mousey
=
Math
.
Round
(
GraphicsWindow
.
MouseY
/
30
)
*
30
Turret
[
TurretNum
]
[
TypeClicked
]
[
"x"
]
=
Mousex
Turret
[
TurretNum
]
[
TypeClicked
]
[
"y"
]
=
Mousey
Color
=
GraphicsWindow
.
BrushColor
GraphicsWindow
.
BrushColor
=
"#591DB904"
RangeCir
[
TurretNum
]
=
Shapes
.
AddEllipse
(
(
TurretProp
[
TypeClicked
]
[
"Range"
]
*
2
)
,
(
TurretProp
[
TypeClicked
]
[
"Range"
]
*
2
)
)
Shapes
.
Move
(
RangeCir
[
TurretNum
]
,
Mousex
-
TurretProp
[
TypeClicked
]
[
"Range"
]
+
15
,
Mousey
-
TurretProp
[
TypeClicked
]
[
"Range"
]
+
15
)
Shapes
.
HideShape
(
RangeCir
[
TurretNum
]
)
GraphicsWindow
.
BrushColor
=
Color
KillsText
[
TurretNum
]
=
Shapes
.
AddText
(
""
)
Shapes
.
Move
(
KillsText
[
TurretNum
]
,
10
,
GraphicsWindow
.
Height
-
30
)
Shapes
.
HideShape
(
KillsText
[
TurretNum
]
)
TurretName
[
TurretNum
]
=
Shapes
.
AddText
(
TurretProp
[
TypeClicked
]
[
"Name"
]
)
Shapes
.
Move
(
TurretName
[
TurretNum
]
,
10
,
GraphicsWindow
.
Height
-
60
)
Shapes
.
HideShape
(
TurretName
[
TurretNum
]
)
TimeStart
[
TurretNum
]
=
Clock
.
ElapsedMilliseconds
TurretType
[
TurretNum
]
=
TypeClicked
BallColor
[
TurretNum
]
=
TurretProp
[
TurretType
[
Turret2Fire
]
]
[
"BallColor"
]
BallSize
[
TurretNum
]
=
TurretProp
[
TurretType
[
Turret2Fire
]
]
[
"BallSize"
]
BallPath
[
TurretNum
]
=
TurretPic
[
TurretType
[
Turret2Fire
]
]
[
"Projectile"
]
[
"Path"
]
Turret
[
TurretNum
]
[
TypeClicked
]
[
"Top"
]
=
Shapes
.
AddImage
(
ImgTop
[
TypeClicked
]
)
Shapes
.
Move
(
Turret
[
TurretNum
]
[
TypeClicked
]
[
"Top"
]
,
Turret
[
TurretNum
]
[
TypeClicked
]
[
"x"
]
,
Turret
[
TurretNum
]
[
TypeClicked
]
[
"y"
]
-
5
)
EndIf
For
i
=
1
To
NumOfTurretTypes
If
GraphicsWindow
.
MouseX
>
(
i
*
40
)
And
GraphicsWindow
.
MouseX
<
(
i
*
40
)
+
30
And
GraphicsWindow
.
MouseY
>
10
And
GraphicsWindow
.
MouseY
<
40
Then
Clicked
=
"Yes"
TypeClicked
=
i
EndIf
EndFor
If
Clicked
=
"Yes"
Then
If
Money
-
TurretProp
[
TypeClicked
]
[
"Price"
]
>=
0
Then
ObjectMove
=
Shapes
.
AddImage
(
ImgBase
[
TypeClicked
]
)
Mousex
=
Math
.
Round
(
GraphicsWindow
.
MouseX
/
30
)
*
30
Mousey
=
Math
.
Round
(
GraphicsWindow
.
MouseY
/
30
)
*
30
Shapes
.
Move
(
ObjectMove
,
Mousex
,
Mousey
)
Clicked
=
"No"
TurretNum
=
TurretNum
+
1
Money
=
Money
-
TurretProp
[
TypeClicked
]
[
"Price"
]
EndIf
EndIf
EndSub
Sub
OnMouseMove
If
ObjectMove
<>
""
Then
Mousex
=
Math
.
Round
(
GraphicsWindow
.
MouseX
/
30
)
*
30
Mousey
=
Math
.
Round
(
GraphicsWindow
.
MouseY
/
30
)
*
30
Shapes
.
Move
(
ObjectMove
,
Mousex
,
Mousey
)
EndIf
EndSub
Sub
GetAngle
Tx
[
i1
]
=
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"x"
]
Ty
[
i1
]
=
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"y"
]
If
Posx
[
i1
]
>
Tx
[
i1
]
Then
'Aims At Pos
AngleRadians
[
i1
]
=
Math
.
ArcTan
(
(
Posy
[
i1
]
-
Ty
[
i1
]
)
/
(
Posx
[
i1
]
-
Tx
[
i1
]
)
)
+
1.57079
'90 Degs. In Radians
ElseIf
Posx
[
i1
]
<
Tx
[
i1
]
Then
AngleRadians
[
i1
]
=
Math
.
ArcTan
(
(
Posy
[
i1
]
-
Ty
[
i1
]
)
/
(
Posx
[
i1
]
-
Tx
[
i1
]
)
)
-
1.57079
'90 Degs. In Radians
ElseIf
Posx
[
i1
]
=
Tx
[
i1
]
And
Posy
[
i1
]
>
Ty
[
i1
]
Then
AngleRadians
[
i1
]
=
Math
.
ArcTan
(
(
Posy
[
i1
]
-
Ty
[
i1
]
)
/
(
Posx
[
i1
]
-
Tx
[
i1
]
)
)
+
3.14159
EndIf
Angle
[
i1
]
=
Math
.
GetDegrees
(
AngleRadians
[
i1
]
)
EndSub
Sub
AddTanks
For
i3
=
1
To
NumOfTanks
If
Tank
[
i3
]
=
""
Then
Tank
[
i3
]
=
Shapes
.
AddImage
(
TankImg
)
EndIf
Tanky
[
i3
]
=
Math
.
GetRandomNumber
(
GraphicsWindow
.
Height
-
TankHeight
)
Tankx
[
i3
]
=
GraphicsWindow
.
Width
+
Math
.
GetRandomNumber
(
GraphicsWindow
.
Width
)
TankVar
[
i3
]
=
Math
.
GetRandomNumber
(
TankMaxVar
)
/
TankMaxVar
Shapes
.
Remove
(
HealthBarInside
[
i3
]
)
Color
=
GraphicsWindow
.
BrushColor
Size
=
GraphicsWindow
.
PenWidth
PColor
=
GraphicsWindow
.
PenColor
GraphicsWindow
.
PenWidth
=
3
GraphicsWindow
.
BrushColor
=
"White"
If
TankHealthRec
[
i3
]
=
""
Then
TankHealthRec
[
i3
]
=
Shapes
.
AddRectangle
(
100
,
12
)
EndIf
GraphicsWindow
.
BrushColor
=
"Red"
GraphicsWindow
.
PenColor
=
"Red"
HealthBarInside
[
i3
]
=
Shapes
.
AddRectangle
(
94
,
6
)
GraphicsWindow
.
BrushColor
=
Color
GraphicsWindow
.
PenWidth
=
Size
GraphicsWindow
.
PenColor
=
PColor
TankHealth
[
i3
]
=
IntTankHealth
EndFor
CurrTnkHealth
=
IntTankHealth
IntTankHealth
=
IntTankHealth
+
TankHealthInc
TankHealthInc
=
TankHealthInc
+
TankHealthIncAcc
TankCost
=
TankCost
+
TankPriceInc
OutThisRound
=
0
EndSub
Sub
MoveTanks
For
i4
=
1
To
NumOfTanks
Tankx
[
i4
]
=
Tankx
[
i4
]
-
(
TankSpeed
+
TankVar
[
i4
]
)
Shapes
.
Move
(
Tank
[
i4
]
,
Tankx
[
i4
]
,
Tanky
[
i4
]
)
Shapes
.
Move
(
TankHealthRec
[
i4
]
,
Tankx
[
i4
]
+
5
,
Tanky
[
i4
]
+
(
TankHeight
+
20
)
)
Shapes
.
Move
(
HealthBarInside
[
i4
]
,
Tankx
[
i4
]
+
8
,
Tanky
[
i4
]
+
(
TankHeight
+
23
)
)
If
Tankx
[
i4
]
<
(
0
-
TankWidth
)
Then
Out
=
out
+
1
OutThisRound
=
OutThisRound
+
1
Tankx
[
i4
]
=
4000
EndIf
EndFor
EndSub
Sub
SetAim
For
i9
=
1
To
TurretNum
CanCalcFire
[
i9
]
=
"No"
EndFor
CanSetFire
=
"No"
For
i5
=
1
To
TurretNum
For
i6
=
1
To
NumOfTanks
Dify
=
Math
.
Max
(
Turret
[
i5
]
[
TurretType
[
i5
]
]
[
"y"
]
+
15
,
Tanky
[
i6
]
)
-
Math
.
Min
(
Turret
[
i5
]
[
TurretType
[
i5
]
]
[
"y"
]
+
15
,
Tanky
[
i6
]
)
Difx
=
Math
.
Max
(
Turret
[
i5
]
[
TurretType
[
i5
]
]
[
"x"
]
+
15
,
Tankx
[
i6
]
)
-
Math
.
Min
(
Turret
[
i5
]
[
TurretType
[
i5
]
]
[
"x"
]
+
15
,
Tankx
[
i6
]
)
Dist
=
Math
.
SquareRoot
(
(
Dify
*
Dify
)
+
(
Difx
*
Difx
)
)
If
Dist
<=
TurretProp
[
TurretType
[
i5
]
]
[
"Range"
]
Then
Posx
[
i5
]
=
Tankx
[
i6
]
+
(
TankWidth
/
2
)
Posy
[
i5
]
=
Tanky
[
i6
]
+
(
TankHeight
/
2
)
CanCalcFire
[
i5
]
=
"Yes"
EndIf
EndFor
EndFor
EndSub
Sub
HitTank
TankHealth
[
i7
]
=
TankHealth
[
i7
]
-
TurretProp
[
TurretType
[
i1
]
]
[
"Damage"
]
Time
[
i1
]
[
i2
]
=
100
If
TankHealth
[
i7
]
<=
0
Then
Tankx
[
i7
]
=
3000
TurretKills
[
i1
]
=
TurretKills
[
i1
]
+
1
Kills
=
Kills
+
1
Money
=
Money
+
TankCost
EndIf
BarWidth
=
(
TankHealth
[
i7
]
/
CurrTnkHealth
)
*
94
Shapes
.
Remove
(
HealthBarInside
[
i7
]
)
Color
=
GraphicsWindow
.
BrushColor
PColor
=
GraphicsWindow
.
PenColor
GraphicsWindow
.
PenColor
=
"Red"
GraphicsWindow
.
BrushColor
=
"Red"
If
BarWidth
>
1
Then
HealthBarInside
[
i7
]
=
Shapes
.
AddRectangle
(
BarWidth
,
6
)
Shapes
.
Move
(
HealthBarInside
[
i7
]
,
Tankx
[
i7
]
+
8
,
Tanky
[
i7
]
+
(
TankHeight
+
23
)
)
EndIf
GraphicsWindow
.
BrushColor
=
Color
GraphicsWindow
.
PenColor
=
PColor
EndSub
Sub
CalcXY
For
i1
=
1
To
TurretNum
If
TurretLive
[
i1
]
<>
"No"
Then
Shapes
.
SetText
(
KillsText
[
i1
]
,
"Kills: "
+
TurretKills
[
i1
]
)
If
GraphicsWindow
.
MouseX
>
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"x"
]
And
GraphicsWindow
.
MouseX
<
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"x"
]
+
30
And
GraphicsWindow
.
MouseY
>
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"y"
]
And
GraphicsWindow
.
MouseY
<
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"y"
]
+
30
Then
Shapes
.
ShowShape
(
RangeCir
[
i1
]
)
Shapes
.
ShowShape
(
KillsText
[
i1
]
)
Shapes
.
ShowShape
(
TurretName
[
i1
]
)
Else
Shapes
.
HideShape
(
RangeCir
[
i1
]
)
Shapes
.
HideShape
(
KillsText
[
i1
]
)
Shapes
.
HideShape
(
TurretName
[
i1
]
)
EndIf
GetAngle
(
)
Shapes
.
Rotate
(
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"Top"
]
,
Angle
[
i1
]
)
For
i2
=
1
To
BallCount
For
i7
=
1
To
NumOfTanks
If
x
[
i1
]
[
i2
]
>
Tankx
[
i7
]
And
x
[
i1
]
[
i2
]
<
Tankx
[
i7
]
+
TankWidth
And
y
[
i1
]
[
i2
]
>
Tanky
[
i7
]
And
y
[
i1
]
[
i2
]
<
Tanky
[
i7
]
+
TankHeight
Then
HitTank
(
)
EndIf
If
(
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"x"
]
+
30
)
>
Tankx
[
i7
]
And
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"x"
]
<
Tankx
[
i7
]
+
TankWidth
And
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"y"
]
+
15
>
Tanky
[
i7
]
And
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"y"
]
<
Tanky
[
i7
]
+
TankHeight
Then
T2D
=
i1
DeadAng
[
i1
]
=
Angle
[
i1
]
DestroyTurret
(
)
EndIf
EndFor
Time
[
i1
]
[
i2
]
=
Time
[
i1
]
[
i2
]
+
.005
If
CanCalcFire
[
i1
]
=
"Yes"
Then
TimeCurrent
[
i1
]
=
Clock
.
ElapsedMilliseconds
-
TimeStart
[
i1
]
EndIf
If
TimeCurrent
[
i1
]
>=
TurretProp
[
TurretType
[
i1
]
]
[
"ROF"
]
Then
TimeStart
[
i1
]
=
Clock
.
ElapsedMilliseconds
Turret2Fire
=
i1
Angle2Fire
=
Angle
[
i1
]
TurretType2
=
TurretType
Fire
(
)
CanFire
[
i1
]
=
"No"
EndIf
x
[
i1
]
[
i2
]
=
Vh
[
i1
]
[
i2
]
*
Time
[
i1
]
[
i2
]
+
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"x"
]
y
[
i1
]
[
i2
]
=
Vv
[
i1
]
[
i2
]
*
Time
[
i1
]
[
i2
]
+
(
Math
.
Power
(
Time
[
i1
]
[
i2
]
,
2
)
)
+
Turret
[
i1
]
[
TurretType
[
i1
]
]
[
"y"
]
Shapes
.
Move
(
Ball
[
i1
]
[
i2
]
,
x
[
i1
]
[
i2
]
,
y
[
i1
]
[
i2
]
)
Shapes
.
Rotate
(
Ball
[
i1
]
[
i2
]
,
Ang
[
i1
]
[
i2
]
-
90
)
EndFor
EndIf
EndFor
EndSub
Sub
DestroyTurret
Wreck
[
T2D
]
=
Shapes
.
AddImage
(
Img6
)
Shapes
.
Move
(
Wreck
[
T2D
]
,
Turret
[
T2D
]
[
TurretType
[
T2D
]
]
[
"x"
]
,
Turret
[
T2D
]
[
TurretType
[
T2D
]
]
[
"y"
]
)
WreckTop
[
T2D
]
=
Shapes
.
AddImage
(
Img5
)
Shapes
.
Rotate
(
WreckTop
[
T2D
]
,
DeadAng
[
T2D
]
)
Shapes
.
Move
(
WreckTop
[
T2D
]
,
Turret
[
T2D
]
[
TurretType
[
T2D
]
]
[
"x"
]
+
5
,
Turret
[
T2D
]
[
TurretType
[
T2D
]
]
[
"y"
]
-
5
)
Turret
[
T2D
]
[
TurretType
[
T2D
]
]
[
"y"
]
=
6000
Shapes
.
Remove
(
Turret
[
T2D
]
[
TurretType
[
T2D
]
]
[
"Top"
]
)
TankHealth
[
i7
]
=
TankHealth
[
i7
]
-
TurretProp
[
TurretType
[
T2D
]
]
[
"Price"
]
*
20
TurretLive
[
i1
]
=
"No"
BarWidth
=
(
TankHealth
[
i7
]
/
CurrTnkHealth
)
*
94
Shapes
.
Remove
(
HealthBarInside
[
i7
]
)
Color
=
GraphicsWindow
.
BrushColor
PColor
=
GraphicsWindow
.
PenColor
GraphicsWindow
.
PenColor
=
"Red"
GraphicsWindow
.
BrushColor
=
"Red"
If
BarWidth
>
1
Then
HealthBarInside
[
i7
]
=
Shapes
.
AddRectangle
(
BarWidth
,
6
)
Shapes
.
Move
(
HealthBarInside
[
i7
]
,
Tankx
[
i7
]
+
8
,
Tanky
[
i7
]
+
(
TankHeight
+
23
)
)
EndIf
GraphicsWindow
.
BrushColor
=
Color
GraphicsWindow
.
PenColor
=
PColor
If
TankHealth
[
i7
]
<=
0
Then
Tankx
[
i7
]
=
3000
TurretKills
[
i1
]
=
TurretKills
[
i1
]
+
1
Kills
=
Kills
+
1
Money
=
Money
+
TankCost
TurretDeaths
=
TurretDeaths
+
1
EndIf
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.