Microsoft Small Basic

Program Listing: BXB154
'=============================================
'Radio Blaster 2.0
'
'by Vince Long, May 2011
' images from www.openclipart.org and OpenGameArt.org
'=============================================

Init_Stuff()

Splash_Screen()
'Begin_Game()

'================================
'Begin_Game
'================================
Sub Begin_Game

state = "game"
Timer.Resume()
GraphicsWindow.DrawImage(background, 0, 0)

'Load the TV images
For i = 1 to number_of_tvs
tv[i] = Shapes.AddImage(Path + "\Antique_Television-small.png")
tvX[i] = Math.GetRandomNumber(520)+60
tvY[i] = Math.GetRandomNumber(375)
tvY[i] = -tvY[i]
Shapes.Move(tv[i],tvX[i],tvY[i])
endfor


'Load the Radio image
radio = Shapes.AddImage(Path + "\oldradio-small.png")
Shapes.Move(radio,radioX,radioY)

'Load the bullet images
For i = 1 to number_of_bullets
bullet[i] = Shapes.AddImage(Path + "\tower_mini.gif")
Shapes.HideShape(bullet[i])
bulletActive[i] = 0
bulletX = 0
bulletY[i] = 60
endFor

' Load the explosion images
For i = 1 To 16
boom[i] = Shapes.AddImage(Path + "\BOOM"+i+".gif")
Shapes.HideShape(boom[i])
endFor

' Draw Score Box
GraphicsWindow.PenColor = "black"
GraphicsWindow.PenWidth = "2"
GraphicsWindow.DrawRectangle(1,1,200,35)
GraphicsWindow.BrushColor = "#ffe5aa"
GraphicsWindow.FillRectangle(2,2,198,33)
GraphicsWindow.BrushColor = "#b04c4b"
GraphicsWindow.FontSize = 10
GraphicsWindow.FontBold = "True"
GraphicsWindow.DrawText(3,5,"Score: "+score+" hits, "+misses+" misses, "+landedTVs+" landed TVs")
GraphicsWindow.DrawText(3,18,"M to Quit to Menu")
endSub

'================================
'Setup things
'================================
Sub Init_Stuff

Timer.Interval = 50
Timer.Tick = Update_the_stuff
Timer.Pause()

initKeys()

number_of_bullets = 3
score = 0
misses = 0
landedTVs = 0
radioX = 320
radioY = GraphicsWindow.Height - 65

Path = Program.Directory

GraphicsWindow.KeyDown=KeyPressed
GraphicsWindow.MouseDown = OnMouseDown

endSub



'=================================
' Update_the_stuff
'=================================
Sub Update_the_stuff

' Update the TVs
For i = 1 to number_of_tvs

tvY[i] = tvY[i] + 2

If tvY[i] > 380 AND tvY[i] < 490 then

GraphicsWindow.DrawImage(staticTV, tvX[i],380)
landedTVs = landedTVs + 1
Update_Scorebox()
If number_of_tvs = landedTVs Then
You_Lose()
endIf
tvX[i] = Math.GetRandomNumber(520)+60
tvY[i] = -50
ElseIf tvY[i] > 380 Then
tvX[i] = Math.GetRandomNumber(520)+60
tvY[i] = -50
endIf


Shapes.Move(tv[i],tvX[i],tvY[i])

endFor


' Update the bullets
For i = 1 to number_of_bullets

If bulletActive[i] = 1 Then
bulletY[i] = bulletY[i] - 5

If bulletY[i] < -50 then
bulletActive[i] = 0
misses=misses + 1
Update_Scorebox()
endIf

Shapes.Move(bullet[i],bulletX[i],bulletY[i])
EndIf
endFor

Collision_Checker()
endSub



'=================================
' Mouse Click - Release a bullet
'=================================
Sub OnMouseDown

For i = 1 to number_of_bullets
If bulletActive[i] = 0 Then
bulletActive[i] = 1
bulletX[i] = radioX + 20
bulletY[i] = GraphicsWindow.Height - 110
Shapes.Move(bullet[i],bulletX[i],bulletY[i])
Shapes.ShowShape(bullet[i])
i = number_of_bullets
endIf
endFor

EndSub


'==============================
'Init the keys
'==============================
Sub initKeys

keyOne = "D1"
keyTwo = "D2"
keyThree = "D3"
keyFour = "D4"
keyM = "M"
keyQ = "Q"
right = "Right"
left = "Left"

endSub

'============================
'Keypressed subroutine
'==============================

Sub KeyPressed

If state = "menu" Then
GraphicsWindow.Clear()
If GraphicsWindow.LastKey = keyOne then
number_of_tvs = 3
Begin_Game()
elseIf GraphicsWindow.LastKey = keyTwo then
number_of_tvs = 8
Begin_Game()
elseIf GraphicsWindow.LastKey = keyThree then
number_of_tvs = 12
Begin_Game()
elseIf GraphicsWindow.LastKey = keyFour then
Program.End()
EndIf


ElseIf state = "game" Then

If GraphicsWindow.LastKey = right Then
radioX = radioX + 10
If radioX > 570 Then
radioX = 570
endIf
Shapes.Move(radio, radioX, GraphicsWindow.Height - 65)
elseIf GraphicsWindow.LastKey = left Then
radioX = radioX - 10
If radioX < 5 Then
radioX = 5
endIf
Shapes.Move(radio, radioX, GraphicsWindow.Height - 65)
elseIf GraphicsWindow.LastKey = keyM then
Init_Stuff()
Splash_Screen()
elseIf GraphicsWindow.LastKey = keyQ then
Program.End()
endif

endIf
endSub


' ======================
' check for collisions
'======================
Sub Collision_Checker

For i = 1 to number_of_bullets
For j = 1 To number_of_tvs
If bulletActive[i] = 1 then

' determine if there is a collision by measuring the delta x and y values
thisTVx = Shapes.GetLeft(tv[j]) + 15
thisTVy = Shapes.GetTop(tv[j]) + 69

thisbulletx = Shapes.GetLeft(bullet[i]) + 12
thisbullety = Shapes.GetTop(bullet[i]) + 2

deltaX = Math.Abs(thisbulletx - thisTVx)
deltaY = Math.Abs(thisbullety - thisTVy)

If deltaX < 15 AND deltaY < 15 then

' deactivate the bullet
bulletActive[i] = 0
score = score + 1

Update_Scorebox()

' hide the tv and move it below the screen
Shapes.HideShape(tv[j])
tvY[j] = 500
Shapes.Move(tv[j],tvX[j],tvY[j])
Shapes.ShowShape(tv[j])
Shapes.HideShape(bullet[i])

'create the explosion
Make_boom()
endIf

endIf
endFor
endFor

endSub

'===============================
' Update the scorebox
'===============================
Sub Update_Scorebox
GraphicsWindow.BrushColor = "#ffe5aa"
GraphicsWindow.FillRectangle(2,2,198,33)
GraphicsWindow.BrushColor = "#b04c4b"
GraphicsWindow.FontSize = 10
GraphicsWindow.FontBold = "True"
GraphicsWindow.DrawText(3,5,"Score: "+score+" hits "+misses+" misses "+landedTVs+" landed TVs")
GraphicsWindow.DrawText(3,18,"M to Quit to Menu")
endSub
'===============================
' Animate the explosion
'===============================
Sub Make_boom
boomx = thisTVx
boomy = thisTVy
thisTVx = 0
thisTVy = 0
For b = 1 To 16
Shapes.Move(boom[b],boomx - 15,boomy - 30)
Shapes.ShowShape(boom[b])
Program.Delay(70)
Shapes.HideShape(boom[b])
EndFor
endSub

'===============================
' Splash Screen and Menu
'===============================
Sub Splash_Screen
background = ImageList.LoadImage( Path + "\chicago.gif")

GraphicsWindow.FontSize = "12"
GraphicsWindow.Title = "Old Time Radio Blaster Game"
GraphicsWindow.Show()

p_bar = ImageList.LoadImage(Path + "\p_bar.gif")
my_p_bar = Shapes.AddImage(p_bar)
Shapes.HideShape(my_p_bar)

GraphicsWindow.DrawText(250,70,"Loading data...")
GraphicsWindow.DrawLine(98,88,542,88)
GraphicsWindow.DrawLine(542,88,542,112)
GraphicsWindow.DrawLine(98,112,542,112)
GraphicsWindow.DrawLine(98,88,98,112)

Program.Delay(10)
'For i = 100 to 530
' Shapes.ShowShape(my_p_bar)
' Shapes.Move(my_p_bar,i,90)
' Program.Delay(10)
'endFor
Shapes.HideShape(my_p_bar)
GraphicsWindow.Clear()
GraphicsWindow.DrawImage(background, 0, 0)

' Load a Static TV
staticTV = ImageList.LoadImage( Path + "\Antique_Television-small.png")
GraphicsWindow.DrawImage(staticTV, 560,20)

' Load a Static Radio
staticRadio = ImageList.LoadImage( Path + "\oldradio-small.png")
GraphicsWindow.DrawImage(staticRadio, 25,32)

GraphicsWindow.BrushColor="Black"
GraphicsWindow.FontSize = 30
GraphicsWindow.FontBold = "True"
GraphicsWindow.DrawText(95,30,"Old Time Radio Blaster Game")

Play = 2
GraphicsWindow.FontSize = 15
GraphicsWindow.BrushColor = "yellow"
GraphicsWindow.DrawText(120,70,"Use your skills to stop the invasion of the televisions")
GraphicsWindow.DrawText(185,85,"and their threat of world domination. ")


mText[4] = "Use the keyboard arrow keys to move your Radio Blaster left and right."
mText[5] = "Use the left button on the mouse to launch Radio Tower Projectiles."
mText[6] = ""
mText[7] = "1. Level 1 - Easy (3 targets at a time, 3 landed TVs loses)"
mText[8] = "2. Level 2 - Medium (8 targets at a time, 8 landed TVs loses)"
mText[9] = "3. Level 3 - Easy (12 targets at a time, 12 landed TVs loses)"
mText[10] = "4. Quit"


GraphicsWindow.FontSize = 11
GraphicsWindow.BrushColor = "blue"
LineLocation = 275

For i = 4 to 6
LineLocation = LineLocation + 17
GraphicsWindow.DrawText(120,LineLocation,mText[i])
endFor
For i = 7 to 10
LineLocation = LineLocation + 17
GraphicsWindow.DrawText(170,LineLocation,mText[i])
endFor
GraphicsWindow.DrawText(170,425,"Make a Choice")
GraphicsWindow.FontBold = "False"
state = "menu"
endSub

Sub You_Lose
Timer.Pause()
For i = 1 to number_of_tvs
Shapes.HideShape(tv[i])
endfor
GraphicsWindow.BrushColor="#ffff95"
GraphicsWindow.FontSize = 30
GraphicsWindow.FontBold = "True"
GraphicsWindow.DrawText(225,35,"You Lose!")
For i = 1 To 60
tvMassX[i] = Math.GetRandomNumber(520)+60
tvMassY[i] = Math.GetRandomNumber(375)
tvMassY[i] = -tvMassY[i]
tvMass[i] = Shapes.AddImage(Path + "\Antique_Television-small.png")
Shapes.Move(tvMass[i],tvMassX[i],tvMassY[i])
Shapes.Animate(tvMass[i],tvMassX[i],380,3000)
endFor
endSub