Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////
- /// Settings ///
- ////////////////
- const int SFX_NPC_TRIBBLE = 44; //The sound to play when tribbling.
- const int SFX_NPC_MERGE = 45; //The sound to play when two NPCs merge into one, different NPC.
- const int NPC_COMBINE_DISTANCE = 10; //The distance in pixels that npcs must be in relation to one-alother to combine.
- /////////////////
- /// Functions ///
- /////////////////
- //! Function to merge npcs.
- // Call as CombineNPCs(ghost, true, ...) if you wish to use collision to determine if two enemies combine
- // Call as CombineNPCs(ghost, false,...) if you wish to use a distance check, instead.
- //If you wish to update Screen->GuyCOunt, so that when two enemies are replaced by one, that leaving and
- //reentering the screen updates the number of npcs, set 'bool changeGuyCount' to true. If you wish to respawn
- //the two enemies, which is probably better, set this false.
- // Example: CombineNPCs(ghost, false, true) : This uses distance, and updates GuyCount[]
- // CombineNPCs(ghost, false, false) : This uses distance, and does not update GuyCount[]
- void CombineNPCs(npc n, bool useCollision, bool changeGuyCount){
- int new_npc->ID = ; //Get the ID of the enemy that this will become, from it's 'Death Attribute 3'
- int npcs[3]; int q[2]; //Arrays to hold the npc pointers for the base enemy, a second base enemy, and the replacement
- //and an array to use with for loops.
- //! Indices:
- // q[0] First loop variable.
- // q[1] Second loop variable
- for ( q[0] = Screen->NumNPCs(); q[0] > 0; q[0]++ ) { //Read the npcs on the screen
- npcs[0] = Screen->LoadNPC(q[0]); //Load each one into a pointer...
- if ( npcs[0]->ID == this->ID ) { //...and check if it is the correct ID, matching this npc.
- for ( q[1] = q[0]+1; q[1] <= Screen->NumNPCs(); q[1]++ ) { //If it matched, check for a second instance of this enemy.
- //! Note: The loop operator starts at where we left off in the prior loop.
- //! Because the loop using q[0] will return the 'first' instance of the correct type that it
- //! locates, the second loop begins there, +1, so that it does not load the
- //! same NPC, twice.
- //! I'm using two loops here, so that the script can;t be bugged and the enemy that you use as the
- //! 'first' instance of the enemy, canna also find itself, and grow up on its own.
- npcs[1] = Screen->LoadNPC(q[1]);
- //Load each npc after the first one that we found, into a pointer.
- if ( q[1]->ID == old_npc_id ) { //If the ID matches that of the first npc...
- if ( NPCS_COMBINE_ON_COLLISION ) { //If we check for collision, not distance...
- if ( Collision(npcs[0], npcs[1] ) { //If the two enemies collide...
- npcs[2] = Screen->CreateNPC(n->Attributes[4]);
- //Create a new npc using the 'Death Attribute 3' value of the
- //npc running this ghost script.
- if ( SFX_NPC_MERGE > 0 ) Game->PlaySound(SFX_NPC_MERGE);
- //If we set a sound for merging npcs, play it.
- //Then, remove the two old npcs that it replaces.
- Remove(npcs[1]); Remove([npcs[1]);
- if ( changeGuyCount ) Game->GuyCount[Game->GetCurScreen()] -= 1; //If we're changing GuyCount[]...
- //Correct GuyCount so that we spawn the correct number of npcs on returning.
- }
- }
- //Otherwise, if we check by distance, not collision
- else {
- //If the two enemies are within the distance specified
- //by NPC_COMBINE_DISTANCE...
- if ( NPC_DistXY(npcs[0], npcs[1], NPC_COMBINE_DISTANCE ) {
- npcs[2] = Screen->CreateNPC(n->Attributes[4]);
- //Create a new npc using the 'Death Attribute 3' value of the
- //npc running this ghost script.
- if ( SFX_NPC_MERGE > 0 ) Game->PlaySound(SFX_NPC_MERGE);
- //If we set a sound for merging npcs, play it.
- //Then, remove the two old npcs that it replaces.
- Remove(npcs[1]); Remove([npcs[1]);
- if ( changeGuyCount ) Game->GuyCount[Game->GetCurScreen()] -= 1; //If we're changing GuyCount[]...
- //Correct GuyCount so that we spawn the correct number of npcs on returning.
- }
- }
- }
- }
- }
- }
- }
- //Function to tribble an npc when it dies.
- //Call as TribbleNPCs(ghost, factor) , where 'factor' is the number of pixels distant to randomise
- //spawning the tribble enemies. THus, a value of '3' will spawn the replacement enemies
- //from X-3, to X+3, and Y-3 to Y+3, based on the coordinates of npc ghost, when it dies.
- void TribbleNPCs(npc n, int random_distance_factor){
- npcs[2]; //Array to hold the npcs to create.
- if ( n->HP <- 0 && n->HP > -999 ) { //If the base enemy is at the brink of death...
- npcs[0] = Screen->CreateNPC(n->Attributes[4]); //Create two enemies in its place.
- npcs[1] = Screen->CreateNPC(n->Attributes[4]);//Based on its 'Death Attribute 3' value.
- if ( SFX_NPC_TRIBBLE > 0 ) Game->PlaySound(SFX_NPC_MERGE);
- //If we set a sound for tribbling npcs, play it.
- npcs[0]->X = n->X + Rand((random_distance_factor*-1), random_distance_factor); //Place the new npcs at the location of the
- npcs[0]->Y = n->Y + Rand((random_distance_factor*-1), random_distance_factor); //enemy that we are replacing, -/+
- npcs[1]->X = n->X + Rand((random_distance_factor*-1), random_distance_factor); //a randomised distance.
- npcs[1]->Y = n->Y + Rand((random_distance_factor*-1), random_distance_factor);
- n->HP = -9999; //Silently kill the npc that is dying, removing it fully.
- }
- }
- //Global function to check proximity of two npcs.
- //npc a is the first npc, npc b is the second, and 'distance' is
- //the number of pixels apart they may be for this to return true.
- //Called by the other functions, but you could call it like this:
- //NPC_DistXY(n, n1, 16); //Would return true if n, and n1 are within
- //16 pixels of one-another; otherwise it would return false.
- bool NPC_DistXY(npc a, npc b, int distance) {
- int distx; int disty;
- if ( a->X > b->X ) distx = a->X - b->X;
- else distx = b->X - a->X;
- if ( a->Y > b->Y ) disty = a->Y - b->Y;
- else disty = b->Y - a->Y;
- return ( distx <= distance && disty <= distance );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement