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

📄 form1.frm

📁 VB6+DX7开发即时战略游戏(游戏代码+编辑器)
💻 FRM
📖 第 1 页 / 共 5 页
字号:

End Sub


Sub PaintBackground()
Dim destRect As RECT
Dim srcRect As RECT

Dim a As Integer
Dim b As Integer

srcRect.Right = ddsdBlack.lWidth        'cls以便于观察
srcRect.Bottom = ddsdBlack.lHeight      'cls不是必须的,但加上会有好处
destRect.Right = DisplayWidth + BackgroundTile_Width * 2 - 1
destRect.Bottom = DisplayHeight + BackgroundTile_Height * 2 - 1

Call BackbufferSurface.Blt(destRect, Black, srcRect, DDBLT_WAIT)

Dim i As Integer
Dim j As Integer

a = Int(Ma_Date.CurPosX / BackgroundTile_Width)
b = Int(-Ma_Date.CurPosY / BackgroundTile_Height)

For i = a - 4 To a + 4
    For j = b - 3 To b + 3
        DoEvents        '脱离当前镜头的tile不予运算,对于提升速度很有效
        'If Abs(Tile_Date(i, j).X - Ma_Date.CurPosX) <= (DisplayWidth / 2 + BackgroundTileSize / 2) And Abs(Tile_Date(i, j).Y - Ma_Date.CurPosY) <= (DisplayHeight / 2 + BackgroundTileSize / 2) Then
            With srcRect
                .Left = 0
                .Right = BackgroundTile_Width - 1
                .Top = 0
                .Bottom = BackgroundTile_Height - 1
            End With
            
            With destRect
        
                .Left = Tile_Date(i, j).X - Ma_Date.CurPosX + DisplayWidth / 2 + BackgroundTile_Width - BackgroundTile_Width / 2
                
        
                .Right = Tile_Date(i, j).X - Ma_Date.CurPosX + DisplayWidth / 2 + BackgroundTile_Width + BackgroundTile_Width / 2
                
                
                .Top = -(Tile_Date(i, j).Y - Ma_Date.CurPosY) + DisplayHeight / 2 + BackgroundTile_Height - BackgroundTile_Height / 2
                
                
                .Bottom = -(Tile_Date(i, j).Y - Ma_Date.CurPosY) + DisplayHeight / 2 + BackgroundTile_Height + BackgroundTile_Height / 2
                
        
            End With
            
            Select Case Tile_Date(i, j).GraphyIndex
            
            Case Red_Index
            Call BackbufferSurface.Blt(destRect, Red, srcRect, DDBLT_WAIT)
            
            Case Green_Index
            Call BackbufferSurface.Blt(destRect, Green, srcRect, DDBLT_WAIT)
            
            Case Blue_Index
            Call BackbufferSurface.Blt(destRect, Blue, srcRect, DDBLT_WAIT)
            
            End Select
        
        'End If
        
    Next j
    
Next i

End Sub

Sub Blt()
PaintBackground
PaintMaZiDan
PaintEnemyZidan
PaintMa
PaintEnemy1
PaintHit
PaintDestroy
PaintRadar
PaintText
PaintToScreen
End Sub

Sub Hit_Test()       '符合命中条件
Dim i As Integer
Dim j As Integer
Dim X As Integer

For j = 0 To 1     '计算每一颗子弹
    For X = 0 To 49  '敌机
        DoEvents
        With Ma_ZiDan_Date(j)
            If Enemy1_Date(X).Hp > 0 Then   '如果敌机生存
                '如果敌机被命中,HP-
                If Abs(.CurPosX - Enemy1_Date(X).CurPosX) <= Enemy1_Date(X).R And Abs(.CurPosY - Enemy1_Date(X).CurPosY) <= Enemy1_Date(X).R And .Shotting = True Then
                    .Shotting = False
                    Enemy1_Date(X).Hp = Enemy1_Date(X).Hp - 1
                    For i = 0 To 9      '启动hit动态图象
                            If Hit_Date(i).Hitted = False Then
                                Hit_Date(i).Hitted = True
                                Hit_Date(i).State = -1
                                Hit_Date(i).CurPosX = .CurPosX
                                Hit_Date(i).CurPosY = .CurPosY
                                       
                                'PlayHitWav 这里并不很需要播放声音
                                
                                Exit For
                            
                            End If
                    Next i
                    
                    If Enemy1_Date(X).Hp <= 0 Then   '如果敌机被命中后,hp减到0
                        Enemy1_Date(X).Hp = 0
                        For i = 0 To 9      '启动destroy动态图象
                            If Destroy_Date(i).Hitted = False Then
                                Destroy_Date(i).Hitted = True
                                Destroy_Date(i).State = -1
                                Destroy_Date(i).CurPosX = Enemy1_Date(X).CurPosX
                                Destroy_Date(i).CurPosY = Enemy1_Date(X).CurPosY
                                       
                                'PlayHitWav  '播放空中爆炸的声音
                                
                                Exit For
                            
                            End If
                        Next i
                    End If
                    
                End If
            
            End If
                        
        End With
        
    Next X

Next j

For j = 0 To 5     '计算敌机的每一颗子弹
        DoEvents
        With Enemy_ZiDan_Date(j)
            If Ma_Date.Hp > 0 Then  '如果我机生存
                '如果座机被命中
                If Abs(.CurPosX - Ma_Date.CurPosX) <= Ma_Date.R And Abs(.CurPosY - Ma_Date.CurPosY) <= Ma_Date.R And .Shotting = True Then
                    .Shotting = False
                    Ma_Date.Hp = Ma_Date.Hp - 1
                    For i = 0 To 9      '启动hit动态图象
                            If Hit_Date(i).Hitted = False Then
                                Hit_Date(i).Hitted = True
                                Hit_Date(i).State = -1
                                Hit_Date(i).CurPosX = .CurPosX
                                Hit_Date(i).CurPosY = .CurPosY
                                
                                'PlayHitWav   这里倒是有必要放点声音出来
                                
                                Exit For
                            
                            End If
                            
                    Next i
                    
                    If Ma_Date.Hp <= 0 Then      '如果被命中后hp减到0
                        Ma_Date.Hp = 0
                        'Ma_Date.CurSpeed = 0  '被击毁后屏幕定格,不再滚动
                        For i = 0 To 9          '启动destroy动态图象
                            If Destroy_Date(i).Hitted = False Then
                                Destroy_Date(i).Hitted = True
                                Destroy_Date(i).State = -1
                                Destroy_Date(i).CurPosX = Ma_Date.CurPosX
                                Destroy_Date(i).CurPosY = Ma_Date.CurPosY
                                
                                'PlayHitWav  '播放空中爆炸的声音
                                
                                Exit For
                            
                            End If
                            
                        Next i
                    End If
                End If
            End If
        End With
            
Next j

End Sub

Sub PaintToScreen()     '刷新屏幕
Dim destRect As RECT
Dim srcRect As RECT

Call D7.GetWindowRect(MainForm.hWnd, destRect)
With srcRect
    .Left = BackgroundTile_Width
    .Right = BackgroundTile_Width + DisplayWidth
    .Top = BackgroundTile_Height
    .Bottom = BackgroundTile_Height + DisplayHeight
End With

Call PrimarySurface.Blt(destRect, BackbufferSurface, srcRect, DDBLT_WAIT)

End Sub

Sub PaintMa()
Dim destRect As RECT
Dim srcRect As RECT
Dim i As Integer
i = 0

If Ma_Date.Hp > 0 Then
       
    With destRect       '座机总是在屏幕的中央
        .Left = DisplayWidth / 2 + BackgroundTile_Width - SpriteTileSize / 2
        .Right = DisplayWidth / 2 + BackgroundTile_Width + SpriteTileSize / 2
        .Top = DisplayHeight / 2 + BackgroundTile_Height - SpriteTileSize / 2
        .Bottom = DisplayHeight / 2 + BackgroundTile_Height + SpriteTileSize / 2
    End With
    
    With srcRect         '根据角度计算该调用哪个图形
        .Top = 0
        .Bottom = SpriteTileSize - 1
        
        If Ma_Date.FangXiang >= 270 And Ma_Date.FangXiang < 281.25 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
    
        If Ma_Date.FangXiang >= 281.25 And Ma_Date.FangXiang < 303.75 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
    
        i = i + 1
    
        If Ma_Date.FangXiang >= 303.75 And Ma_Date.FangXiang < 326.25 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
        
        If Ma_Date.FangXiang >= 326.25 And Ma_Date.FangXiang < 348.75 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
        
        If Ma_Date.FangXiang >= 348.75 And Ma_Date.FangXiang < 360 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
                
        If Ma_Date.FangXiang >= 0 And Ma_Date.FangXiang < 11.25 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
        
        If Ma_Date.FangXiang >= 11.25 And Ma_Date.FangXiang < 33.75 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
        
        If Ma_Date.FangXiang >= 33.75 And Ma_Date.FangXiang < 56.25 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
        
        If Ma_Date.FangXiang >= 56.25 And Ma_Date.FangXiang < 78.75 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
        
        If Ma_Date.FangXiang >= 78.75 And Ma_Date.FangXiang < 101.25 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
        
        If Ma_Date.FangXiang >= 101.25 And Ma_Date.FangXiang < 123.75 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
        
        If Ma_Date.FangXiang >= 123.75 And Ma_Date.FangXiang < 146.25 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
        
        If Ma_Date.FangXiang >= 146.25 And Ma_Date.FangXiang < 168.75 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
        
        If Ma_Date.FangXiang >= 168.75 And Ma_Date.FangXiang < 191.25 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
        
        If Ma_Date.FangXiang >= 191.25 And Ma_Date.FangXiang < 213.75 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
        
        If Ma_Date.FangXiang >= 213.75 And Ma_Date.FangXiang < 236.25 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = i + 1
        
        If Ma_Date.FangXiang >= 236.25 And Ma_Date.FangXiang < 258.75 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
        
        i = 0
        
        If Ma_Date.FangXiang >= 258.75 And Ma_Date.FangXiang < 270 Then
            .Left = SpriteTileSize * i
            .Right = SpriteTileSize * (i + 1)
        End If
                
    End With

    Call BackbufferSurface.Blt(destRect, Ma, srcRect, DDBLT_WAIT Or DDBLT_KEYSRC)
    
    
    With srcRect

⌨️ 快捷键说明

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