Advertisement
ZoriaRPG

AutoGhost Deadrock Enemy v0.6

Nov 20th, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.34 KB | None | 0 0
  1. /////////////////////////////
  2. /// Autohost DeadRock NPC ///
  3. /// 20-Nov-2016           ///
  4. /// v0.6.0                ///
  5. /// By: ZoriaRPG          ///
  6. /////////////////////////////
  7.  
  8. const int NPC_DEADROCK_STONETIME = 300; //Time in frames that DeadRock will be petrified.
  9. const int NPC_DEADROCK_TURNTIME = 48; //The 'halttime' value for Ghost_HaltingWalk4()
  10. const int NPC_DEADROCK_TILE = 10200; //Tile for DeadRock in stoned state.
  11. const int NPC_DEADROCK_LAYER = 2; //Layer of drawn 'a[NPC_DEADROCK_ROCK]' tile.
  12. const int NPC_DEADROCK_CSET = -1; //Set to 0 or higher to use a fixed CSet.
  13. const int NPC_DEADROCK_DIST = 8; //Radius distant from enemy, when in a stoned state, to block Link's inputs.
  14. const int NPC_DEADROCK_DIST_HITDIR = 24;
  15. const int NPC_DEADROCK_WEAPONDIST = 12; //Distance for collisio of the weapon and the npc when in a a[NPC_DEADROCK_ROCK] state.
  16. const int NPC_DEADROCK_SFX_CLINK = 100;
  17.  
  18. //DeadRock ffc internal array a[] indices:
  19. const int NPC_DEADROCK_WALK = 0;
  20. const int NPC_DEADROCK_Q = 1;
  21. const int NPC_DEADROCK_W = 2;
  22. const int NPC_DEADROCK_ROCK = 3;
  23. const int NPC_DEADROCK_LASTHP = 4;
  24. const int NPC_DEADROCK_ORIGHP = 5;
  25. const int NPC_DEADROCK_RANDOM_HITDIR = 6;
  26.  
  27. ffc script DeadRock{
  28.     void run(int enem_id){
  29.        
  30.         npc ghost = Ghost_InitAutoGhost(this,enem_id);
  31.         Ghost_SetFlag(GHF_FULL_TILE_MOVEMENT); //Will not move onto partially solid combos.
  32.         Ghost_SetFlag(GHF_4WAY); //4-Way walking.
  33.         lweapon l;
  34.         int a[7]={-1};
  35.         a[NPC_DEADROCK_ORIGHP] = ghost->HP;
  36.         a[NPC_DEADROCK_RANDOM_HITDIR] = ghost->Attributes[11];     
  37.         //walk = a[NPC_DEADROCK_WALK]; q = a[NPC_DEADROCK_Q]; w = a[NPC_DEADROCK_W]; rock = a[NPC_DEADROCK_ROCK]; lasthp = a[NPC_DEADROCK_LASTHP]
  38.        
  39.         while(true){
  40.             a[NPC_DEADROCK_LASTHP] = ghost->HP;
  41.            
  42.             //Handle movement.
  43.             a[NPC_DEADROCK_WALK] = Ghost_HaltingWalk4(
  44.                 a[NPC_DEADROCK_WALK],
  45.                 ghost->Step,
  46.                 ghost->Rate,
  47.                 ghost->Homing,
  48.                 ghost->Hunger,
  49.                 ghost->Haltrate,
  50.                 NPC_DEADROCK_TURNTIME);
  51.            
  52.             //Check for collision with items
  53.             for ( a[NPC_DEADROCK_Q] = Screen->NumLWeapons(); a[NPC_DEADROCK_Q] >= 0; a[NPC_DEADROCK_Q]-- ) {
  54.                 l = Screen->LoadLWeapon(a[NPC_DEADROCK_Q]);
  55.                 if ( Collision(ghost,l) ) { //&& ghost->HP < a[NPC_DEADROCK_LASTHP]
  56.                     //if *anything hits him...
  57.                     //Turn to stone:
  58.                    
  59.                     //Draw flesh-to-stone transformation anim.
  60.                    
  61.                     for ( a[NPC_DEADROCK_Q] = 0; a[NPC_DEADROCK_Q] < 12; a[NPC_DEADROCK_Q]++ ){
  62.                         if ( a[NPC_DEADROCK_Q] % 2 == 0 ) {
  63.                             for ( a[NPC_DEADROCK_W] = 0; a[NPC_DEADROCK_W] < 5; a[NPC_DEADROCK_W]++ ) {
  64.                                 ghost->DrawXOffset = ghost->X;
  65.                                 Ghost_WaitframeLight(this, ghost);
  66.                             }
  67.                         }
  68.                         else {
  69.                             for ( a[NPC_DEADROCK_W] = 0; a[NPC_DEADROCK_W] < 5; a[NPC_DEADROCK_W]++ ) {
  70.                                 ghost->DrawXOffset = -200;
  71.                                 if ( NPC_DEADROCK_CSET >= 0 ) Screen->FastTile(NPC_DEADROCK_LAYER, ghost->X, ghost->Y, NPC_DEADROCK_TILE, NPC_DEADROCK_CSET, OP_OPAQUE);
  72.                                 else Screen->FastTile(NPC_DEADROCK_LAYER, ghost->X, ghost->Y, NPC_DEADROCK_TILE, ghost->CSet, OP_OPAQUE);
  73.                                 Ghost_WaitframeLight(this, ghost);
  74.                             }
  75.                         }
  76.                        
  77.                     }
  78.                    
  79.                     a[NPC_DEADROCK_ROCK] = NPC_DEADROCK_STONETIME;
  80.                 }
  81.             }
  82.            
  83.             //While he's stoned...
  84.             while (a[NPC_DEADROCK_ROCK]--) {
  85.                
  86.                 //Check for weapon collision and do effects by weapon type
  87.                 for ( a[NPC_DEADROCK_Q] = Screen->NumLWeapons(); a[NPC_DEADROCK_Q] >= 0; a[NPC_DEADROCK_Q]-- ) {
  88.                     l = Screen->LoadLWeapon(a[NPC_DEADROCK_Q]);
  89.                     if ( _____DistXY(ghost,l,NPC_DEADROCK_WEAPONDIST) ) {
  90.                         if ( l->ID == LW_HOOKSHOT || l->ID == LW_BRANG ) { l->DeadState = WDS_BOUNCE; Game->PlaySound(NPC_DEADROCK_SFX_CLINK); }
  91.                         if ( l->ID == LW_BEAM || l->ID >= LW_SCRIPT1 ) l->DeadState = WDS_DEAD;
  92.                         if ( l->ID == LW_ARROW ) { l->DeadState = WDS_DEAD; Game->PlaySound(NPC_DEADROCK_SFX_CLINK); }
  93.                         if ( l->ID == LW_SWORD || l->ID == LW_HAMMER || l->ID == LW_WAND ) Game->PlaySound(NPC_DEADROCK_SFX_CLINK);
  94.                     }
  95.                 }
  96.                
  97.                 //Move the real npc offscreen
  98.                 ghost->DrawXOffset = -200; ghost->HitXOffset = -200;
  99.                
  100.                 //Draw the a[NPC_DEADROCK_ROCK] tile
  101.                 if ( NPC_DEADROCK_CSET >= 0 ) Screen->FastTile(NPC_DEADROCK_LAYER, ghost->X, ghost->Y, NPC_DEADROCK_TILE, NPC_DEADROCK_CSET, OP_OPAQUE);
  102.                 else Screen->FastTile(NPC_DEADROCK_LAYER, ghost->X, ghost->Y, NPC_DEADROCK_TILE, ghost->CSet, OP_OPAQUE);
  103.                  
  104.                 //Kill inputs if Link tries to pass through DeadRock or damage to Link would push him past DeadRock...
  105.                 //Link is on the left side...
  106.                 if ( _____LeftOf(ghost) && Link->CollDetection ) {
  107.                     if ( _____DistXY(ghost, NPC_DEADROCK_DIST) && _____LinkFacing(ghost) ) {
  108.                         if ( Link->PressRight || Link->InputRight ) {
  109.                             Link->PressRight = false; Link->InputRight = false;
  110.                         }
  111.                     }
  112.                    
  113.                     //Prevent Link from damage boosting past it.
  114.                     if ( _____DistXY(ghost, NPC_DEADROCK_DIST_HITDIR) && Link->Action == LA_GOTHURTLAND || Link->Action == LA_GOTHURTWATER && Link->HitDir == DIR_RIGHT ) {
  115.                         if ( !a[NPC_DEADROCK_RANDOM_HITDIR] ) Link->HitDir = -1;
  116.                         else {
  117.                             do {
  118.                                 Link->HitDir = Rand(4);
  119.                             } while(Link->HitDir == DIR_RIGHT);
  120.                         }
  121.                     }
  122.                    
  123.                 }
  124.                 //Link is on the right side...
  125.                 if ( _____RightOf(ghost) && Link->CollDetection ) {
  126.                     if ( _____DistXY(ghost, NPC_DEADROCK_DIST) && _____LinkFacing(ghost) ) {
  127.                         if ( Link->PressLeft || Link->InputLeft ) {
  128.                             Link->PressLeft = false; Link->InputLeft = false;
  129.                         }
  130.                     }
  131.                    
  132.                     //Prevent Link from damage boosting past it.
  133.                     if ( _____DistXY(ghost, NPC_DEADROCK_DIST_HITDIR) && Link->Action == LA_GOTHURTLAND || Link->Action == LA_GOTHURTWATER && Link->HitDir == DIR_LEFT ) {
  134.                         if ( !a[NPC_DEADROCK_RANDOM_HITDIR] ) Link->HitDir = -1;
  135.                         else {
  136.                             do {
  137.                                 Link->HitDir = Rand(4);
  138.                             } while(Link->HitDir == DIR_LEFT);
  139.                         }
  140.                     }
  141.                 }
  142.                
  143.                 //Link is _____Above...
  144.                 if ( _____Above(ghost) && Link->CollDetection ) {
  145.                     if ( _____DistXY(ghost, NPC_DEADROCK_DIST) && _____LinkFacing(ghost) ) {
  146.                         if ( Link->PressDown || Link->InputDown ) {
  147.                             Link->PressDown = false; Link->InputDown = false;
  148.                         }
  149.                     }
  150.                     //Prevent Link from damage boosting past it.
  151.                     if ( _____DistXY(ghost, NPC_DEADROCK_DIST_HITDIR) && Link->Action == LA_GOTHURTLAND || Link->Action == LA_GOTHURTWATER && Link->HitDir == DIR_DOWN ) {
  152.                         if ( !a[NPC_DEADROCK_RANDOM_HITDIR] ) Link->HitDir = -1;
  153.                         else {
  154.                             //do {
  155.                             //  hitdir = Rand(4);
  156.                             //} while(hitdir == DIR_DOWN);
  157.                             //Link->HitDir = hitdir;
  158.                            
  159.                             do {
  160.                                 Link->HitDir = Rand(4);
  161.                             } while(Link->HitDir == DIR_DOWN);
  162.                    
  163.                         }
  164.                     }
  165.                 }
  166.                
  167.                 //Link is _____Below...
  168.                 if ( _____Below(ghost) && Link->CollDetection ) {
  169.                     if ( _____DistXY(ghost, NPC_DEADROCK_DIST) && _____LinkFacing(ghost) ) {
  170.                         if ( Link->PressUp || Link->InputUp ) {
  171.                             Link->PressUp = false; Link->InputUp = false;
  172.                         }
  173.                     }
  174.                     //Prevent Link from damage boosting past it.
  175.                     if ( _____DistXY(ghost, NPC_DEADROCK_DIST_HITDIR) && Link->Action == LA_GOTHURTLAND || Link->Action == LA_GOTHURTWATER && Link->HitDir == DIR_UP ) {
  176.                         if ( !a[NPC_DEADROCK_RANDOM_HITDIR] ) Link->HitDir = -1;
  177.                         else {
  178.                             do {
  179.                                 Link->HitDir = Rand(4);
  180.                             } while(Link->HitDir == DIR_UP);
  181.                         }
  182.                     }
  183.                 }
  184.                 Ghost_WaitframeLight(this, ghost);
  185.             }
  186.            
  187.             //Deadrock is no longer stoned. Restore him...
  188.             ghost->HitXOffset = ghost->X;
  189.             ghost->DrawXOffset = -200;
  190.             ghost->HP = a[NPC_DEADROCK_ORIGHP];
  191.             Ghost_Waitframe(this,ghost,true,true);
  192.         }
  193.     }
  194.    
  195.    
  196.     //Embed:
  197.    
  198.     bool _____DistXY(npc b, int distance) {
  199.         int distx; int disty;
  200.         if ( Link->X > b->X ) distx = Link->X - b->X;
  201.         else distx = b->X - Link->X;
  202.        
  203.         if ( Link->Y > b->Y ) disty = Link->Y - b->Y;
  204.         else disty = b->Y - Link->Y;
  205.  
  206.         return ( distx <= distance && disty <= distance );
  207.     }
  208.  
  209.  
  210.     bool _____DistXY(ffc b, int distance) {
  211.         int distx; int disty;
  212.         if ( Link->X > b->X ) distx = Link->X - b->X;
  213.         else distx = b->X - Link->X;
  214.        
  215.         if ( Link->Y > b->Y ) disty = Link->Y - b->Y;
  216.         else disty = b->Y - Link->Y;
  217.  
  218.         return ( distx <= distance && disty <= distance );
  219.     }
  220.        
  221.     bool _____DistXY(lweapon a, ffc b, int distance) {
  222.         int distx; int disty;
  223.         if ( a->X > b->X ) distx = a->X - b->X;
  224.         else distx = b->X - a->X;
  225.        
  226.         if ( a->Y > b->Y ) disty = a->Y - b->Y;
  227.         else disty = b->Y - a->Y;
  228.  
  229.         return ( distx <= distance && disty <= distance );
  230.     }
  231.     bool _____DistXY(lweapon a, npc b, int distance) {
  232.         int distx; int disty;
  233.         if ( a->X > b->X ) distx = a->X - b->X;
  234.         else distx = b->X - a->X;
  235.        
  236.         if ( a->Y > b->Y ) disty = a->Y - b->Y;
  237.         else disty = b->Y - a->Y;
  238.  
  239.         return ( distx <= distance && disty <= distance );
  240.     }
  241.     bool _____DistXY(npc a, lweapon b, int distance) {
  242.         int distx; int disty;
  243.         if ( a->X > b->X ) distx = a->X - b->X;
  244.         else distx = b->X - a->X;
  245.        
  246.         if ( a->Y > b->Y ) disty = a->Y - b->Y;
  247.         else disty = b->Y - a->Y;
  248.  
  249.         return ( distx <= distance && disty <= distance );
  250.     }
  251.     bool _____DistXY(ffc a, lweapon b, int distance) {
  252.         int distx; int disty;
  253.         if ( a->X > b->X ) distx = a->X - b->X;
  254.         else distx = b->X - a->X;
  255.        
  256.         if ( a->Y > b->Y ) disty = a->Y - b->Y;
  257.         else disty = b->Y - a->Y;
  258.  
  259.         return ( distx <= distance && disty <= distance );
  260.     }
  261.  
  262.     bool _____Above(npc n){ return Link->Y < n->Y; }
  263.     bool _____Below(npc n){ return Link->Y > n->Y; }
  264.     bool _____LeftOf(npc n){ return Link->X < n->X; }
  265.     bool _____RightOf(npc n){ return Link->X > n->X; }
  266.  
  267.     bool _____Above(ffc n){ return Link->Y < n->Y; }
  268.     bool _____Below(ffc n){ return Link->Y > n->Y; }
  269.     bool _____LeftOf(ffc n){ return Link->X < n->X; }
  270.     bool _____RightOf(ffc n){ return Link->X > n->X; }
  271.    
  272.     bool _____LinkFacing(ffc f){
  273.         if ( Link->Dir == DIR_UP && Link->Y > f->Y ) return true;
  274.         if ( Link->Dir == DIR_DOWN && Link->Y < f->Y ) return true;
  275.         if ( Link->Dir == DIR_RIGHT && Link->X < f->X ) return true;
  276.         if ( Link->Dir == DIR_LEFT && Link->X > f->X ) return true;
  277.         return false;
  278.     }
  279.  
  280.  
  281.     bool _____LinkFacing(npc f){
  282.         if ( Link->Dir == DIR_UP && Link->Y > f->Y ) return true;
  283.         if ( Link->Dir == DIR_DOWN && Link->Y < f->Y ) return true;
  284.         if ( Link->Dir == DIR_RIGHT && Link->X < f->X ) return true;
  285.         if ( Link->Dir == DIR_LEFT && Link->X > f->X ) return true;
  286.         return false;
  287.     }
  288. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement