ZoriaRPG

DrawCollision.zh

Nov 19th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.49 KB | None | 0 0
  1. //TileCollision.zh
  2. //v0.2.4
  3.  
  4. float Vars[147414];
  5. const int FRAME_COUNT = 0;
  6.  
  7. int ScreenNPCs[256];
  8. int ScreenLWeapons[256];
  9. int ScreenEWeapons[256];
  10. int ScreenItems[256];
  11.  
  12. global script active{
  13.     void run(){
  14.         Vars[FRAME_COUNT] = 1; //Start of a new game, set the frame count at '1'.
  15.         while(true){
  16.             FrameCounter(); //Increase the frame count by 1 each frame, so that we can use it as a reference.
  17.             Waitdraw();
  18.             Waitframe();
  19.         }
  20.     }
  21. }
  22.  
  23. //Damage NPCs on Collision with Tiles by making a temporary weapon. This is the most HACKISH way to handle this.
  24. bool DrawTileCollisionDamage(int damage, int weap_type, int layer, int x, int y, int tile, int blockw, int blockh, int cset, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  25.    
  26.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  27.    
  28.     //We need to adjust damage based on the weapon type.
  29.     for ( int q = 1; q <= Screen->NumNPCs(); q++ ) {
  30.         if ( ( n->X >= ( x-8 ) && n->X <= (x + (blockw*16) + 8) && n->Y >= ( x-8 ) && ->Y <= ( y + (blockh*16) + 8 ) ) ){
  31.         {
  32.             lweapon l = Screen->CreateLWeapon(weap_type);
  33.             l->X = n->X;
  34.             l->Y = n->Y;
  35.             l->UseSprite(0);
  36.             l->DeadState = WDS_DEAD;
  37.         }
  38.     }
  39.    
  40.         //! We need f->HitWidth & f->HitHeight in here.
  41.     //here, we need to consider the collision box of the npc, and calculate X/Y offsets for that, too.
  42.    
  43. }
  44.  
  45.  
  46. //Store the ID of an enemy in the array when collision occurs. Damage handling must be separate.
  47. bool DrawTileCollision_N(int layer, int x, int y, int tile, int blockw, int blockh, int cset, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  48.     npc n;
  49.     int nx; int ny;
  50.    
  51.    
  52.        
  53.    
  54.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  55.     for ( int q = 1; q <= Screen->NumNPCs(); q++ ) {
  56.         n = Screen->LoadNPC(q);
  57.         if ( n->X >= ( x-8 ) && n->X <= (x + (blockw*16) + 8) && n->Y >= ( x-8 ) && ->Y <= ( y + (blockh*16) + 8 ) );
  58.             ScreenNPCs[q] = n->ID;
  59.     }
  60.         //! We need f->HitWidth & f->HitHeight in here.
  61.     //here, we need to consider the collision box of the npc, and calculate X/Y offsets for that, too.
  62.    
  63. }
  64.            
  65.        
  66. //Runs a counter so that we always know what frame we are on.
  67. void FrameCounter(){
  68.     if ( Vars[FRAME_COUNT] <= 60 ) Vars[FRAME_COUNT]++;
  69.     else if Vars[FRAME_COUNT] > 60 ) Vars[FRAME_COUNT] = 1;
  70. }
  71.  
  72. bool DrawTileCollision(npc n, int layer, int x, int y, int tile, int blockw, int blockh, int cset, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  73.  
  74.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  75.     return ( n->X >= ( x-8 ) && n->X + n->HitWidth <= (x + (blockw*16) + 8) && n->Y >= ( x-8 ) && n->Y + n->HitHeight <= ( y + (blockh*16) + 8 ) );
  76.    
  77. }
  78.  
  79. void DamageNPC(int npc, int damage){
  80.     if ( !Vars[FRAME_COUNT] % 60 ) n->HP -=damage;
  81. }
  82.  
  83. //Damage NPCs on Collision with Tiles
  84. bool DrawTileCollisionDamage(int damage, int layer, int x, int y, int tile, int blockw, int blockh, int cset, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  85.  
  86.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  87.  
  88.     for ( int q = 1; q <= Screen->NumNPCs(); q++ ) {
  89.         if ( ( n->X >= ( x-8 ) && n->X + n->HitWidth <= (x + (blockw*16) + 8) && n->Y >= ( x-8 ) && n->Y + n->HitHeight <= ( y + (blockh*16) + 8 ) ) ){
  90.             DamageNPC(n,damage);
  91.     }
  92.    
  93.         //! We need f->HitWidth & f->HitHeight in here.
  94.     //here, we need to consider the collision box of the npc, and calculate X/Y offsets for that, too.
  95.    
  96. }
  97.  
  98. //Draws block of tiles and returns if **Link** is in Collision with them.
  99. bool DrawTileCollision(layer, int x, int y, int tile, int blockw, int blockh, int cset, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  100.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  101.     return ( Link->X + Link->HitXOffset >= ( x-8 ) && Link->X + Link->HitXOffset + Link->HitWidth <= (x + (blockw*16) + 8) && Link->Y + Link->HitYOffset >= ( x-8 ) && Link->Y + Link->HitYOffset + Link->HitHeight <= ( y + (blockh*16) + 8 ) );
  102. }
  103.  
  104. //Draws block of tiles and returns if **Link** is in Collision with them.
  105. bool LinkTileCollision(layer, int x, int y, int tile, int blockw, int blockh, int cset, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  106.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  107.     return ( Link->X + Link->HitXOffset >= ( x-8 ) && Link->X + Link->HitXOffset + Link->HitWidth <= (x + (blockw*16) + 8) && Link->Y + Link->HitYOffset >= ( x-8 ) && Link->Y + Link->HitYOffset + Link->HitHeight <= ( y + (blockh*16) + 8 ) );
  108. }
  109.  
  110. //Draws a block of tiles and returns if npc 'n' is on collision with them.
  111. bool DrawTileCollision(npc n, int layer, int x, int y, int tile, int blockw, int blockh, int cset,  int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  112.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  113.     return ( n->X >= ( x-8 ) && n->X + n->HitWidth <= (x + (blockw*16) + 8) && n->Y >= ( x-8 ) && n->Y + n->HitHeight <= ( y + (blockh*16) + 8 ) );
  114. }
  115.  
  116. //Draws a block of tiles and returns if ffc 'f' is on collision with them.
  117. bool DrawTileCollision(ffc f, int layer, int x, int y, int tile, int blockw, int blockh, int cset,  int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  118.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  119.     return ( f->X >= ( x-8 ) && f->X + (f->TileWidth*16) <= (x + (blockw*16) + 8) && f->Y >= ( x-8 ) && f->Y + (f->TileHeight*16) <= ( y + (blockh*16) + 8 ) );
  120. }
  121.  
  122. //Draws a block of tiles and returns if lweapon 'l' is on collision with them.
  123. bool DrawTileCollision(lweapon l, int layer, int x, int y, int tile, int blockw, int blockh, int cset, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  124.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  125.     return ( l->X + l->HitXOffset >= ( x-8 ) && l->X + l->HitXOffset + l->HitWidth <= (x + (blockw*16) + 8) && l->Y + l->HitYOffset >= ( x-8 ) && l->Y + l->HitYOffset + l->HitHeight <= ( y + (blockh*16) + 8 ) );
  126. }
  127.  
  128. //Draws a block of tiles and returns if item 'i' is on collision with them.
  129. bool DrawTileCollision(item i, int layer, int x, int y, int tile, int blockw, int blockh, int cset, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  130.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  131.     return ( i->X + i->HitXOffset >= ( x-8 ) && i->X + i->HitXOffset + i->HitWidth <= (x + (blockw*16) + 8) && i->Y + i->HitYOffset >= ( x-8 ) && i->Y + i->HitYOffset + i->HitHeight <= ( y + (blockh*16) + 8 ) );
  132. }
  133.  
  134. //Draws a block of tiles and returns if npc 'e' is in collision with them.
  135. //! This will pose a problem if we want to use it in for loops, as we need to know
  136. //! the e pointer first, but we're already drawing.
  137. bool DrawTileCollision(eweapon e, int layer, int x, int y, int tile, int blockw, int blockh, int cset, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  138.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  139.     return ( e->X + e->HitXOffset >= ( x-8 ) && e->X + e->HitXOffset + e->HitWidth <= (x + (blockw*16) + 8) && e->Y + e->HitYOffset >= ( x-8 ) && e->Y + e->HitYOffset + e->HitHeight <= ( y + (blockh*16) + 8 ) );
  140. }
  141.  
  142. //Draws a block of tiles and returns the pointer ID of lweapon 'l' if it is in collision with them.
  143. int DrawTileCollisionNPC(int layer, int x, int y, int tile, int blockw, int blockh, int cset, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  144.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  145.     npc n;
  146.     for ( int q = 1; q <= Screen->NumNPCs(); q++ ) {
  147.         n = Screen->LoadNPC(q);
  148.         if ( n->X + n->HitXOffset >= ( x-8 ) && n->X + n->HitXOffset + n->HitWidth <= (x + (blockw*16) + 8) && n->Y + n->HitYOffset >= ( x-8 ) && n->Y + n->HitYOffset + n->HitHeight <= ( y + (blockh*16) + 8 ) )
  149.             return q;
  150.     }
  151.     return 0;
  152. }
  153.  
  154. //Draws a block of tiles and returns the ID of an ffc 'f' if it is in collision with them.
  155. int DrawTileCollisionFFC(int layer, int x, int y, int tile, int blockw, int blockh, int cset,  int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  156.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  157.     ffc f;
  158.     for ( int q = 1; q <= 32; q++ ) {
  159.         f = Screen->LoadFFC(q);
  160.         if ( f->X >= ( x-8 ) && f->X + (f->TileWidth*16) <= (x + (blockw*16) + 8) && f->Y >= ( x-8 ) && f->Y + (f->TileHeight*16) <= ( y + (blockh*16) + 8 ) )
  161.         return q;
  162.     }
  163.     return 0;
  164. }
  165.  
  166. //Draws a block of tiles and returns the pointer ID of lweapon 'l' if it is in collision with them.
  167. int DrawTileCollisionLW(int layer, int x, int y, int tile, int blockw, int blockh, int cset, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  168.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  169.     lweapon l;
  170.     for ( int q = 1; q <= Screen->NumLWeapons(); q++ ) {
  171.         l = Screen->LoadLWeapon(q);
  172.         if ( l->X + l->HitXOffset >= ( x-8 ) && l->X + l->HitXOffset + l->HitWidth <= (x + (blockw*16) + 8) && l->Y + l->HitYOffset >= ( x-8 ) && l->Y + l->HitYOffset + l->HitHeight <= ( y + (blockh*16) + 8 ) )
  173.             return q;
  174.     }
  175.     return 0;
  176. }
  177.  
  178. //Draws a block of tiles and returns the pointer ID of eweapon 'e' if it is in collision with them.
  179. bool DrawTileCollisionEW(int layer, int x, int y, int tile, int blockw, int blockh, int cset, int rx, int ry, int rangle, int flip, bool transparency, int opacity){
  180.     DrawTile(layer, x, y, tile, blockw, blockh, cset, -1, -1, rx, ry, rangle, flip, transparency, opacity);
  181.     eweapon e;
  182.     for ( int q = 1; q <= Screen->NumEWeapons(); q++ ) {
  183.         e = Screen->LoadEWeapon(q);
  184.         if ( e->X + e->HitXOffset >= ( x-8 ) && e->X + e->HitXOffset + e->HitWidth <= (x + (blockw*16) + 8) && e->Y + e->HitYOffset >= ( x-8 ) && e->Y + e->HitYOffset + e->HitHeight <= ( y + (blockh*16) + 8 ) )
  185.             return q;
  186.     }
  187.     return 0;
  188. }
  189.  
  190.  
  191.    
  192. //We need additional args to constrain hit size of box. int CollWidthX and int CollWidthY
  193.  
  194. //DrawCombbo Collision
  195.  
  196. //Draws a combo, or combo block, and returns if it is in collision with Link.
  197. bool DrawComboCollision( int layer, int x, int y, int combo, int w, int h, int cset, int rx, int ry, int rangle, int frame, int flip, bool transparency, int opacity){
  198.  
  199.     DrawCombo(layer, x, y, combo, w, h, cset, -1, -1, rx, ry, rangle, frame, flip, transparency opacity);
  200.  
  201.     return ( Link->X + Link->HitXOffset >= ( x-8 ) && Link->X + Link->HitXOffset + Link->HitWidth <= (x + (blockw*16) + 8) && Link->Y + Link->HitYOffset >= ( x-8 ) && Link->Y + Link->HitYOffset + Link->HitHeight <= ( y + (blockh*16) + 8 ) );
  202.  
  203. }
  204.  
  205. //Draws a combo, or combo block, and returns if it is in collision with Link.
  206. //! Accepts additional hitbox constraints collWidthX and collWidthY.
  207. bool DrawComboCollision( int layer, int x, int y, int combo, int w, int h, int cset, int rx, int ry, int rangle, int frame, int flip, bool transparency, int opacity, int collWidthX, int collWidthY){
  208.    
  209.     DrawCombo(layer, x, y, combo, w, h, cset, -1, -1, rx, ry, rangle, frame, flip, transparency opacity);
  210.    
  211.     return ( Link->X + Link->HitXOffset >= (x + (blockw*16) + 8 + collWidthX) && Link->X + Link->HitXOffset + Link->HitWidth <= (x + (blockw*16) + 8) && Link->Y + Link->HitYOffset >= ( x-8 ) && Link->Y + Link->HitYOffset + Link->HitHeight <= ( y + (blockh*16) + 8 + collWidthY) );
  212. }
  213.  
  214.  
  215. //! ### If n collided with this last frame, check if there are any other collisions.
  216. //! if so, return the first of those, and so forth.
  217. //! otherwise, return whatever it hit.
  218.  
  219. //Very preliminary function for circular combo or tile collision. Note that the maths here are placeholders, and incorrect.
  220. bool DrawCircularComboCollision( int layer, int x, int y, int combo, int w, int h, int cset, int rx, int ry, int rangle, int frame, int flip, bool transparency, int opacity){
  221.     int lx = Link->X; //So that we can modify them to adjust for things, if needed.
  222.     int ly = Link->Y;
  223.     int lx = Link->Z; //We should have a separate function with int UseZ, for this.
  224.     int cmbX = x+w;
  225.     int cmbY = x+h;
  226.     int xrad = cmbx / 2; //Use these to gauge distance from the effect.
  227.     int yrad = cmbY / 2;
  228.    
  229.     bool matchX;
  230.     bool matchY;
  231.    
  232.    
  233.     DrawCombo(layer, x, y, combo, w, h, cset, -1, -1, rx, ry, rangle, frame, flip, transparency opacity);
  234.     int collBoxX = x + (w*16);
  235.     int collBoxY = y + (h*16);
  236.     //if ( ( lx <= collBoxX-4 && lx > collBoxX-5 ) || ( lx >= collBoxX +12 && lx < collBoxX+13 ) ) matchX = true;
  237.     //if ( ( ly <= collBoxY-4 && ly > collBoxY-5 ) || ( ly >= collBoxY +12 && ly < collBoxY+13 ) ) matchY = true;
  238.     //if ( matchX && matchY ) return true;
  239.     if ( Distance( LinkCenterX(), LinkCenterY(), cmbX, cmbY ) <= 8+xrad ) return true;
  240.     return false;
  241. }
  242.  
  243. //////////////////////////////////
  244. /// Enemy Invincibility Frames ///
  245. //////////////////////////////////
  246.  
  247. //Settings for Enemy Invincibility Frames
  248. const int ENEMY_INVINCIBILITY_FRAMES_DURATION = 180;
  249. const int INVINCIBLE_ENEMIES_PHANTOM = 1; //Setting to enable or disable phantoming injured enemies.
  250. const int STORE_ORIGINAL_ENEMY_PALETTE = 1; //Setting to enable storing original enemy palette or cset.
  251.  
  252. //You may enable *ONE* of these two rules, to match your quest rule settings.
  253. //! If one is enabled, the other MUST be disabled.
  254. const int ENEMIES_FLICKER_WHEN_HIT = 0; //Use the OriginalSprite, and store it instead of CSet or BPal
  255. const int ENEMIES_FLASH_WHEN_HIT = 0; //Use the CSet or BPal to make an enemy flash, when hit.
  256.  
  257. //Values For Enemy Invincibility Frames
  258.  
  259. //n->Misc Indices
  260. const int ENEM_HP_LAST = 1; //n->Mics[] holds last enemy HP. Adjusted when damaged.
  261. const int ENEM_INV_FRAMES = 2; //n->Misc[] holds the present nth frame of invincibility as a countdown timer.
  262. const int ENEM_ORIG_PAL = 3; //original CSet or Palette, or OriginalSprite
  263.  
  264. const int ENEM_BLANK_TILE = 65260; //Set to a tile at the head of a FULL PAGE of BLANK tiles.
  265. //const int ENEM_FLASH_TIMER = 4;
  266.  
  267. //Framecount for each enemy flash or flicker.
  268. const int ENEM_FLASH_1 = 180; //Will change on frame 180
  269. const int ENEM_FLASH_2 = 150; //...frame 150
  270. const int ENEM_FLASH_3 = 120;
  271. const int ENEM_FLASH_4 = 90;
  272. const int ENEM_FLASH_5 = 60;
  273. const int ENEM_FLASH_6 = 30; //...frame 30
  274.  
  275. //Cset or BPal to use when flashing
  276. const int ENEM_BPAL_FLASH = 6;
  277. const int ENEM_CSET_FLASH = 6;
  278.  
  279.  
  280. //Run before Waitdraw, and before EnemyInvincibilityFrames()
  281. void InitEnemyLastHP(){
  282.     for ( int q = 1; q <= Screen->NumNPCs(); q++ ) {
  283.         npc n = Screen->LoadNPC(q);
  284.         if (!n->Misc[ENEM_HP_LAST] && n->HP > 0) n->Misc[ENEM_HP_LAST] = n->HP;
  285.         if ( STORE_ORIGINAL_ENEMY_PALETTE && !n->Misc[ENEM_ORIG_PAL] ) {
  286.             if ( n->CSet == 14 ) n->Misc[ENEM_ORIG_PAL] = n->BossPal;
  287.             else n->Misc[ENEM_ORIG_PAL] = n->CSet;
  288.         }
  289.         if ( ENEMIES_FLICKER_WHEN_HIT && !n->Misc[ENEM_ORIG_PAL] ) {
  290.             n->Misc[ENEM_ORIG_PAL] = n->OriginalTile;
  291.         }
  292.     }
  293. }
  294.  
  295. void _InitEnemyLastHP(){
  296.     for ( int q = 1; q <= Screen->NumNPCs(); q++ ) {
  297.         npc n = Screen->LoadNPC(q);
  298.         if (!n->Misc[ENEM_HP_LAST] && n->HP > 0) n->Misc[ENEM_HP_LAST] = n->HP;
  299.     }
  300. }
  301.  
  302. //Run before Waitdraw and before any collision/damage functions that need to read these values.
  303. void _EnemyInvincibilityFrames(){
  304.     for ( int q = 1; q <= Screen->NumNPCs(); q++ ) {
  305.         npc n = Screen->LoadNPC(q);
  306.         if ( n->Misc[ENEM_HP_LAST] > n->HP ) {
  307.             n->Misc[ENEM_HP_LAST] = n->HP;
  308.             n->Misc[ENEM_INV_FRAMES] = ENEMY_INVINCIBILITY_FRAMES_DURATION;
  309.         }
  310.         if ( n->Misc[ENEM_INV_FRAMES] > 0 ) n->Misc[ENEM_INV_FRAMES]--;
  311.         if ( n->Misc[ENEM_INV_FRAMES] < 0 ) n->Misc[ENEM_INV_FRAMES] = 0;
  312.     }
  313. }
  314.  
  315. //Run after InitEnemyLastHP, before Waitdraw and before any collision/damage functions that need to read these values.
  316. void EnemyInvincibilityFrames(){
  317.     for ( int q = 1; q <= Screen->NumNPCs(); q++ ) {
  318.         npc n = Screen->LoadNPC(q);
  319.         if ( n->Misc[ENEM_HP_LAST] > n->HP ) {
  320.             n->Misc[ENEM_HP_LAST] = n->HP;
  321.             n->Misc[ENEM_INV_FRAMES] = ENEMY_INVINCIBILITY_FRAMES_DURATION;
  322.         }
  323.         if ( n->Misc[ENEM_INV_FRAMES] > 0 ) n->Misc[ENEM_INV_FRAMES]--;
  324.         if ( n->Misc[ENEM_INV_FRAMES] < 0 ) n->Misc[ENEM_INV_FRAMES] = 0;
  325.        
  326.         if ( INVINCIBLE_ENEMIES_PHANTOM ) {
  327.             if ( EnemyInvincible(n) && n->DrawStyle != DS_PHANTOM ) n->DrawStyle = DS_PHANTOM;
  328.             if ( !EnemyInvincible(n) && n->DrawStyle == DS_PHANTOM
  329.                 && !GetNPCMiscFlag(n,NPCM_TRANSLUCENT) && !GetNPCMiscFlag(n,NPCM_FLICKERING)
  330.                 && !GetNPCMiscFlag(n,NPCM_FLASHING) ) n->DrawStyle = DS_NORMAL;
  331.  
  332.         }
  333.     }
  334. }
  335.  
  336.  
  337.  
  338. //Run IMMEDIATELY AFTER EnemyInvincibilityFrames() if you have flashing, or flickering settings enabled.
  339. void FlashEnemyWhenHit(npc n) {
  340.     if ( ENEMIES_FLASH_WHEN_HIT && n->Misc[ENEM_INV_FRAMES] > 0 ) {
  341.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_1 ) {
  342.             if ( n->CSet == 14 ) n->BossPal = ENEM_BPAL_FLASH;
  343.             else n->CSet = ENEM_CSET_FLASH;
  344.         }
  345.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_2 ) {
  346.             if ( n->CSet == 14 ) n->BossPal = n->Misc[ENEM_ORIG_PAL];
  347.             else n->CSet = n->Misc[ENEM_ORIG_PAL];
  348.         }
  349.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_3 ) {
  350.             if ( n->CSet == 14 ) n->BossPal = ENEM_BPAL_FLASH;
  351.             else n->CSet = ENEM_CSET_FLASH;
  352.         }
  353.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_4 ) {
  354.             if ( n->CSet == 14 ) n->BossPal = n->Misc[ENEM_ORIG_PAL];
  355.             else n->CSet = n->Misc[ENEM_ORIG_PAL];
  356.         }
  357.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_5 ) {
  358.             if ( n->CSet == 14 ) n->BossPal = ENEM_BPAL_FLASH;
  359.             else n->CSet = ENEM_CSET_FLASH;
  360.         }
  361.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_6 ) {
  362.             if ( n->CSet == 14 ) n->BossPal = n->Misc[ENEM_ORIG_PAL];
  363.             else n->CSet = n->Misc[ENEM_ORIG_PAL];
  364.         }
  365.     }
  366.     if ( ENEMIES_FLICKER_WHEN_HIT && n->Misc[ENEM_INV_FRAMES] > 0 ) {
  367.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_1 ) {
  368.             n->OriginalTile = ENEM_BLANK_TILE;
  369.         }
  370.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_2 ) {
  371.             n->OriginalTIle = n->Misc[ENEM_ORIG_PAL];
  372.         }
  373.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_3 ) {
  374.             n->OriginalTile = ENEM_BLANK_TILE;
  375.         }
  376.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_4 ) {
  377.             n->OriginalTIle = n->Misc[ENEM_ORIG_PAL];
  378.         }
  379.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_5 ) {
  380.             n->OriginalTile = ENEM_BLANK_TILE;
  381.         }
  382.         if ( n->Misc[ENEM_INV_FRAMES] == ENEM_FLASH_6 ) {
  383.             n->OriginalTIle = n->Misc[ENEM_ORIG_PAL];
  384.         }
  385.     }
  386. }
  387.  
  388. //Returns if an enemy is invincible.
  389. int EnemyInvincible(npc n){
  390.     return n->Misc[ENEM_INV_FRAMES];
  391. }
  392.  
  393.  
  394. //! Who originally made this? I'm adapting some of it as a method, ad DrawYOffset is probably better than changing the tile.
  395. ffc script FlickerWhenHit{
  396.     void run(int enemyID){
  397.         npc e = FindNPCOf(enemyID);
  398.         e->Misc[0] = 1;
  399.         int life = e->HP;
  400.         int offset = e->DrawYOffset;
  401.         int flicker;
  402.         while(e->isValid()){
  403.             if(e->HP < life){
  404.                 flicker = FLICKER_TIME;
  405.                 life = e->HP;
  406.             }
  407.             if(flicker > 0 && e->HP > 0){
  408.                 if(flicker%2 == 0) e->DrawYOffset = -200;
  409.                 else e->DrawYOffset = offset;
  410.                 flicker--;
  411.             }
  412.             else e->DrawYOffset = offset;
  413.             Waitframe();
  414.         }
  415.     }
  416.     npc FindNPCOf(int enemyID){
  417.         npc e;
  418.         for(int i = Screen->NumNPCs(); i > 0; i--){
  419.             npc e2 = Screen->LoadNPC(i);
  420.             if(e2->ID != enemyID) continue;
  421.             else if(e2->Misc[0] != 0) continue;
  422.             e = e2;
  423.             break;
  424.         }
  425.         return(e);
  426.     }
  427. }
  428.  
  429.  
  430. ///Circular Implementation Refs
  431.  
  432. //A circular collision between an ffc and an ffc. Uses TileWidth and TileHeight to find the centre of the FFCs.
  433. bool Collision(ffc f, int radius1, ffc f2, int radius2) {
  434.     return CircleCollision(f->X+f->TileWidth/2, f->Y+f->TileHeight/2, radius1,f2->X+f2->TileWidth/2, f2->Y+f2->TileHeight/2, radius2);
  435. }
  436.  
  437. //Returns true if the two circles c1 and c2 overlap.
  438. bool CircleCollision(int c1x, int c1y, int radius1, int c2x, int c2y, int radius2) {
  439.   return (Distance(c1x,c1y,c2x,c2y) <= (radius1+radius2));
  440. }
  441.  
  442. //A circular collision between an ffc and an ffc. Uses TileWidth and TileHeight to find the centre of the FFCs.
  443. bool Collision(ffc f, int radius1, ffc f2, int radius2) {
  444.     return CircleCollision(f->X+f->TileWidth/2, f->Y+f->TileHeight/2, radius1,f2->X+f2->TileWidth/2, f2->Y+f2->TileHeight/2, radius2);
  445. }
Add Comment
Please, Sign In to add comment