Option Explicit On
Option Strict On
Public Class Car
Public Enum direction As Integer
Right
Left
End Enum
Private pDirection As direction = direction.Right
Private iX As Integer = 20
Private iY As Integer = 20
Private iSpeed As Integer = 40
Private iWidth As Integer = 100
Private iHeight As Integer = 100
Private cColour As Color = Color.Orange
Public Sub New()
End Sub
Public Sub drawcar(ByVal R As Graphics)
Dim bodyBrush As New SolidBrush(cColour)
Dim wheelBrush As New SolidBrush(Color.Black)
Dim windowBrush As New SolidBrush(Color.White)
Dim horizontal As Integer
Dim vertical As Integer
horizontal = iWidth \ 8
vertical = iHeight \ 5
R.FillRectangle(bodyBrush, iX, iY + 2 * vertical, horizontal * 8, vertical * 2)
R.FillEllipse(wheelBrush, iX + 1 * horizontal, iY + 3 * vertical, horizontal * 2, vertical * 2)
R.FillEllipse(wheelBrush, iX + 5 * horizontal, iY + 3 * vertical, horizontal * 2, vertical * 2)
Select Case pdirection
Case direction.Right
R.FillRectangle(bodyBrush, iX + 1 * horizontal, iY, horizontal * 5, vertical * 2)
R.FillRectangle(windowBrush, iX + 3 * horizontal, iY + 1 * vertical, horizontal * 2, vertical * 1)
Case direction.Left
R.FillRectangle(bodyBrush, iX + 2 * horizontal, iY, horizontal * 5, vertical * 2)
R.FillRectangle(windowBrush, iX + 3 * horizontal, iY + 1 * vertical, horizontal * 2, vertical * 1)
End Select
End Sub
Public Sub MoveCar(ByVal R As Graphics)
ClearCar(R)
If pDirection = direction.Right Then
iX += iSpeed
Else
iX -= iSpeed
End If
drawcar(R)
End Sub
#Region "Propertires"
Public Property X() As Integer
Get
Return iX
End Get
Set(ByVal value As Integer)
iX = value
End Set
End Property
Public Property Y() As Integer
Get
Return iY
End Get
Set(ByVal value As Integer)
iY = value
End Set
End Property
Public Property Width() As Integer
Get
Return iwidth
End Get
Set(ByVal value As Integer)
iwidth = value
End Set
End Property
Public Property Height() As Integer
Get
Return iheight
End Get
Set(ByVal value As Integer)
iheight = value
End Set
End Property
Public Property Colour() As Color
Get
Return cColour
End Get
Set(ByVal value As Color)
cColour = value
End Set
End Property
Public Property Speed() As Integer
Get
Return ispeed
End Get
Set(ByVal value As Integer)
ispeed = value
End Set
End Property
Public Property Directions() As direction
Get
Return pdirection
End Get
Set(ByVal value As direction)
pdirection = value
End Set
End Property
#End Region
Public Sub ClearCar(ByVal R As Graphics)
Dim clearBrush As New SolidBrush(Color.White)
Dim horizontal As Integer
Dim vertical As Integer
horizontal = iWidth \ 8
vertical = iHeight \ 5
R.FillRectangle(clearBrush, iX, iY + 2 * vertical, horizontal * 8, vertical * 2)
R.FillEllipse(clearBrush, iX + 1 * horizontal, iY + 3 * vertical, horizontal * 2, vertical * 2)
R.FillEllipse(clearBrush, iX + 5 * horizontal, iY + 3 * vertical, horizontal * 2, vertical * 2)
Select Case pDirection
Case direction.Right
R.FillRectangle(clearBrush, iX + 1 * horizontal, iY, horizontal * 5, vertical * 2)
Case direction.Left
R.FillRectangle(clearBrush, iX + 2 * horizontal, iY, horizontal * 5, vertical * 2)
End Select
End Sub
Public Sub New(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal colour As Color, ByVal speed As Integer)
iX = x
iY = y
iSpeed = speed
iHeight = height
iWidth = width
cColour = colour
End Sub
End Class
AND FOR SPIKE
Public Class Spike
'attributes
Private ix As Integer = 0
Private iy As Integer = 0
Private iSize As Integer = 20
Private cBody As Color = Color.Red
Private cFeatures As Color = Color.Black
#Region "Properties"
'properties
Public Property x() As Integer
Get
Return ix
End Get
Set(ByVal Value As Integer)
ix = Value
End Set
End Property
Public Property y() As Integer
Get
Return iy
End Get
Set(ByVal Value As Integer)
iy = Value
End Set
End Property
Public Property size() As Integer
Get
Return iSize
End Get
Set(ByVal Value As Integer)
iSize = Value
End Set
End Property
Public Property body() As Color
Get
Return cBody
End Get
Set(ByVal Value As Color)
cBody = Value
End Set
End Property
Public Property features() As Color
Get
Return cFeatures
End Get
Set(ByVal Value As Color)
cFeatures = Value
End Set
End Property
Public ReadOnly Property width() As Integer
Get
Return iSize * 1.5
End Get
End Property
#End Region
'constructor methods
Public Sub New()
End Sub
Public Sub New(ByVal x As Integer, _
ByVal y As Integer, _
ByVal size As Integer, _
ByVal body As Color, _
ByVal features As Color)
ix = x
iy = y
iSize = size
cBody = body
cFeatures = features
End Sub
'other methods
'draw spike
Public Sub Draw(ByVal spikeArea As Graphics)
Dim bodyPen As Pen
Dim bodyBrush As SolidBrush
Dim featuresBrush As SolidBrush
Dim iHalfsize As Integer = iSize \ 2
Dim iWidth As Integer = iSize * 1.5
Dim iArm As Integer = iSize \ 4
Dim iFeature As Integer = iSize \ 5
Dim iMouthX As Integer = iArm + iFeature * 1.5
Dim iMouthY As Integer = iFeature * 3.25
Dim iLeg As Integer = iSize \ 10
bodyPen = New Pen(cBody, iLeg)
bodyBrush = New SolidBrush(cBody)
featuresBrush = New SolidBrush(cFeatures)
spikeArea.FillEllipse(bodyBrush, ix + iArm, iy, iSize, iSize)
spikeArea.DrawLine(bodyPen, ix, iy, ix + iWidth, iy + iSize)
spikeArea.DrawLine(bodyPen, ix, iy + iHalfsize, ix + iWidth, iy + iHalfsize)
spikeArea.DrawLine(bodyPen, ix, iy + iSize, ix + iWidth, iy)
spikeArea.FillEllipse(featuresBrush, ix + iArm + iFeature, iy + iArm, iFeature, iFeature)
spikeArea.FillEllipse(featuresBrush, ix + iArm + iFeature * 3, iy + iArm, iFeature, iFeature)
spikeArea.FillRectangle(featuresBrush, ix + iMouthX, iy + iMouthY, iFeature * 2, iFeature \ 2)
End Sub
'clear spike
Public Sub Clear(ByVal spikeArea As Graphics)
Dim clearPen As Pen
Dim clearBrush As SolidBrush
Dim iHalfsize As Integer = iSize \ 2
Dim iWidth As Integer = iSize * 1.5
Dim iArm As Integer = iSize \ 4
Dim iLeg As Integer = iSize \ 10
clearPen = New Pen(Color.White, iLeg)
clearBrush = New SolidBrush(Color.White)
spikeArea.FillEllipse(clearBrush, ix + iArm, iy, iSize, iSize)
spikeArea.DrawLine(clearPen, ix, iy, ix + iWidth, iy + iSize)
spikeArea.DrawLine(clearPen, ix, iy + iHalfsize, ix + iWidth, iy + iHalfsize)
spikeArea.DrawLine(clearPen, ix, iy + iSize, ix + iWidth, iy)
End Sub
End Class
As far as I'm aware, all the code for car.vb and spike is correct.