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

📄 shooterdemo.frm

📁 VB编写的非常好的小游戏
💻 FRM
📖 第 1 页 / 共 3 页
字号:
    x2 = ScaleWidth / 2 - sprSHIP.Width / 2
    y2 = ScaleHeight - sprSHIP.Height
'Set starting values for the coordinates of
'the 15 aliens.The syntax
' For I=1 to N
' X=(Container.Width * (N-I)/N)-(Control.Width/2)
' Next
'can be used to horizontaly center N identical
'controls in a container (Form,picture box etc)
 xi1 = (Form1.Width / 2) - (sprINVADER5.Width / 2)
 yi1 = 1000
 For i = 1 To 2
 yi2(i) = yi1 + sprINVADER5.Height + 50
 Next
 xi2(1) = (Form1.Width / 2) - (Form1.Width / 8) - (sprINVADER5.Width / 2)
 xi2(2) = (Form1.Width / 2) + (Form1.Width / 8) - (sprINVADER5.Width / 2)
 For i = 1 To 3
 yi3(i) = yi2(1) + sprINVADER5.Height + 50
 xi3(i) = ((Form1.Width * (4 - i) / 4) - (sprINVADER5.Width / 2))
 Next
 For i = 1 To 4
 yi4(i) = yi3(1) + sprINVADER5.Height + 200
 xi4(i) = ((Form1.Width * (5 - i) / 5) - (sprINVADER5.Width) / 2)
 Next
 For i = 1 To 5
 yi5(i) = yi4(1) + sprINVADER5.Height + 300
 xi5(i) = ((Form1.Width * (6 - i) / 6) - (sprINVADER5.Width) / 2)
 Next
End Sub

'The procedure that would normally run when
'the user hits the cursor keys or the space bar
'but in this demo version of the game runs when
'a new command keyword is retrieved from the file
'DEMO.DAT

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeySpace
Call fire
Case vbKeyLeft
movement = "Left"
Case vbKeyRight
movement = "Right"
Case Else
movement = ""
End Select
End Sub

'The procedure that needs to be executed only one
'time ,when you run the application.It opens the
'text file that contains the command keywords.The
'text file remains open until the user hits the
'EXIT button
Private Sub Form_Load()
ChDir App.Path
Dim ModFile As String
ModFile = App.Path & "\Moonlite.mod"
RetVal = ModPlug_CreateEx("loop|true")
XOX = ModPlug_SetWindow(RetVal, Form2.hwnd)
ModFileName$ = ModFile
XOX = ModPlug_Load(RetVal, ModFileName$)
XOX = ModPlug_Play(RetVal)
F = App.Path & "\demo.dat"
'Code to play the MOD file with the ModPlug
'Plug-in npmod32.DLL
Open F For Input As #1
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
cmdExit_Click
End Sub

'This procedure is here in case you click the X
'button on the upper right of the form instead
'of the exit button.It makes sure that the text
'file closes before the application ends


'The procedure that executes every 0,001 sec and
'controls just about everything goes on in the
'game.The general idea is that event procedures all
'all around the project alter the values of FLAG
'variables like BOOM,SHOT,X2 etc and this procedure
'uses those values to do whatever the event is about.
Private Sub Timer1_Timer()
'---------------------------------------
'Retrieve a command keyword from the text file and
'call the Form_KeyDown event with the proper argument.
'This is how the program emulates a real user playing
'the game
'
   Select Case Wait
   Case 0
   If EOF(1) = True Then
   Close
   Open App.Path & "\demo.dat" For Input As #1
'When Wait=0 it means that the random delay from the
'last action of the spaceship has expired and a new
'command keyword needs to be inputed.If the items
'of the file have been all used and the counter
'has reached the end of the file (   EOF(1)=True   )
'then reopen the file and start over again.
   Else
'If not,input the next keyword,
   Input #1, Action
   Select Case Action
'and emulate the user hitting keys by calling
'the Form_KeyDown event and passing it a constant
'that represents the action to be carried out.
' vbKeySpace=shoot
' vbKeyLeft=move left
' vbKeyRight=move right
'The second constant is the state of the SHIFT key,
'it has no use in this project
   Case "fire"
   Call Form_KeyDown(vbKeySpace, 1)
   Case "left"
   Call Form_KeyDown(vbKeyLeft, 1)
   Case "right"
   Call Form_KeyDown(vbKeyRight, 1)
   End Select
     
