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

📄 module1.bas

📁 潜艇大战游戏源程序
💻 BAS
字号:
Attribute VB_Name = "Module1"
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Public Declare Function GetTickCount Lib "kernel32.dll" () As Long
Declare Function GetPixel Lib "gdi32.dll" (ByVal hdc As Long, ByVal nXPos As Long, ByVal nYPos As Long) As Long
Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Const SRCAND = &H8800C6
Public Const SRCPAINT = &HEE0086
Public Const SRCCOPY = &HCC0020



Public Type Coor
 X As Integer
 Y As Integer
 Act As Boolean
 Tag As Integer
End Type

Public Type Player
 X As Integer
 Y As Integer
 Ammo As Integer
 Dire As Byte
 Health As Integer
 Score As Long
 Speed As Currency
 Firetime As Currency
End Type

Public Type SubMarine
 X As Integer
 Y As Integer
 Act As Boolean
 Score As Integer
 Dire As Integer
 Speed As Integer
 Damaged As Integer
End Type

Public Type DropBombs
 X As Integer
 Y As Integer
 Act As Boolean
 Speed As Currency
End Type

Public Type Bomber
 X As Integer
 Y As Integer
 Act As Boolean
 Dire As Integer
 Speed As Integer
 BombLoad As Integer
 Droped As Boolean
End Type

Public Type HighScore
 PlName As String
 plScore As Long
 plDate As String
End Type


Public Const Bredde As Integer = 400
Public Const Hoyde As Integer = 360
Public Const ShipBredde = 53
Public Const ShipHoyde = 14
Public Const SubBredde = 36
Public Const SubHoyde = 10
Public Const PlaneBredde = 29
Public Const PlaneHoyde = 12
Public Const MaxAmmo = 7
Public P1 As Player
Public Shot(1 To 30) As Coor
Public Subs(1 To 30) As SubMarine
Public HighS(1 To 10) As HighScore
Public Planes(1 To 10) As Bomber
Public Bombs(1 To 30) As DropBombs
Public Explo(1 To 10) As Coor
Public TheKing As Coor
Public NumPlanes As Integer
Public NumSubs As Integer
Public NumShots As Integer
Public NumBombs As Integer
Public DontClose As Boolean
Public MainPause As Boolean


Public Function PlaySound(File As String)
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2
Const SND_LOOP = &H8
Const SND_NOSTOP = &H10
    wFlags% = SND_ASYNC Or SND_NODEFAULT
    Svar = sndPlaySound(App.Path & "\" & File & ".wav", wFlags%) 'Send the sound to the big world
End Function

Public Sub Fire()
Dim A As Integer
    
    If (GetTickCount - P1.Firetime) < 300 Then Exit Sub
    If P1.Ammo = 0 Then Exit Sub
    If NumShots = 30 Then Exit Sub
    
    P1.Firetime = GetTickCount
    P1.Ammo = P1.Ammo - 1
    NumShots = NumShots + 1
    
    
    A = 1
    Do Until Not Shot(A).Act
        A = A + 1
    Loop
    
    With Shot(A)
        .Act = True
        .Y = P1.Y + ShipHoyde
        .X = P1.X + (ShipBredde / 2)
    End With
End Sub

Public Sub MakeSub()
Dim A As Integer
    If NumSubs = 30 Then Exit Sub
    
    Randomize
    temp = (Rnd * 130)
    If temp < 2 + 30 - NumSubs Then
    
        NumSubs = NumSubs + 1
        
        A = 1
        Do Until Not Subs(A).Act Or A = 30
            A = A + 1
        Loop
        With Subs(A)
        
        .Act = True
        
        If Int((Rnd * 2) + 1) = 1 Then
            .X = 0 - SubBredde - 2
            .Dire = 2
        Else
            .X = Bredde + 2
            .Dire = 1
        End If
        
        .Y = Int((Rnd * 200) + 130)
        Randomize
        temp = Int((Rnd * 100) + 1)
        Select Case temp
        Case 80 To 100
            .Speed = 3
        Case 50 To 80
            .Speed = 2
        Case Else
            .Speed = 1
        End Select
        
        
        .Score = (.Speed * 2) * (.Y / 10)
        
        End With
    End If
End Sub
Public Sub Movesubs()
    For A = 1 To 30
    With Subs(A)
        If .Act Then
        
        If .Dire = 2 Then M = .Speed
        If .Dire = 1 Then M = -1 * .Speed
        
        If .Damaged <> 0 Then
            .Damaged = .Damaged + 1
            .Y = .Y + 3
            If .Damaged = 10 Then
                .Damaged = 0
                .X = 0
                .Y = 0
                .Dire = 0
                .Act = False
            End If
        Else
        .X = .X + M
        End If
        'N

⌨️ 快捷键说明

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