2D Engine Design: Object Manager

Started by
4 comments, last by joshboudreau 21 years, 6 months ago
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.
-- Josh BoudreauThis isn''t an office. It''s Hell with fluorescent lighting.
Advertisement
Use arrays of your class and then roll through each array item using a for loop.

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
http://www.8ung.at/basiror/theironcross.html
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.
Don't we all still remember and miss the day we plotted our first pixel?
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).

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)


"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]
-- Josh BoudreauThis isn''t an office. It''s Hell with fluorescent lighting.

This topic is closed to new replies.

Advertisement