Esempio n. 1
0
        public void AdjustToMoveable(Moveable move)
        {
            if (playerTangible != PlayerObjectMode.None && move.playerTangible != PlayerObjectMode.None)
            {
                if (playerTangible != move.playerTangible) return;
            }
            //moveCollided = true;
            //if (move.moveCollided) return;
            float pushX = 0;
            float movePushX = 0;
            if (!hitBox.CheckCollision(move.hitBox)) return;
            pushX = speed.X * move.moveModifier;
            movePushX = move.speed.X * moveModifier;
            AABB aabb = move.hitBox.GetAABB();
            Vector2 solution = aabb.SolveCollision(hitBox.GetAABB());
            solution /= 2;
            hitBox.SetPosition(hitBox.GetPosition() + solution);
            move.hitBox.SetPosition(move.hitBox.GetPosition() - solution);

            AdjustPositions(move, hitBox.GetPosition());
            move.AdjustPositions(this, move.hitBox.GetPosition());
            if (speed.X == 0)
            {
                speed.X = pushX;
                move.speed.X = movePushX;
            }
        }
Esempio n. 2
0
        public void AdjustPositions(Moveable move, Vector2 newpos)
        {
            if (newpos.Y != position.Y) speed.Y = Level.SolveBounce(this, true);
            if (newpos.X != position.X) speed.X = Level.SolveBounce(this, false);
            if (newpos.Y < position.Y)
            {
                state = PhysState.Grounded;
                frictionMultiplier = EnvironmentData.NORMAL;
                move.currentMass += currentMass;
                if (move.affectsResident && !move.residentList.Contains(this)) move.residentList.Add(this);
            }

            Vector2 prevPosition = position;
            position = newpos;
            hitBox.SetPosition(position);

            Vector2 dPos = position - prevPosition;
            foreach (PhysObj resident in residentList)
            {
                resident.position += dPos;
                resident.hitBox.SetPosition(resident.position);
            }
        }
Esempio n. 3
0
 public Moveable AddMoveable(Texture2D texture, Vector2 position, float moveModifier = .5f)
 {
     Moveable move = new Moveable(texture, position);
     move.moveModifier = moveModifier;
     moveList.Add(move);
     moveAuras.Add(new GaussianTargets(gameStateManager.game.GraphicsDevice));
     return move;
 }
Esempio n. 4
0
 public void CheckForPush(Moveable move)
 {
     if (playerTangible != PlayerObjectMode.None && move.playerTangible != PlayerObjectMode.None)
     {
         if (playerTangible != move.playerTangible) return;
     }
     float pushX = 0;
     if (hitBox.CheckCollision(move.hitBox))
     {
         if (pushing && (pushTarget == move || !CheckForAlreadyHeld()))
         {
             pushX = speed.X * move.moveModifier;
         }
         AdjustCollision(move);
         if (pushing && speed.X == 0 && (pushTarget == move || !CheckForAlreadyHeld()))
         {
             speed.X = pushX;
             move.speed.X = pushX;
             if (hitBox.WorldCornerMax.Y > move.hitBox.WorldCornerMin.Y)
             {
                 if (move.parent == null)
                 {
                     pushTarget = move;
                     move.parent = this;
                 }
             }
             else if (move.parent == this)
             {
                 move.parent = null;
                 pushTarget = null;
             }
         }
         else if (move.parent == this)
         {
             move.parent = null;
             pushTarget = null;
         }
     }
     else if (grabBox.CheckCollision(move.hitBox))
     {
         if (pushing && (pushTarget == move || !CheckForAlreadyHeld()))
         {
             pushX = speed.X * move.moveModifier;
             //runningSpeed = pushX;
             move.speed.X = pushX;
             speed.X = pushX;
             if (move.parent == null)
             {
                 pushTarget = move;
                 move.parent = this;
             }
         }
         else if (move.parent == this)
         {
             move.parent = null;
             pushTarget = null;
         }
     }
     else if (move.parent == this)
     {
         move.parent = null;
         pushTarget = null;
     }
 }