Archived

This topic is now archived and is closed to further replies.

joshboudreau

2D Engine Design: Object Manager

Recommended Posts

Hi, all. I''m trying to get a simple 2D engine together to drive a few small game ideas I have and I''m having some doubts on my design (since this is the first time I try this sort of thing). I would like to hear on how some of you manage objects within your game. I''ll post info on the way I''m thinking of doing it and if you see any flaws or a better way of doing it, please let me know. Simple prite structure: struct Sprite { SDL_Surface *texture; int x; int y; int z; int xvel; int yvel; int zvel; int life; bool invulnerable; bool opaque; }; Then i''m planning on having a class like the following: class CObjectManager { public: UpdatePosition(); SendToRenderer(); etc...(); private: list SpriteList; }; I think this would work fine if I updated all objects all the time, but how would I Identify and access an individual object within the game? Would it be better to have different object types for static things that don''t move? If you have any ressources that speak on this subject please let me know. -- Josh Boudreau This isn''''t an office. It''''s Hell with fluorescent lighting.

Share this post


Link to post
Share on other sites
if you use arrays you have to limit the units count for example

id say you create a linked list and each object in the list stores around 20 units

terrain should always be an array because arrays are easy to access and vising is easy as well

Share this post


Link to post
Share on other sites
hehe, I didn''t get one word of that code you posted, so that''s what C++ looks like =D
I guess I need to learn that before going to D3D...

[sorry, totally useless reply]
The way I do it, is with functions, the old C style. I have an array of structs for all my sprites, and the function that translates and processes them, loops through the array, and just skips if my bool alive variable is FALSE.
Dunno if that helps.

It''''s nice to be important, but it''''s more important to be nice.

Share this post


Link to post
Share on other sites
Why do you have Z fields for a 2D engine? 2D uses 2 dimensions; X and Y.

Strange.

You also might want to include the size (unless the size is embedded in the SDL_Surface structure).

Share this post


Link to post
Share on other sites

"Why do you have Z fields for a 2D engine? 2D uses 2 dimensions; X and Y."

I'm using the Z for depth ordering... some sprites might be in front of others etc... they get sorted before sent for drawing.

Thank you guys for the input.

--
Josh Boudreau
This isn''t an office. It''s Hell with fluorescent lighting.

[edited by - joshboudreau on October 21, 2002 4:09:05 PM]

Share this post


Link to post
Share on other sites