Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Graphics
Public Class GameObject
Protected _Position As Vector2
Protected _Velocity As Vector2
Protected _Rotation As Single
Protected _Center As Vector2
Protected _Sprite As Texture2D
Protected _Color As Color
Protected _Scale As Single
Protected _Enabled As Boolean = True
Public Overridable Property Position() As Vector2
Get
Return _Position
End Get
Set(ByVal Value As Vector2)
_Position = Value
End Set
End Property
Public Overridable Property Velocity() As Vector2
Get
Return _Velocity
End Get
Set(ByVal Value As Vector2)
_Velocity = Value
End Set
End Property
Public Overridable Property Rotation() As Single
Get
Return _Rotation
End Get
Set(ByVal Value As Single)
_Rotation = Value
End Set
End Property
Public Overridable Property Center() As Vector2
Get
Return _Center
End Get
Set(ByVal Value As Vector2)
_Center = Value
End Set
End Property
Public Overridable Property Sprite() As Texture2D
Get
Return _Sprite
End Get
Set(ByVal value As Texture2D)
_Sprite = value
End Set
End Property
Public Overridable Property Color() As Color
Get
Return _Color
End Get
Set(ByVal value As Color)
_Color = value
End Set
End Property
Public Overridable Property Scale() As Single
Get
Return _Scale
End Get
Set(ByVal value As Single)
_Scale = value
End Set
End Property
Public Overridable Property Enabled() As Boolean
Get
Return _Enabled
End Get
Set(ByVal value As Boolean)
_Enabled = value
End Set
End Property
Public Overridable Sub Draw(ByVal Batch As SpriteBatch)
If Me.Enabled Then
Batch.Draw(Me.Sprite, Me.Position, Nothing, Me.Color, Me.Rotation, Me.Center, Me.Scale, SpriteEffects.None, 0)
End If
End Sub
Public Overridable Sub UpdatePosition()
Me.Position += Me.Velocity
End Sub
Sub New()
Me.Color = Graphics.Color.White
Me.Position = Vector2.Zero
Me.Rotation = 0
Me.Scale = 1.0
Me.Velocity = Vector2.Zero
End Sub
Sub New(ByVal Sprite As Texture2D)
Me.New()
Me.Sprite = Sprite
Me.Center = Me.Position + New Vector2(Me.Sprite.Width * Me.Scale / 2, Me.Sprite.Height * Me.Scale / 2)
End Sub
End Class
Public Class GameText
Inherits GameObject
Private _Font As Drawing.Font
Private _Text As String
Public Property Font() As Drawing.Font
Get
Return _Font
End Get
Set(ByVal value As Drawing.Font)
_Font = value
End Set
End Property
Public Property Text() As String
Get
Return _Text
End Get
Set(ByVal value As String)
_Text = value
End Set
End Property
Sub New()
MyBase.New()
End Sub
Public Sub CreateSprite(ByVal Device As GraphicsDevice)
Dim B As New Drawing.Bitmap(100, 100)
Dim G As Drawing.Graphics = Drawing.Graphics.FromImage(B)
Dim StringSize As Drawing.SizeF = G.MeasureString(Me.Text, Me.Font)
Dim DrawingColor As Drawing.Color = Drawing.Color.FromArgb(Me.Color.A, Me.Color.R, Me.Color.G, Me.Color.B)
Dim Stream As IO.MemoryStream
B = New Drawing.Bitmap(CInt(StringSize.Width), CInt(StringSize.Height))
G = Drawing.Graphics.FromImage(B)
G.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
G.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
G.DrawString(Me.Text, Me.Font, New Drawing.SolidBrush(DrawingColor), 0, 0)
Stream = New IO.MemoryStream
B.Save(Stream, Drawing.Imaging.ImageFormat.Png)
Stream.Position = 0
Me.Sprite = Texture2D.FromFile(Device, Stream)
Stream.Close()
End Sub
End Class
Public Class Block
Inherits GameObject
Private _Life As Int16 = 1
Private _Name As String
Public Property Life() As Int16
Get
Return _Life
End Get
Set(ByVal value As Int16)
_Life = value
End Set
End Property
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Sub New()
MyBase.new()
End Sub
Sub New(ByVal Sprite As Texture2D)
Me.New()
Me.Sprite = Sprite
Me.Center = Me.Position + New Vector2(Me.Sprite.Width * Me.Scale / 2, Me.Sprite.Height * Me.Scale / 2)
End Sub
End Class