I'm working on an assignment for school (I'm remaking the Intro Stage from Mega Man X).
The thing is... I've got a class "Bullet" and a class" Wheel". These aren't 'connected' but I need to get the two connected somehow so I can check if they hit each other (using a Hitregion).
I thought of one solution and that is make the object "Wheel" I made in my Main class public (if that's possible) but I can't seem to figure out how.
Can someone please push me in the right direction?
These classes don't need to know anything about each other.
Rather, there should be a manager class that manages all objects or all objects that have a hitbox. Then you can ask the manager about any collisions, which in turn asks each object whether it collides with the object in question.
Yeah. That's sort of my main class. But the Bullet object gets called in the class which has the information for the player and its movement.
It isn't possible to start this object in the Main class I think because I need the states of the Player (walking, waiting, jumping,...)
Will try your method but I don't think it'll work.
Yes. The bullets are created in the Player class.
So... eveything should go back to the class I call Main and be processed there? And the info from the bullets should go through the Player class?
So... eveything should go back to the class I call Main and be processed there?
Not sure what you mean, but probably not. The player class creates new bullet objects. Upon creation, the bullets register themselves with the object manager, so they can be drawn and given processing time in your main loop.
It's not something you're taught, it's just a matter of how you design your program so you get the desired results in the easiest way possible. At least for a game like you're describing, this concept works reasonably well.
Basically you have an abstract class called e.g. Object or DrawableObject, which should have at least two abstract functions: draw() and tick(). The first draws the object on a surface/canvas passed to the function, the second one is called every tick to give the object a chance to do something (a bullet has to move and check if it has hit something, for example).
To keep track of all existing objects, there can be a global or per-world container (an instance of the object manager class), where objects register and unregister themselves when they are created and destroyed. The container itself can be a std::list, for example. (Un)registering is simply the process of adding and removing references (raw pointers or smart pointers) from the container.
Your main loop can make use of the managers to draw and tick() all objects in one go.