Jump to content
  • Advertisement


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


Need advice with linked lists...

This topic is 6984 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
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.


Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites
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?..

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!