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.
-
Answer # 1
-
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
Just likeclass 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_; };
, 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.
Related articles
- c ++ - if you trace two pointers from a member function, you get an error: invalid use of incomplete type
- [c ++] from the textbook: the const member function program causes an error
- c ++ - i get an error saying that the special member function generated by the compiler cannot be defined
- c ++ - i want to know how to create a member function or constructor of template class separately from definition and declarati
- c ++ - about argument of member function
- about call to a member function bindparam () on bool in in php
- c ++ - the pow function does not work well, and a mysterious value is entered in set
- c ++ - dynamic allocation of memory to two member variables of template class does not work
- c ++ - function in structure? i do not understand
- c ++ - matter that blocking function performed in thread does not work
- c ++ - i want to create a function that creates a variable
- is the destructor executed even if it is thrown in a c ++ member function?
- create a graph in c ++ (when the applied function differs depending on the range)
- c ++ - about the node deletion function of the tree structure editing program
- c ++ - is it possible to use a function within a function?
- i want to set the same structure to a member variable in a c ++ structure
- c ++ - i want to solve creategraphicspipelinestate function becomes e_fail
- c ++ - i want to know why the fscanf_s ();function can only set the first character
- between () and {} of c ++ function
- c ++ - about specifying return value type when function overload condition is specified by decltype and sfinae
- resolution of unknown type name'a', which is a c ++ error
- c # - i want to create software that manages products on ec sites with macros
- c ++ - about test case output
- c ++ - forward declaration compilation error for c structs
- about embedding random numbers in c ++ output file names
- c ++ - stack overflow in a dynamic multidimensional array
- c ++ - about getting the number of elements in a two-dimensional array
- c ++ - inside the x and y array
- c ++ - libpng build method
- c ++ - could you please tell me how to resolve the error when using "wiring pih" and "bcm2835h" of raspberry
Questions are
I want to do this
Such
to make it happenBut 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
Sinceis 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.
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.