modglobal.bas

来自「也是坦克大战」· BAS 代码 · 共 63 行

BAS
63
字号
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 + =
减小字号Ctrl + -
显示快捷键?