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

📄 modglobal.bas

📁 也是坦克大战
💻 BAS
字号:
Attribute VB_Name = "Module1"
Option Explicit

Public Enum SpriteDirectionConstants
    dirUp = 1
    dirRight = 2
    dirDown = 3
    dirLeft = 4
End Enum

Public Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long



Public Function AssignRect(l As Long, t As Long, r As Long, b As Long) As RECT
    Dim rc As RECT
    
    With rc
        .Left = l
        .Top = t
        .Right = r
        .Bottom = b
    End With
    
    AssignRect = rc
End Function

Public Function SpriteCollision(spr1 As cSprite, spr2 As cSprite) As Boolean
    Dim rc1 As RECT, rc2 As RECT
    
    With spr1
        rc1 = AssignRect(.x - (.SpriteWidth / 2), .Y - (.SpriteHeight / 2), _
        .x + (.SpriteWidth / 2), .Y + (.SpriteHeight / 2))
    End With
    With spr2
        rc2 = AssignRect(.x - (.SpriteWidth / 2), .Y - (.SpriteHeight / 2), _
        .x + (.SpriteWidth / 2), .Y + (.SpriteHeight / 2))
    End With
    
    If (rc1.Left >= rc2.Left And rc1.Left <= rc2.Right) Or _
       (rc1.Right >= rc2.Left And rc1.Right <= rc2.Right) Then
       
        If (rc1.Top >= rc2.Top And rc1.Top <= rc2.Bottom) Or _
           (rc1.Bottom >= rc2.Top And rc1.Bottom <= rc2.Bottom) Then
            SpriteCollision = True
        End If
        
    End If
End Function


Public Function RectCollision(rc1 As RECT, rc2 As RECT) As Boolean
    If (rc1.Left >= rc2.Left And rc1.Left <= rc2.Right) Or _
       (rc1.Right >= rc2.Left And rc1.Right <= rc2.Right) Then
       
        If (rc1.Top >= rc2.Top And rc1.Top <= rc2.Bottom) Or _
           (rc1.Bottom >= rc2.Top And rc1.Bottom <= rc2.Bottom) Then
            RectCollision = True
        End If
        
    End If
End Function

⌨️ 快捷键说明

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