Mario Game structure

Started by
3 comments, last by Irlan Robson 8 years, 5 months ago
Hi, i am developing mario game.I have some problems about game structure :
I have a class BaseObject to inhenrit objects . Inside it, i have functions like :
Void Init();
Void Load(Content);
Void Update(Keyboard,GameTime);
Void Draw(Graphic);

COLLI_DIRECT CheckCollision(BaseObject obj);

I controll BaseObject list in class Game .Class Game aslo has 4 functions before (except CheckCollision)

In Game::Update(...) ,I make logic in game ,and check collison, loop BaseObject list call BaseObject::Update(...)

My problem is : I has Mario class extends from BaseObject class , I want to check collision inside Mario::Update() , not inside Game::Update() .But Game keeps object list and i dont want pass more parameters in Mario::Update() because it may break my system.
I have 2 solutions :
_list become static ,and i call anywhere
_create collision event, inside Mario catch this event.
Can anyone solve this problem ??
Thank you for your reading
Advertisement
You need all objects to detect that two objects collide, so the Game is the proper place to detect such things, imho.

Add a "BaseObject::CollidesWith(BaseObject other_object)", and run the collision detection code in the Game for all objects. When it finds a collision, it notifies both objects about it. Eg When Mario collides with tree, you call mario.CollidesWith(tree); and tree.CollidesWith(mario);

What you do inside Mario::CollidesWith() is entirely up to you. It could be as simple as just storing the object it collided with (and then in Mario::Update() act on it), or you could full collision handling right there.


Note that you may want to split moving objects from non-moving objects, and skip collision tests between non-moving objects.
Oh I understood ! Thank you very much ! It is really what I need
This should answer your question directly with details: http://www.gamedev.net/topic/650640-is-using-static-variables-for-input-engine-evil/#entry5113267
This goes into details on architecture that may be helpful: General Game/Engine Structure


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This should hep you with your input system: https://irlans.wordpress.com/2015/11/09/asynchronous-keyboard-input/

This topic is closed to new replies.

Advertisement