Archived

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

best way to spawn an enemy

This topic is 5503 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

i need enemies to respawn elsewhere in the level after they die. They need to go to a certain location and wait there until it is time for them to attack. What is the best way to do this?

Share this post


Link to post
Share on other sites
That kind of question is really implementation-specific. Hopefully you''ve incorporated enough into your design to be able to handle these kind of situations.

You''ll probably need some sort of state machine to handle the waiting part. The respawn part is nothing more than changing the state (dead->alive or whatever) and moving to a new location.

Share this post


Link to post
Share on other sites
Respawning enemies is pretty cool! However, the best way to do it involves changing the enemies "Level Coordinated" (level''s point of reference) so that the enemy appears in a different part of the level. The enemy object should have a "die" flag that can be turned on and off. After changing the enemy''s coordinates (level coordinates) you would turn the "die" flag off. That''s the best way that I see how to do it. Good luck!


Hey, don''t forget to visit my page... by clicking here!

Share this post


Link to post
Share on other sites
the state machine is pretty much the way i am doing it now. The game is a 3d version of smash tv, so when the enemies die they go to their assigend door until the door is full of enemies, then the door opens, the enemies ai constantly checks for an open door, and when it finds it open, it goes out. This just doesn''t seem like the most efficient way, and the coding gets confusing.

Share this post


Link to post
Share on other sites
The door should notify everyone in the room that it opened. So really all the creatures should be doing is checking if their event queues are empty or not which they should be until the door opens. If you are really worried about it you can gen them in the inactive list and have the door move them into the active list when it opens. The door could gen them for that matter as it opens.

Share this post


Link to post
Share on other sites
I was wanting to make the door tell everyone that is is open, the probelem is that the door class is defined before the enemy class, so the door class cannot access anything in the enemies class. If i defined the enemies class first, i couldn''t access the x, y position of the door from the enemies funtcion, because a door class wouldn''t exits. I guess what i need to now is how to get to classes to communicate to each other regardless of the order they are defined.

Share this post


Link to post
Share on other sites
couldn''t the door class have something like this?


class Door
{
... //your other stuff
bool Open_Close;
... //other stuff still
}

class Enemy
{
void checkIfAbleToMove (/*hypothetical of course*/ bool Door.Open_Close);
...//other stuff
}

could that work?

Share this post


Link to post
Share on other sites
Thanks everyone, i''ve got it working now. I put a pointer to a door object in the enemy. In the enemies initialization takes a door object as an argument which is assigned to the enemies door. When an enemy dies, it moves to its door''s xy position, dissapears, and adds 1 to it''s doors enemy number. The door class has code do check when it is full, and changes bool isOPen to true. It then checks to see when its door is open using it''s isOpen, when this is true, it comes back to life.

Share this post


Link to post
Share on other sites