Interaction between objects

Started by
2 comments, last by Drastick 20 years, 11 months ago
I'm feeling a little lost, I have my player who needs to shoot then see if the shot has hit a monster then update the moster to tell it to take damage, then the moster needs to do the same to the player. Is there a way use two or more classes to work together on the same level. [edited by - Drastick on April 27, 2003 11:38:55 PM]
Advertisement
I''m not sure how you are storing your objects, but this is how I do it in my engine.

I have a base class called a spriteInfo class. Well, these are all stored in linked lists in my spriteHandler class. Now, when I''m creating a game, I also create arrays of pointers to my spriteInfos. So I might have:

spriteInfo* mainCharacter;
spriteInfo* playerBullets[128];
spriteInfo* enemies[128];
spriteInfo* enemyBullets[256];

Sure there are some management issues at hand when it comes to creation and destruction of bullets, but I''m sure you can figure that out.

But anyway, I have collision functoins that take in spriteInfo*, and return bools on whether they are colliding or not. So all you do is take two arrays, such as the main character and enemy bullets, and do collision detection on all of them. If you get a collision, then do what you need, such as destroy the bullet and lower the player''s health. Same ith player bullets and enemies (although here you''ll have a many vs. many relationship).



--Vic--

The future of 2D game development:
Flat Red Ball
I really like your setup for your program, it sounds like it works really well. I also have an object manager and a generic object class for my program, but I hadn''t even considered writing a function that would return a bool on a collision. I think I''ll probably implement it too.
Peon
I have a nice collection of collision detection functions if you anyone is interested. They also handle movement (if two objects are colliding, move the secondary sprite - like a player - to the outside of the primary sprite - like a wall). They function with my spriteInfo class, but even if you are using your own sprite class, they are easy to understand. I can also offer help online through AIM, if anyone is interested. You can download the engine at the bottom of this post on the link and look at collisionFunctions.cpp and .h, or send me an Instant Message on AIM: ArmySarj.



--Vic--

The future of 2D game development:
Flat Red Ball

[edited by - Roof Top Pew Wee on April 28, 2003 11:17:01 AM]

This topic is closed to new replies.

Advertisement