Thread: How to make player fire rockets?

  1. #1
    Registered User
    Join Date
    Oct 2006

    How to make player fire rockets?

    EDIT: Please ignore my stupid question. I asked because I was struggling with a bug which made this seams more complicated then what it really is. Feel Free to delete the post.

    Im trying to make a simple game, but im having some problems.

    Im my game I have a player class which covers move, draw, kill, life and so on. It also has a fireRocket() function, but im not sure how to really make the player able to shoot. Right now im trying fireRocket() create a new object (class Missile) but the whole thing does not really work and is very very messy.

    What would be a good design/ solution to this?

    Sorry if this is badly formulated/stupid question.
    Last edited by h3ro; 01-15-2008 at 06:45 PM.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    You have the right idea except you may want to allow the rocket class to be created by a class that manages objects. Then you would do something like addRocket() inside of PlayerFire().

    In my asteroids game I add lasers to a laser manager class which then handles the object from that point on.

    My solution is something along these lines:

    void Player::Fire()
       X3DGetApp()->GetLaserMgr()->Add(new Laser(....));
    X3DGetApp() returns the application object which then has public accessor functions that allow access to it's various manager classes.

    You could also go with a factory approach in that you have a rocket factory which in turn produces rocket objects. So you would get an instance of the factory and then call create() which would then create the rocket.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Keeping track of the player in a 2d numbered grid.
    By Shamino in forum C++ Programming
    Replies: 1
    Last Post: 03-25-2009, 05:39 PM
  2. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM
  3. Trying To Implement A 'Player' Class
    By adc85 in forum C++ Programming
    Replies: 2
    Last Post: 04-02-2003, 03:51 PM
  4. forest fire
    By Kohatian 3279 in forum C++ Programming
    Replies: 0
    Last Post: 04-18-2002, 01:52 PM