Advertisement
dimmpixeye

Untitled

Dec 8th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1.  public class ProcessingMotionAirDeprecated : ProcessingBase, ITick
  2.     {
  3.         public Group<ComponentInAirDeprecated, ComponentPhysics, ComponentBounce, ComponentRotation, ComponentObject> groupDrop;
  4.    
  5.         public ProcessingMotionAirDeprecated()
  6.         {
  7.             groupDrop.Add += DropOnAdd;
  8.             groupDrop.Remove += DropOnRemove;
  9.         }
  10.  
  11.         static void DropOnAdd(int entity)
  12.         {
  13.             var cPhysics = entity.ComponentPhysics();
  14.             cPhysics.direction = cPhysics.velocity.x >= 0 ? 1 : -1;
  15.         }
  16.         static void DropOnRemove(int entity)
  17.         {
  18.             entity.ComponentPhysics().hit = false;
  19.         }
  20.  
  21.         public void Tick()
  22.         {
  23.             var delta = Time.delta;
  24.             foreach (var entity in groupDrop)
  25.             {
  26.                 var cInAir    = Game.ComponentInAirDeprecated(entity);
  27.                 var cPhysics  = entity.ComponentPhysics();
  28.                 var cBounce   = entity.ComponentBounce();
  29.                 var cObject   = entity.ComponentObject();
  30.                 var cRotation = entity.ComponentRotation();
  31.                 var v         = cPhysics.velocity;
  32.                
  33.                 v.y += cPhysics.gravity * delta;
  34.                 v.x = v.x + (0 - v.x) * delta / cPhysics.drag;
  35.  
  36.                 var pos = cObject.transform.position;
  37.                 pos.x += v.x * delta;
  38.                 pos.y += v.y * delta;
  39.  
  40.                 // go opposite if it occurs
  41.                 if (!cPhysics.hit)
  42.                 {
  43.                     var hits = Phys.CircleOverlap2D(pos, 0.05f, 1 << 13);
  44.  
  45.                     if (hits > 0)
  46.                     {
  47.                         cPhysics.hit = true;
  48.                         v.x *= -0.5f;
  49.                         cRotation.facing = -cRotation.facing;
  50.                     }
  51.                 }
  52.  
  53.                 cPhysics.velocity = v;
  54.                
  55.                 if (pos.y < cInAir.landingSpot)
  56.                 {
  57.                     pos.y = cInAir.landingSpot;
  58.  
  59.                     if (cBounce.amount-- == 0)
  60.                     {
  61.                         entity.Remove<ComponentInAirDeprecated>();
  62.                         entity.Remove<ComponentPhysics>();
  63.                         entity.Remove<ComponentBounce>();
  64.                     }
  65.                     else
  66.                     {
  67.                         cPhysics.velocity = new Vector2(cBounce.velX * cBounce.amount * cPhysics.direction, cBounce.velY * cBounce.amount);
  68.                         cPhysics.gravity = -12f;
  69.                         v = cPhysics.velocity;
  70.  
  71.                         pos.x += v.x * delta;
  72.                         pos.y += v.y * delta;
  73.                     }
  74.                 }
  75.  
  76.                 cObject.transform.position = pos;
  77.             }
  78.         }
  79.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement