Advertisement
jewalky

Untitled

Jan 5th, 2017
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.14 KB | None | 0 0
  1. const SHRINK_RATIO = 0.25;
  2.  
  3. // it's possible to check if actor is shrunk, by checking this item in inventory.
  4. // shrunk actors can't do things. can't attack, for example.
  5. class Shrunk : Inventory {}
  6.  
  7. class ShrinkTrail : Actor
  8. {
  9.     int timer;
  10.    
  11.     override void Tick()
  12.     {
  13.         //Super.Tick();
  14.         timer++;
  15.         if (timer > 6) Destroy();
  16.     }
  17.  
  18.     Default
  19.     {
  20.         +NOGRAVITY;
  21.         +NOINTERACTION;
  22.     }
  23. }
  24.  
  25. class ShrinkThinker : Actor
  26. {
  27.     enum ShrinkState
  28.     {
  29.         SS_NotShrunk,
  30.         SS_Shrinking,
  31.         SS_Shrunk,
  32.         SS_Expanding
  33.     }
  34.    
  35.     // shrinks to 0.25.
  36.     double baseScaleX;
  37.     double baseScaleY;
  38.     double baseSpeed;
  39.     double baseRadius;
  40.     double baseHeight;
  41.     int baseHealth;
  42.     bool basePlayer;
  43.     //
  44.     double baseViewHeight;
  45.     double baseViewBob;
  46.     double baseJumpZ;
  47.     double baseAttackZ;
  48.     //
  49.     double shfactor;
  50.     ShrinkState shstate;
  51.     bool juststarted;
  52.     int shrunktime;
  53.    
  54.     override void PostBeginPlay()
  55.     {
  56.         Super.PostBeginPlay();
  57.         shfactor = 1.0;
  58.         shstate = SS_NotShrunk;
  59.         juststarted = true;
  60.     }
  61.    
  62.     void ApplyShrinkFrame(bool dotrail)
  63.     {
  64.         // spawn shrink trail at current size.
  65.         // don't spawn shrink trail for players. this doesn't look well in first person.
  66.         if (dotrail && !basePlayer && level.time%2 == 0)
  67.         {
  68.             ShrinkTrail st = ShrinkTrail(Spawn("ShrinkTrail", (target.pos)));
  69.             st.sprite = target.sprite;
  70.             st.frame = target.frame;
  71.             st.A_SetScale(target.scale.x, target.scale.y);
  72.             st.angle = target.angle;
  73.             st.pitch = target.pitch;
  74.             st.roll = target.roll;
  75.         }
  76.    
  77.         if (basePlayer)
  78.         {
  79.             PlayerPawn pptarget = PlayerPawn(target);
  80.             pptarget.ViewHeight = pptarget.player.ViewHeight = baseViewHeight*shfactor;
  81.             pptarget.ViewBob = baseViewBob*shfactor;
  82.             pptarget.JumpZ = baseJumpZ*(shfactor*4);
  83.             pptarget.AttackZOffset = baseAttackZ*shfactor;
  84.         }
  85.        
  86.         target.A_SetScale(baseScaleX*shfactor, baseScaleY*shfactor);
  87.         if (!target.A_SetSize(baseRadius*shfactor, baseHeight*shfactor, true)) // weird
  88.             target.DamageMobj(null, null, 10000000, 'Crush');
  89.         if (target) target.speed = baseSpeed*shfactor;
  90.     }
  91.  
  92.     override void Tick()
  93.     {
  94.         //Super.Tick();
  95.         if (!target && juststarted) return;
  96.         else if (!target)
  97.         {
  98.             Destroy();
  99.             return;
  100.         }
  101.        
  102.         switch (shstate)
  103.         {
  104.         case SS_NotShrunk:
  105.             if (juststarted)
  106.             {
  107.                 juststarted = false;
  108.                 shstate = SS_Shrinking;
  109.                 baseScaleX = target.scale.x;
  110.                 baseScaleY = target.scale.y;
  111.                 baseSpeed = target.speed;
  112.                 baseRadius = target.radius;
  113.                 baseHeight = target.height;
  114.                 baseHealth = target.health;
  115.                 PlayerPawn pptarget = PlayerPawn(target);
  116.                 basePlayer = !!pptarget;
  117.                 if (basePlayer)
  118.                 {
  119.                     baseViewHeight = pptarget.player.ViewHeight;
  120.                     baseViewBob = pptarget.ViewBob;
  121.                     baseJumpZ = pptarget.JumpZ;
  122.                     baseAttackZ = pptarget.AttackZOffset;
  123.                 }
  124.                 //
  125.                 target.GiveInventoryType("Shrunk");
  126.                 target.Deactivate(null);
  127.                 if (!basePlayer) target.bNoClip = true;
  128.                 break;
  129.             }
  130.            
  131.             Cleanup();
  132.             return;
  133.        
  134.         case SS_Shrinking:
  135.             if (shfactor > SHRINK_RATIO) shfactor -= 0.02;
  136.             else
  137.             {
  138.                 shfactor = SHRINK_RATIO;
  139.                 shstate = SS_Shrunk;
  140.                 shrunktime = 0;
  141.                 target.bNoClip = false;
  142.                 target.Activate(null);
  143.                 target.SetState(target.ResolveState("See"));
  144.                 target.health = 1;
  145.                 break;
  146.             }
  147.            
  148.             ApplyShrinkFrame(true);
  149.             break;
  150.            
  151.         case SS_Shrunk:
  152.             if (target.health <= 0 || target.bCorpse) // if enemy died while shrunk, leave it as is.
  153.             {
  154.                 Destroy();
  155.                 return;
  156.             }
  157.  
  158.             ApplyShrinkFrame(false);
  159.  
  160.             shrunktime++;
  161.             if (shrunktime > 35*5)
  162.             {
  163.                 shstate = SS_Expanding;
  164.                 if (!basePlayer) target.bNoClip = true;
  165.                 target.Deactivate(null);
  166.             }
  167.             break;
  168.            
  169.         case SS_Expanding:
  170.             if (shfactor < 1.0) shfactor += 0.02;
  171.             else
  172.             {
  173.                 shfactor = 1.0;
  174.                 shstate = SS_NotShrunk;
  175.                 target.Activate(null);
  176.                 target.bNoClip = false;
  177.                
  178.                 /* partial cleanup */
  179.                 target.A_SetScale(baseScaleX, baseScaleY);
  180.                 target.A_SetSize(baseRadius, baseHeight, false); // this is if it didn't die.
  181.                 target.speed = baseSpeed;
  182.                 target.health = baseHealth;
  183.                 if (basePlayer)
  184.                 {
  185.                     PlayerPawn pptarget = PlayerPawn(target);
  186.                     pptarget.ViewHeight = pptarget.player.ViewHeight = baseViewHeight;
  187.                     pptarget.ViewBob = baseViewBob;
  188.                     pptarget.JumpZ = baseJumpZ;
  189.                     pptarget.AttackZOffset = baseAttackZ;
  190.                 }
  191.                
  192.                 break;
  193.             }
  194.            
  195.             ApplyShrinkFrame(true);
  196.             break;
  197.            
  198.         default:
  199.             break;
  200.         }
  201.     }
  202.    
  203.     void Cleanup()
  204.     {
  205.         if (target) // target might be dead due to expansion failure.
  206.         {
  207.             Inventory si = target.FindInventory("Shrunk");
  208.             if (si)
  209.             {
  210.                 target.RemoveInventory(si);
  211.                 si.Destroy();
  212.             }
  213.         }
  214.        
  215.         Destroy();
  216.     }
  217.    
  218.     Default
  219.     {
  220.         +NOINTERACTION;
  221.         +NOSECTOR;
  222.     }
  223. }
  224.  
  225. class ShrinkRay : Actor
  226. {
  227.     void A_MyMissile()
  228.     {
  229.         // check 'intersection' with shootable actors
  230.         BlockThingsIterator bit = BlockThingsIterator.Create(self);
  231.         while (bit.Next())
  232.         {
  233.             Actor mo = bit.thing;
  234.             if (mo == self.target) continue;
  235.             if (!mo.bSolid && !mo.bShootable) continue;
  236.             if (mo.health <= 0) continue;
  237.            
  238.             vector3 pdiff = mo.pos-pos;
  239.             if (abs(pdiff.x) > radius+mo.radius || abs(pdiff.y) > radius+mo.radius)
  240.                 continue;
  241.                
  242.             if (mo.pos.z+mo.height < pos.z ||
  243.                 mo.pos.z > pos.z+height) continue;
  244.            
  245.             if (mo.bShootable)
  246.             {
  247.                 vel = (0,0,0);
  248.                 SetState(ResolveState("Death"));
  249.                 // check if already shrunk.
  250.                 if (mo.FindInventory("Shrunk")) continue;
  251.                 // bosses cannot be shrinked.
  252.                 if (mo.bBoss) continue;
  253.                 // check if actor can be shrinked.
  254.                 int ndmg = ApplyDamageFactor('ShrinkRay', 100);
  255.                 if (!ndmg) continue; // can't damage
  256.                 // shrink the actor!
  257.                 ShrinkThinker st = ShrinkThinker(Spawn("ShrinkThinker", mo.pos));
  258.                 st.target = mo;
  259.             }
  260.            
  261.             return;
  262.         }
  263.     }
  264.    
  265.     override bool CanCollideWith(Actor other, bool passive)
  266.     {
  267.         return false; // manual collision detection.
  268.     }
  269.    
  270.     Default
  271.     {
  272.         Projectile;
  273.        
  274.         Radius 8;
  275.         Height 16;
  276.         Speed 16;
  277.        
  278.         Scale 0.75;
  279.        
  280.         RenderStyle "Add";
  281.        
  282.         //SeeSound "octa/missile";
  283.     }
  284.    
  285.     States
  286.     {
  287.     Spawn:
  288.         SHRY AABBCCDD 1 BRIGHT A_MyMissile;
  289.         loop;
  290.     Death:
  291.         SHRY EFGH 4 BRIGHT;
  292.         stop;
  293.     }
  294. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement