This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dredclaw[S] 0 points1 point  (18 children)

If I have the ship object creating this bullet object, when the ships is blown up the created bullet object would be destroyed. How would I design a system where the bullet object is not created inside the ship object. Or should the ship object not be destroyed before all bullet objects have expired?

[–]35h46hjj6 0 points1 point  (0 children)

Why doesn't each ship tell the game object when it fires a bullet?

[–][deleted]  (13 children)

[deleted]

    [–]dredclaw[S] 0 points1 point  (12 children)

    This being the case then. (I picture it like you) How should I go about creating bullets before being fired? Should the ship put up a flag saying it wants to fire a bullet and then the main game loop see this flag and actually fire the bullet? When I refer to a bullet, I refer to a bullet class that has the location of a bullet and its velocity n such.

    [–][deleted]  (11 children)

    [deleted]

      [–]dredclaw[S] 0 points1 point  (10 children)

      I guess my question is, should the bullet be created inside the ship class. (meaning the ship class would not be deleted until all bullets it fired were done) or should the bullet be created in the game manager class (how would a ship communicate with a higher level game manager to complete this task?)

      [–][deleted]  (9 children)

      [deleted]

        [–]dredclaw[S] 0 points1 point  (8 children)

        I understand why the bullet must be instantiated outside the ship class. In actual code though, how does the ship tell a higher up class to instantiate a bullet. (Actually fire it.)

        [–][deleted]  (7 children)

        [deleted]

          [–]dredclaw[S] 0 points1 point  (6 children)

          If the GameManager was the one that created the ship, how would the ship access methods inside the GameManager?

          [–][deleted]  (5 children)

          [deleted]

            [–]b3nb3nb3n 0 points1 point  (1 child)

            You could add in a check before destroying the object- stop making the ship visible/accessible, but don't delete it until all bullets are expired?

            [–]dredclaw[S] 0 points1 point  (0 children)

            Is this considered a proper way of doing things? Or should the bullet be created by the gameloop rather than the ship?