Maze+-+Bullet+Class


 * This is a sample class for a bullet OBJECT from my formative maze game. This is the recipe (class) for the cookie (bullet). This tells the computer how to create the bullet (its speed, size, image, timer, what to do if it hits the walls, etc....).**

Public Class Bullet Public pbxBullet As New PictureBox Dim tmrBTimer As New Timer Dim intSpeed As Integer Dim intXMove As Integer Dim intYMove As Integer

Public Sub New(ByVal s As Integer) Try pbxBullet.Image = Image.FromFile("bullet2.jpg") pbxBullet.SizeMode = PictureBoxSizeMode.StretchImage pbxBullet.Height = 20 pbxBullet.Width = 20 intSpeed = s Catch ex As Exception MsgBox("CANNOT FIND IMAGE!!! " & ex.Message) End Try

tmrBTimer.Interval = 100 - s tmrBTimer.Start AddHandler tmrBTimer.Tick, AddressOf timeBullet End Sub

Public Sub timeBullet intXMove = 5 pbxBullet.Location = New Point(pbxBullet.Location.X - intXMove, pbxBullet.Location.Y + intYMove) If pbxBullet.Location.X > frmLevel3.Width Then tmrBTimer.Stop pbxBullet.Dispose pbxBullet = Nothing ElseIf pbxBullet.Bounds.IntersectsWith(frmLevel3.pbxElmo2.Bounds) Then tmrBTimer.Stop pbxBullet.Location = New Point(-2000, 0) pbxBullet.Dispose pbxBullet = Nothing frmLevel3.Close

End If End Sub End Class