🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Need advice with linked lists...

Started by
3 comments, last by habus 24 years, 8 months ago
Hmm not quite sure what your trying to do there. Why not just store the image with the object? Not quite sure what you are asking.
Personaly i just use a linked list for my objects and the objects have the images with them.
something Like this.

typedef struct Monster_{
int type;
directdraw suface buffer;
struct Monster_* next;
struct Monster_* prev;
} Monster;

Advertisement
If you are building all the lists a initialization time, I would use a structure that had pointers to your images and put them on a multi-directional linked list. That way you can cycle through the images for animation purposes.

typedef node {

nodePtr *left;
nodePtr *right;
image *imagePtr;

} nodePtr;

Of course, this is C syntax, and if you are using c++ or another language, then you would have to alter things accordingly.

I like using linked list for animation, but tend to be careful that I am not doing any allocation at runtime. It can really cause some problems. Using pointers will help you out. Especially if you are doing a shooter and want to cat animations onto other animaitons, etc. You can extend your animations or limit them depending on how deep you sycle the list and what other lists you insert or attach to the parent list.

Skott

The way I've always done it was to have a list of entities *seperate* from their images, i.e.:

struct Monster {
pointer to direct draw surface
int curframe;
int hitpoints;
int attackstrength;
int movementspeed;
// whatever
}

By using a pointer to a surface instead of an actual surface, you gain 2 things:

1) Multiple instances of Monster can share the same direct draw surface, saving gfx card memory;

2) it's easy to have monsters with the same stats, but different appearances. This is the classic "red blob/green blob/blue blob" technique used by lots of old NES games (FF springs to mind).

Keep in mind that even though your images are outside the struct, each struct needs to know what frame of animation it's on... otherwise, all of your monsters will all have to be on the same frame at the same time, which doesn't look realistic.

Mason McCuskey
Spin Studios
www.spin-studios.com

Founder, Cuttlefish Industries
The Cuttlefish Engine lets anyone develop great games for iPad, iPhone, Android, WP7, the web, and more!
Hi!

For the little shooter I'm doing I want to have a linked list to hold
my objects and other for the images. But I have a doubt here, should I
use this schema - 2 linked list - or :
1 List for images
1 For objects that don't need to be validated - background tiles, explotions,
planets in the first plane,etc.. -
1 For objects to validate - spaceships, bullets, lives and so on - ..

I used the last one in a DOS side view game I did once but I'm not sure if
the first method will affect the performance - the second one does less
collition detection -. The first one allow me to deal with everything in just
one class and the map editor could be used for both..

What method do you use to hold your information - objetcs - and images?
Any advice?

Thanks in advance.

"Old programmers don't die,they just terminate and stay resident."
Thanks for all your posts!

The way I'm doing it its to have a class for holding the foe info, something like this:

Class miFoe{
int iKind;
int iFrame,iMaxFrame;
int iHp, iSpeedx,iSpeedy,...
}

the var iKind allow me to search in the images lists to display the correct one..

With the technique used by mason, Do you search the right image every time you create a new object?? Is this faster than just looking for the image when you update the screen?..

"Old programmers don't die,they just terminate and stay resident."

This topic is closed to new replies.

Advertisement