Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 4. Asteroid Belt Assault Lost in... > Time for action - adding the ShotMan...

Time for action - adding the ShotManager class

  1. Add a new class called ShotManager to the Asteroid Belt Assault project.

  2. Add declarations to the ShotManager class:

    Public Shots As List(Of Sprite) = New List(Of Sprite)()
    Private Shared _screenBounds As Rectangle
    Private Shared _texture As Texture2D
    Private Shared _initialFrame As Rectangle
    Private Shared _frameCount As Integer
    Private Shared _collisionRadius As Integer
    Private _shotSpeed As Single
    
  3. Add a constructor to the the ShotManager class:

    Public Sub New (
    texture As Texture2D,
    initialFrame As Rectangle,
    frameCount As Integer,
    collisionRadius As Integer,
    shotSpeed As Single,
    screenBounds As Rectangle)
    _Texture = texture
    _InitialFrame = initialFrame
    _FrameCount = frameCount
    _CollisionRadius = collisionRadius
    _shotSpeed = shotSpeed
    _screenBounds = screenBounds
    End Sub
    

What just happened?

ShotManager maintains a list of fired shots. An enemy-fired shot will not hurt enemies, and a player-fired shot will not hurt the player, if they somehow manage to move into one. We will implement these properties, when we build the CollisionManager class, which will check for collisions between fired shots and other game objects by creating two different instances of the ShotManager class.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint