Need a way of tracking lot's of enemies' energy
I''m using a sprite-list that I update every frame to keep track of my enemy sprites. I was thinking of using lot''s and lot''s of enemy-sprites, but I can''t figure out a good way of keeping track of their seperate info in a smart way.
Is the only way of doing that is to simply create lots and lots of variables for each one of them everytime an enemy-sprite is created or is there some smarter way of doing it?
I hope I made sense =)
Thanks lots!
Not sure I understand what you are trying to get at. When you create an enemy on screen you should store the data about health etc in the same structure. A list of enemies should allow you efficient access to them. Possibly put them in a b-tree for better access to an individual enemy.
My only other comment is that you should use access to the enemy struct during the frame draw for display only. There really isn''t a need to update the health of an enemy every frame. It will take the player more that 1 second(15 - 30 frames) to realize a difference in a given enemies health. The more enemies on the screen at once the longer it will take a player to recognize any given enemies health change. I would suggest that you update health much less frequently. In doing so the list traversal can be more complex, handling more enemies while not using more processor cycles. You might even be able to do more with less processing time using this method.
Seeing that I don''t know much about your game this generic response may entirely not fit your needs, but I hope it helps in some way.
Kressilac
ps Remember that in tying things to frame rate you could give advantages to those players with better systems. If you do things based on frame then those things will happen more often on better systems potentially messing up the timing in your game.
My only other comment is that you should use access to the enemy struct during the frame draw for display only. There really isn''t a need to update the health of an enemy every frame. It will take the player more that 1 second(15 - 30 frames) to realize a difference in a given enemies health. The more enemies on the screen at once the longer it will take a player to recognize any given enemies health change. I would suggest that you update health much less frequently. In doing so the list traversal can be more complex, handling more enemies while not using more processor cycles. You might even be able to do more with less processing time using this method.
Seeing that I don''t know much about your game this generic response may entirely not fit your needs, but I hope it helps in some way.
Kressilac
ps Remember that in tying things to frame rate you could give advantages to those players with better systems. If you do things based on frame then those things will happen more often on better systems potentially messing up the timing in your game.
Derek Licciardi (Kressilac)Elysian Productions Inc.
January 17, 2000 10:14 AM
What do you mean by creating lots and lots of variables?
arent you using a linked list?
struct enemy{
int id;
int energy;
unsigned *next;
unsigned *previous;
}
enemy *enemylist;
enemy *firstenemy;
if you are you only have to code 1 variable for your energy, however it is true you have to transverse your enemy list, to reach enemy 50 per example.
enemylist=firstenemy;
for (x=1;x<50;x++)
enemylist=enemylist.next;
next;
to get each one energy... if you are really concerned about this and you know how many enemies you will need, you may create an array
enemy [500];
then to reach enemy 30 energy per example you could use
enemy[29].energy=energy*0.5; (50% damage!)
I hope that helped.
p.s. off course you could also use a hash system, and a tree or a balanced tree will really help.
arent you using a linked list?
struct enemy{
int id;
int energy;
unsigned *next;
unsigned *previous;
}
enemy *enemylist;
enemy *firstenemy;
if you are you only have to code 1 variable for your energy, however it is true you have to transverse your enemy list, to reach enemy 50 per example.
enemylist=firstenemy;
for (x=1;x<50;x++)
enemylist=enemylist.next;
next;
to get each one energy... if you are really concerned about this and you know how many enemies you will need, you may create an array
enemy [500];
then to reach enemy 30 energy per example you could use
enemy[29].energy=energy*0.5; (50% damage!)
I hope that helped.
p.s. off course you could also use a hash system, and a tree or a balanced tree will really help.
make the data structure
typedef struct tagEnemy
{
int data1;
int data2;
}Enemy;
then i would use a linked list personally
if it was unlikely to change very often, an array of vector
although i would personally wrap it up as a class hierarchy, instead of proceedural style structs, but then im an OOP
typedef struct tagEnemy
{
int data1;
int data2;
}Enemy;
then i would use a linked list personally
if it was unlikely to change very often, an array of vector
although i would personally wrap it up as a class hierarchy, instead of proceedural style structs, but then im an OOP
-PoesRaven
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement