Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ProcessingMotionAirDeprecated : ProcessingBase, ITick
- {
- public Group<ComponentInAirDeprecated, ComponentPhysics, ComponentBounce, ComponentRotation, ComponentObject> groupDrop;
- public ProcessingMotionAirDeprecated()
- {
- groupDrop.Add += DropOnAdd;
- groupDrop.Remove += DropOnRemove;
- }
- static void DropOnAdd(int entity)
- {
- var cPhysics = entity.ComponentPhysics();
- cPhysics.direction = cPhysics.velocity.x >= 0 ? 1 : -1;
- }
- static void DropOnRemove(int entity)
- {
- entity.ComponentPhysics().hit = false;
- }
- public void Tick()
- {
- var delta = Time.delta;
- foreach (var entity in groupDrop)
- {
- var cInAir = Game.ComponentInAirDeprecated(entity);
- var cPhysics = entity.ComponentPhysics();
- var cBounce = entity.ComponentBounce();
- var cObject = entity.ComponentObject();
- var cRotation = entity.ComponentRotation();
- var v = cPhysics.velocity;
- v.y += cPhysics.gravity * delta;
- v.x = v.x + (0 - v.x) * delta / cPhysics.drag;
- var pos = cObject.transform.position;
- pos.x += v.x * delta;
- pos.y += v.y * delta;
- // go opposite if it occurs
- if (!cPhysics.hit)
- {
- var hits = Phys.CircleOverlap2D(pos, 0.05f, 1 << 13);
- if (hits > 0)
- {
- cPhysics.hit = true;
- v.x *= -0.5f;
- cRotation.facing = -cRotation.facing;
- }
- }
- cPhysics.velocity = v;
- if (pos.y < cInAir.landingSpot)
- {
- pos.y = cInAir.landingSpot;
- if (cBounce.amount-- == 0)
- {
- entity.Remove<ComponentInAirDeprecated>();
- entity.Remove<ComponentPhysics>();
- entity.Remove<ComponentBounce>();
- }
- else
- {
- cPhysics.velocity = new Vector2(cBounce.velX * cBounce.amount * cPhysics.direction, cBounce.velY * cBounce.amount);
- cPhysics.gravity = -12f;
- v = cPhysics.velocity;
- pos.x += v.x * delta;
- pos.y += v.y * delta;
- }
- }
- cObject.transform.position = pos;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement