📄 basegameentity.vb
字号:
Public MustInherit Class BaseGameEntity
'each entity has a unique ID
Dim m_ID As Integer
'every entity has a type associated with it (health, troll, ammo etc)
Dim m_EntityType As GameEntity
'this is a generic flag.
Dim m_bTag As Boolean
Shared NextId As Integer = 0
'its location in the environment
Protected m_vPos As New Vector2D
Protected m_vScale As New Vector2D
'//the length of this object's bounding radius
Protected m_dBoundingRadius As Double
'used by the constructor to give each entity a unique ID
Private Function NextValidID() As Integer
NextId += 1
Return NextId
End Function
Protected Sub New()
m_ID = NextValidID()
m_dBoundingRadius = 0.0
m_vPos = New Vector2D
m_vScale = New Vector2D(1.0, 1.0)
m_EntityType = GameEntity.default_entity_type
m_bTag = False
End Sub
Protected Sub New(ByVal entity_type As GameEntity)
m_ID = NextValidID()
m_dBoundingRadius = 0.0
m_vPos = New Vector2D
m_vScale = New Vector2D(1.0, 1.0)
m_EntityType = entity_type
m_bTag = False
End Sub
Protected Sub New(ByVal entity_type As GameEntity, ByVal pos As Vector2D, ByVal r As Double)
m_ID = NextValidID()
m_dBoundingRadius = r
m_vPos = pos
m_vScale = New Vector2D(1.0, 1.0)
m_EntityType = entity_type
m_bTag = False
End Sub
'//this can be used to create an entity with a 'forced' ID. It can be used
'//when a previously created entity has been removed and deleted from the
'//game for some reason. For example, The Raven map editor uses this ctor
'//in its undo/redo operations.
'//USE WITH CAUTION!
Protected Sub New(ByVal entity_type As GameEntity, ByVal ForcedID As Integer)
m_ID = ForcedID
m_dBoundingRadius = 0.0
m_vPos = New Vector2D
m_vScale = New Vector2D(1.0, 1.0)
m_EntityType = entity_type
m_bTag = False
End Sub
Public Overridable Sub Update(ByVal time_elapsed As Double)
End Sub
Public Overridable Sub Render(ByVal g As Graphics)
End Sub
Public Property Pos() As Vector2D
Get
Return m_vPos
End Get
Set(ByVal Value As Vector2D)
m_vPos = Value
End Set
End Property
Public Property BRadius() As Double
Get
Return m_dBoundingRadius
End Get
Set(ByVal Value As Double)
m_dBoundingRadius = Value
End Set
End Property
Public ReadOnly Property ID() As Integer
Get
Return m_ID
End Get
End Property
Public Function IsTagged() As Boolean
Return m_bTag
End Function
Public Sub Tag()
m_bTag = True
End Sub
Public Sub UnTag()
m_bTag = False
End Sub
Public ReadOnly Property Scale() As Vector2D
Get
Return m_vScale
End Get
End Property
Public Property EntityType() As GameEntity
Get
Return m_EntityType
End Get
Set(ByVal Value As GameEntity)
m_EntityType = Value
End Set
End Property
Public Sub SetScale(ByVal val As Vector2D)
m_dBoundingRadius *= Math.Max(val.x, val.y) / Math.Max(m_vScale.x, m_vScale.y)
m_vScale = val
End Sub
Public Sub SetScale(ByVal val As Double)
m_dBoundingRadius *= val / Math.Max(m_vScale.x, m_vScale.y)
m_vScale = New Vector2D(val, val)
End Sub
End Class
Public Enum GameEntity
default_entity_type = -1
End Enum
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -