⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shooterdemo.frm

📁 VB编写的非常好的小游戏
💻 FRM
📖 第 1 页 / 共 3 页
字号:
Case "LEFT"
For i = 1 To 5
If kill(10 + i) = False And xi5(i) > 100 Then xi5(i) = xi5(i) - 200
If xi5(i) < 200 And kill(10 + i) = False And xi5(i) > -100 Then
Mi5 = "RIGHT"
For q = 1 To 5
If boom = True And xinv = xi5(q) Then Exit For
yi5(q) = yi5(q) + 155
Next
End If
Next
GoTo 5
Case "RIGHT"
For i = 1 To 5
If kill(10 + i) = False And xi5(i) > -100 And xi5(i) < (Form1.Width - sprINVADER5.Width) Then xi5(i) = xi5(i) + 200
If xi5(i) > (Form1.Width - sprINVADER5.Width) And kill(10 + i) = False Then
Mi5 = "LEFT"
For q = 1 To 5
If boom = True And xinv = xi5(q) Then Exit For
yi5(q) = yi5(q) + 155
Next
End If
Next
5 End Select
'If the good guy killed 15 aliens,start
'a new level by calling the Form_Activate procedure
Select Case dead
Case 15
dead = 0: Cls
Call Form_Activate
End Select

'If there is an explosion going on somewhere on the
'form (Boom=true) then paint the correct frame of
'it (the variable Explosion represents the number
'of the frame that must be currently painted)
Select Case boom
Case True
Select Case explosion
Case 1
'If the explosion has just started (explosion=1)
'then don't paint any frame of it,just erase the
'alien that has been shot by painting the label
'lblBlank on him.
'lnlBlank is a black label used every now and then
'to erase something from the form.It's Left and
'Top properties have been assigned the X and Y
'coordinates of the alien that's being killed
'as you read these lines.This was done from the
'Kaboom procedure,where the Boom variable was
'assigned the value True and the whole explosion
'buisness began
lblBlank.Visible = True
lblBlank.Visible = False
Case Is <> 1
'If the explosion has already started before the
'current timer event then paint the current frame
'of the explosion on the alien that was just killed.
'Xinv and Yinv are the coordinates of the alien
'that get's his butt kicked every time the good
'guy hits bullseye.
Select Case xinv
Case xi1
PaintPicture imgKABOOM(explosion).Picture, xi1, yi1 - 100
Case xi2(1)
PaintPicture imgKABOOM(explosion).Picture, xi2(1) + 200, yi2(1) - 100
Case xi2(2)
PaintPicture imgKABOOM(explosion).Picture, xi2(2) + 200, yi2(2) - 100
Case xi3(1)
PaintPicture imgKABOOM(explosion).Picture, xi3(1) + 150, yi3(1) - 100
Case xi3(2)
PaintPicture imgKABOOM(explosion).Picture, xi3(2) + 150, yi3(2) - 100
Case xi3(3)
PaintPicture imgKABOOM(explosion).Picture, xi3(3) + 150, yi3(3) - 100
Case xi4(1)
PaintPicture imgKABOOM(explosion).Picture, xi4(1) - 30, yi4(1) - 100
Case xi4(2)
PaintPicture imgKABOOM(explosion).Picture, xi4(2) - 30, yi4(2) - 100
Case xi4(3)
PaintPicture imgKABOOM(explosion).Picture, xi4(3) - 30, yi4(3) - 100
Case xi4(4)
PaintPicture imgKABOOM(explosion).Picture, xi4(4) - 30, yi4(4) - 100
Case xi5(1)
PaintPicture imgKABOOM(explosion).Picture, xi5(1) - 30, yi5(1) - 100
Case xi5(2)
PaintPicture imgKABOOM(explosion).Picture, xi5(2) - 30, yi5(2) - 100
Case xi5(3)
PaintPicture imgKABOOM(explosion).Picture, xi5(3) - 30, yi5(3) - 100
Case xi5(4)
PaintPicture imgKABOOM(explosion).Picture, xi5(4) - 30, yi5(4) - 100
Case xi5(5)
PaintPicture imgKABOOM(explosion).Picture, xi5(5) - 30, yi5(5) - 100
End Select
End Select
'Add 1 to the value of Explosion so that a new frame
'of it will be painted in the next timer event
explosion = explosion + 1
Select Case explosion
Case 7
'if all the frames of the explosion have been painted
'then the alien whose coordinates are the same
'with the values of Xinv and Yinv is officialy dead
'and the fun ends (Boom=false)
explosion = 0
boom = False
If YouDied = True Then Form_Activate
'Let's see that score increase...
score = score + 1000
'Onother one bites the dust.(15-dead) to go
dead = dead + 1
'paint the blank label on the exact spot where
'the explosion frames were painted incase there
'is some smoke left floating there.
'**(There is still a little bug and sometimes
'  (the smoke remains there.Oh well...)
lblBlank.Left = xinv
lblBlank.Top = yinv - 100
lblBlank.Visible = True
lblBlank.Visible = False
'If an alien was just killed,then give his X coordinate
'a very low value (-5000) so that he wont be visible
'on the form
If kill(1) = True Then xi1 = -5000: kill(1) = False
For i = 1 To 2
If kill(i + 1) = True Then xi2(i) = -5000: kill(i + 1) = False: Exit For
Next
For i = 1 To 3
If kill(3 + i) = True Then xi3(i) = -5000: kill(3 + i) = False: Exit For
Next
If kill(7) = True Then xi4(1) = -5000: kill(7) = False
If kill(8) = True Then xi4(2) = -5000:: kill(8) = False
If kill(9) = True Then xi4(3) = -5000: kill(9) = False
If kill(10) = True Then xi4(4) = -5000: kill(10) = False
For i = 1 To 5
If kill(10 + i) = True Then xi5(i) = -5000: kill(10 + i) = False
Next
End Select
Case False
End Select
'If the good guy has just fired his blaster,draw
'a line .The upper bound is determined by how
'high the alien that will be killed is.(if this
'shot wont kill an alien then it will go all the
'way up to the upper edge of the form).In fact
'each time the good guy shoots ,3 lines are drawn
'one after the other on the exact same spot and
'with the exact same length.The first is either
'blue or white,the second is either white or
'blue and the third is black so that
'the "shot ring" will be erased.This is how the
'cool "laser blaster" effect is done
Select Case shot
Case 1
Line (xshot, y2)-(xshot, upper), COL2
shot = 2
Case 2
Line (xshot, y2)-(xshot, upper), BackColor
shot = 0
End Select
'Move the spaceship according to the value of the
'variable Movement.As in most shoot'em up games,the
'ship continues moving towards the direction it has
'been last guided to until it meets the edge of the
'form or onother direction is given.Normally this
'would be done by the user hitting a cursor key
'but in this demo it's done by inputing a new
'keyword command from the file DEMO.DAT
Select Case movement
Case "Left"
x2 = x2 - 210
If x2 < -320 Then x2 = -320
PaintPicture sprSHIP.Picture, x2, y2
Case "Right"
x2 = x2 + 210
If x2 > Form1.Width - 1700 Then x2 = Form1.Width - 1700
PaintPicture sprSHIP.Picture, x2, y2
End Select
'Move the star field that's on the background.
For i = 1 To 30
Circle (X(i), Y(i)), size(i), BackColor
Y(i) = Y(i) + pace(i)
'If a star reaches the bottom of the form then
'it is assigned a new X coordinate and in the next
'timer event it will start falling again ( Y(i)=0)
If Y(i) >= Form1.Height Then Y(i) = 0: X(i) = Int(Form1.Width * Rnd)
Select Case pace(i)
'There are 30 circles of various sizes.Each one
'moves with a different speed and according to his
'speed it is painted with a different shade of grey.
'Stars that move slow are painted almost black 'cause
'they are located deep in space.The ones that move
'quick are almost white because they zip by near
'the camera,they're also bigger than then slow ones.
Case Is <= 200
clr = &H404040
Case Is <= 300
clr = &H808080
Case Is <= 400
clr = &HC0C0C0
Case Else
clr = &HFFFFFF
End Select
Circle (X(i), Y(i)), size(i), clr
Next
'Paint the good guy
PaintPicture sprSHIP.Picture, x2, y2
'Paint the aliens that are not dead,in other
'words the ones for whom Kill(#of alien)=false
'Remember 1<= #of alien <=15
If kill(1) = False Then PaintPicture sprINVADER5.Picture, xi1, yi1
For i = 1 To 2
If kill(1 + i) = False Then PaintPicture sprINVADER5.Picture, xi2(i), yi2(i)
Next
For i = 1 To 3
If kill(3 + i) = False Then PaintPicture sprINVADER5.Picture, xi3(i), yi3(i)
Next
For i = 1 To 4
If kill(6 + i) = False Then PaintPicture sprINVADER5.Picture, xi4(i), yi4(i)
Next
For i = 1 To 5
If kill(10 + i) = False Then PaintPicture sprINVADER5.Picture, xi5(i), yi5(i)
Next
End Sub

'Pull that trigger...
Private Sub fire()

Select Case boom
Case True
Exit Sub
'...but if an explosion is going on,don't fire,
'there's no need to waste ammo
End Select
upper = 1000
Select Case shot
Case Is <> 0
'Also if the previous shot hasn't yet been painted
'in all of it's 3 colors,don't fire onother one
Exit Sub
End Select
shot = 1
'Play the sound fx using API's
Result = sndPlaySound(App.Path & "\fire.wav", &H1)
xshot = x2 + 1062
'Xshot is the X coordinate of the laser beem.The
'weapon of the ship is in the middle,so it's
'Xshot = x2 + 1062 (x2 is the X coordinate of the ship)
'Keep in mind that the sprite has a lot of space
'in each side of the actual ship otherwise it would
'leave trails on the form when it moves
'
'Check if the Xshot is anywhere near an alien
'and "kill" him if so ( kill(#of alien)=True).He
'may not yet be officialy dead since the
'explosion hasn't been painted on him,but that's
'a matter of milliseconds if his KILL array element
'is set to True.
If Abs(xi1 + (sprINVADER5.Width / 2) - xshot) < (sprINVADER5.Width / 4) Then kill(1) = True Else kill(1) = False
If Abs(xi2(1) + (sprINVADER5.Width / 2) - xshot) < (sprINVADER5.Width / 3) Then kill(2) = True Else kill(2) = False
If Abs(xi2(2) + (sprINVADER5.Width / 2) - xshot) < (sprINVADER5.Width / 3) Then kill(3) = True Else kill(3) = False
For i = 1 To 3
If Abs(xi3(i) + (sprINVADER5.Width / 2) - xshot) < (sprINVADER5.Width / 2) Then kill(3 + i) = True: Exit For Else kill(3 + i) = False
Next
For i = 1 To 4
If Abs(xi4(i) + (sprINVADER5.Width / 2) - xshot) < (sprINVADER5.Width / 2) Then kill(6 + i) = True: Exit For Else kill(6 + i) = False
Next
For i = 1 To 5
If Abs(xi5(i) + (sprINVADER5.Width / 2) - xshot) < (sprINVADER5.Width / 3) Then kill(10 + i) = True: Exit For Else kill(10 + i) = False
Next
If kill(1) = True Then xinv = xi1: yinv = yi1: upper = yi1: Call kaboom
If kill(2) = True Then xinv = xi2(1): yinv = yi2(1): upper = yi2(1): Call kaboom:
If kill(3) = True Then xinv = xi2(2): yinv = yi2(2): upper = yi2(2): Call kaboom:
For i = 1 To 3
If kill(i + 3) = True Then xinv = xi3(i): yinv = yi3(i): upper = yi3(i): Call kaboom:
Next
For i = 1 To 4
If kill(6 + i) = True Then xinv = xi4(i): yinv = yi4(i): upper = yi4(i): Call kaboom:
Next
For i = 1 To 5
If kill(10 + i) = True Then xinv = xi5(i): yinv = yi5(i): upper = yi5(i): Call kaboom:
Next
aa = 0
'Check if the shot "killed" some more aliens
'that were above the unlucky one and "ressurect"
'them since laser blasters don't go through
'metal.Only railguns in Quake2...
For i = 15 To 1 Step -1
If kill(i) = True Then aa = i: Exit For
Next
For i = 1 To 15
If i <> aa Then kill(i) = False
Next

11 Line (x2 + 1062, y2)-(xshot, upper), BackColor
'Randomly choose a color for the first of three
'laser beems ...
D = Int(2 * Rnd)
Select Case D
Case 0
COL1 = &HFFFFFF
COL2 = &HFF0000
Case Else
COL1 = &HFF0000
COL2 = &HFFFFFF
End Select
'and paint it...If this one was blue,the second will
'be white and vise versa.The third is always the
'black one that "erases" the trail of the shot
Line (x2 + 1062, y2)-(x2 + 1062, upper), COL1
End Sub

'The procedure that runs everytime you shoot an alien.
'He still has no idea what's in store for him but
'these lines of code will fix him up good
Private Sub kaboom()
'Place the blank label on the unlucky alien so that
'he's erased on the next timer event,before the
'frames of the explosion start showing
lblBlank.Top = yinv
lblBlank.Left = xinv
boom = True
'...and start the fun by setting the Explosion variable
'to 1.In the next timer event a beautiful explosion
'will go off on an ugly alien's face
explosion = 1
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -