ZoriaRPG

AutoGhost Deadrock Enemy

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