PDA

View Full Version : Enemy Generator



C-Dawg
12-19-2006, 11:05 AM
Here ya be. Havn't even really tested it yet, just coded it over a doughnut this morning. Once it's verified to work, we can put it over in the showcase forum.



// ================================================== =====
// ENEMY SPAWNER - This script is used to spawn enemies. The FFC running
// the script will continue to spawn a particular kind of enemy at regular intervals
// until there are too many on the screen, or the combo used by the spawner changes.
//
// D0 = enemy_id = The enemy to be spawned. Check the table in std.zh to get values.
// D1 = delay = The delay, in tics, between enemy spawns.
// D2 = max = The maximum number of enemies that the spawner will put on the screen.
// ================================================== ====


ffc script enemyspawner{

void run(int enemy_id, int delay, int max){


int original_combo = this->Data; // Saves the original combo of this FFC.

int counter = delay; // Used to count the tics until it is time to spawn.

while(true){
// Checks whether the combo for this FFC has changed, or whether there are
// a maximum number of NPCs on the screen.
if ( (this->Data = original combo) && (Screen->NumNPCs() < max) ){

// If max tics have gone by since the last time a spawn took place, spawn.
if ( counter = 0 ){
npc spawnee = Screen->CreateNPC(enemy_id);
spawnee->X = this->X;
spawnee->Y = this->Y;
counter = delay;
}
else{
counter--;
} // end if
} // end if
Waitframe();
} // end of while loop
} // end of void run
} // end of FFC script