'If the good guy fires his weapon (Action="fire")
'then there's no reason to delay his next move.
'Let Wait have the value 0 so that the next time
'the Timer event runs,a new command is inputed.If he
'has just moved (Action<>"fire") then give the
'variable Wait a random value from 0 to 10.This will
'determine how many milliseconds until a new command
'is retrieved from the text file
   If Action <> "fire" Then
    Randomize
    Wait = Int(Rnd * 10)
    Else: Wait = 0
   End If
   
'Show the user what command is carried out in the
'yellow textbox.Also,bring the cursor to the end of
'the text so that the text scrolls down
   txtCommandKeywords.Text = txtCommandKeywords.Text & UCase(Action) & vbCrLf
   txtCommandKeywords.SelStart = Len(txtCommandKeywords.Text)
   End If
   Case Else
'If Wait<>0 then it's not time for a new command.Just
'hang on tight and reduce the value of Wait by 1 so
'that soon it will be time for the new command .
   Wait = Wait - 1
   End Select
'-----------------------------------

'Check if the top alien has crushed on the ship
If (y2 - (yi1 + sprINVADER5.Height)) < -100 And Abs((xi1 + (sprINVADER5.Width / 2)) - (x2 + sprSHIP.Width / 2)) < (sprINVADER5.Width / 2) Then
'and if so
Timer1.Enabled = False
For q = 1 To 6
PaintPicture imgKABOOM(q).Picture, x2 + 600, y2
For l = 1 To 100000: Next
Next
Form_Activate
'halt everything (Timer1.Enabled=false),
'paint the 6 frames of the explosion on the good
'guy ( that is now a dead good guy) and start over
'a new level (Form_Activate)
End If
'Check if an alien from the second row has crushed
'on the ship
For i = 1 To 2
If (y2 - (yi2(i) + sprINVADER5.Height)) < -100 And Abs((xi2(i) + (sprINVADER5.Width / 2)) - (x2 + sprSHIP.Width / 2)) < (sprINVADER5.Width / 2) Then
Timer1.Enabled = False
For q = 1 To 6
PaintPicture imgKABOOM(q).Picture, x2 + 600, y2
For l = 1 To 100000: Next
Next
Form_Activate
End If
Next
'Check if an alien from the 3rd row has crushed
'on the ship
For i = 1 To 3
If (y2 - (yi3(i) + sprINVADER5.Height)) < -100 And Abs((xi3(i) + (sprINVADER5.Width / 2)) - (x2 + sprSHIP.Width / 2)) < (sprINVADER5.Width / 2) Then
Timer1.Enabled = False
For q = 1 To 6
PaintPicture imgKABOOM(q).Picture, x2 + 600, y2
For l = 1 To 100000: Next
Next
Form_Activate
End If
Next
'Check if an alien from the 4th row has crushed
'on the ship
For i = 1 To 4
If (y2 - (yi4(i) + sprINVADER5.Height)) < -100 And Abs((xi4(i) + (sprINVADER5.Width / 2)) - (x2 + sprSHIP.Width / 2)) < (sprINVADER5.Width / 2) Then
Timer1.Enabled = False
For q = 1 To 6
PaintPicture imgKABOOM(q).Picture, x2 + 600, y2
For l = 1 To 100000: Next
Next
Form_Activate
End If
Next
'Check if an alien from the lower row has crushed
'on the ship
For i = 1 To 5
If (y2 - (yi5(i) + sprINVADER5.Height)) < -100 And Abs((xi5(i) + (sprINVADER5.Width / 2)) - (x2 + sprSHIP.Width / 2)) < (sprINVADER5.Width / 2) Then
Timer1.Enabled = False
For q = 1 To 6
PaintPicture imgKABOOM(q).Picture, x2 + 600, y2
For l = 1 To 100000: Next
Next
Form_Activate
End If
Next
'If alien #1 is not dead...
Select Case kill(1)
Case False
Select Case xi1
Case Is > -230
'and he's on the visible part of the Form
'** (when an alien is shot,his X coordinate is given
'   a very low value (-5000) so that if by any
'   chance his sprite is painted on the form,you wont
'   see him)
Select Case Mi1
'Then move him towards the direction that the
'Mi1 variable points out
Case "LEFT"
xi1 = xi1 - 200
If xi1 < 0 Then Mi1 = "RIGHT": yi1 = yi1 + 155
Case "RIGHT"
xi1 = xi1 + 200
If xi1 > Form1.Width - sprINVADER5.Width Then Mi1 = "LEFT": yi1 = yi1 + 155
End Select
End Select
End Select
'Move the 2nd row aliens
Select Case Mi2
Case "LEFT"
If kill(2) = False And xi2(1) > 100 Then xi2(1) = xi2(1) - 200
If kill(3) = False And xi2(2) > 100 Then xi2(2) = xi2(2) - 200
'** (only if they're alive...)
If xi2(1) < 200 And kill(2) = False And xi2(1) > -100 Then
Mi2 = "RIGHT"
For q = 1 To 2
If boom = True And xinv = xi2(q) Then Exit For
yi2(q) = yi2(q) + 155
Next
End If
If xi2(2) < 200 And kill(3) = False And xi2(2) > -100 Then
Mi2 = "RIGHT"
For q = 1 To 2
If boom = True And xinv = xi2(q) Then Exit For
yi2(q) = yi2(q) + 155
Next
End If
GoTo 2
Case "RIGHT"
If kill(2) = False And xi2(1) > -100 And xi2(1) < (Form1.Width - sprINVADER5.Width) Then xi2(1) = xi2(1) + 200
If kill(3) = False And xi2(2) > -100 And xi2(2) < (Form1.Width - sprINVADER5.Width) Then xi2(2) = xi2(2) + 200
If xi2(1) > (Form1.Width - sprINVADER5.Width) And kill(2) = False Then
Mi2 = "LEFT"
For q = 1 To 2
If boom = True And xinv = xi2(q) Then Exit For
yi2(q) = yi2(q) + 155
Next
End If
If xi2(2) > (Form1.Width - sprINVADER5.Width) And kill(3) = False Then
Mi2 = "LEFT"
For q = 1 To 2
If boom = True And xinv = xi2(q) Then Exit For
yi2(q) = yi2(q) + 155
Next
End If
2 End Select
'Move the third row aliens
Select Case Mi3
Case "LEFT"
For i = 1 To 3
If kill(i + 3) = False And xi3(i) > 100 Then xi3(i) = xi3(i) - 200
If xi3(i) < 200 And kill(3 + i) = False And xi3(i) > -100 Then
Mi3 = "RIGHT"
For q = 1 To 3
If boom = True And xinv = xi3(q) Then Exit For
yi3(q) = yi3(q) + 155
Next
End If
Next
GoTo 3
Case "RIGHT"
For i = 1 To 3
If kill(3 + i) = False And xi3(i) > -100 And xi3(i) < (Form1.Width - sprINVADER5.Width) Then xi3(i) = xi3(i) + 200
If xi3(i) > (Form1.Width - sprINVADER5.Width) And kill(3 + i) = False Then
Mi3 = "LEFT"
For q = 1 To 3
If boom = True And xinv = xi3(q) Then Exit For
yi3(q) = yi3(q) + 155
Next
End If
Next
3 End Select
'Move the fourth row aliens
Select Case Mi4
Case "LEFT"
For i = 1 To 4
If kill(6 + i) = False And xi4(i) > 100 Then xi4(i) = xi4(i) - 200
If xi4(i) < 200 And kill(6 + i) = False And xi4(i) > -100 Then
Mi4 = "RIGHT"
For q = 1 To 4
If boom = True And xinv = xi4(q) Then Exit For
yi4(q) = yi4(q) + 155
Next
End If
Next
GoTo 4
Case "RIGHT"
For i = 1 To 4
If kill(6 + i) = False And xi4(i) > -100 And xi4(i) < (Form1.Width - sprINVADER5.Width) Then xi4(i) = xi4(i) + 200
If xi4(i) > (Form1.Width - sprINVADER5.Width) And kill(6 + i) = False Then
Mi4 = "LEFT"
For q = 1 To 4
If boom = True And xinv = xi4(q) Then Exit For
yi4(q) = yi4(q) + 155
Next
End If
Next
4 End Select
'Move the 5th row aliens
Select Case Mi5

⌨️ 快捷键说明

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