Home>

I will briefly explain the current stage.

The bullet class has the following member variables. Move commands are entered using member functions.
-Bullet number
Boolean of whether used
・ Location information
・ From which object is fired

I will write what I don't understand. (I'm sorry for being hard to understand.)
-The bullet number was put in a state where it was not understood, such as "Is it necessary for the number of elements in the object array?"
・ I want to create a number of bullet objects when I press a key in Player :: Control, which is a member function of the player, but my head gets stuck in traffic.

What should I do first? Sorry for the rude question.

c c++
  • Answer # 1

    Questions are

    I want to do this

    Such

    to make it happen

    But this happened (as opposed to what I want to do)

    It is good to summarize it in the form of

    .

    If you apply the question in this case

    I want to fire a bullet from a player member function

    I put these elements as members of bullets

    Traffic jam in your head

    Since

    is applicable, it can be said that the basic appearance is taken, but the problem here is that `` firing bullets '' is too vague as what you want to do .

    I have only done what I did as a situational explanation, and I'm not sure what I'm doing for.

      

    What should I do first?

    For

    , the simple answer is "Decide what you want to do".

    Determine the shape that should be final, such as whether the bullet should just fly, whether it is a damage assessment if it hits something, or who needs to know who hit it. It should be organized in the form of "What is necessary for that?"

    I don't want to evaluate whether individual features are needed and how they should be configured when the purpose is not fixed.

  • Answer # 2

    Let's decide how to manage the existing bullets.
    If you wrote a class that represents a single bullet, where and how do you keep and use the set of instances of that class? The story.

    For example,

    There is a module called "Administrator who manages the set of existing bullets", and this unit moves the coordinates of all the bullets that exist, and discards bullets that have gone off the screen.

    If you decide

    ,
    If a new bullet is created (within Player :: Control), this bullet management module will be
    It may be enough to say, "This is a new bullet that has just been launched.

  • Answer # 3

    First of all, please summarize as shown below.

    Reference 1: How to solve programming problems and logic

    Like y_waiwai in the "Request for correction" column, please consider "How do you consider it to have been fired?"

    And what to do with the "when you hit it" (for example, refill it with a bullet or complete destruction?
    (Even if it needs to be managed)

    For example, if you get used to the moment you fire, you don't need to manage it.

    Even if there is a charge, just charge for something like "Gun Class".

    For example

    class Pistol {
          public:
                     Pistol (int n = 0): n_ (n) {} // Specify the number of bullets in the constructor
                     bool bang (void) {
                          if (n_<= 0) return false;// false because no bullets remain
                          n _--;// Make the bullet negative
                     return true;
                     }
          private:
                     int n_;
    };
    Just like

    , you can manage the number of bullets in the pistol class.

    Maybe it's homing? If it's a comic or something like a "chase until it hits the enemy", you might want to make it an object.

    That way, it varies considerably depending on conditions.

    In the question, it's too sketchy, and even "what you need" and "what you want to do" are unknown.

    Firstorganize your information.

    At first, it is better to clarify "what you want to make in the first place" and "what class exists" and "what processing each one is responsible for".

    No one else can understand.

    Try your best first.