Exemple #1
0
        public void RunMovement(List <PlatformObject> allObjects)
        {
            Vector2        moveY       = new Vector2(0, velocity.Y);
            PlatformObject newOnGround = null;

            foreach (RigidBody c in connected)
            {
                moveY = c.CheckMove(this, moveY, allObjects, ref newOnGround);
            }

            foreach (RigidBody c in connected)
            {
                c.pos += moveY;
            }

            onGround = newOnGround;

            Vector2 moveX = new Vector2(velocity.X, 0);

            foreach (RigidBody c in connected)
            {
                moveX = c.CheckMove(this, moveX, allObjects, ref newOnGround);
            }

            foreach (RigidBody c in connected)
            {
                c.pos     += moveX;
                c.velocity = this.velocity;
            }
        }
Exemple #2
0
        public bool IgnoreCollisions(PlatformObject obj, Vector2 move)
        {
            if (obj is RigidBody)
            {
                return(((RigidBody)obj).connectedID == connectedID);
            }

            return(obj.objectType == PlatformObjectType.Trigger || (objectType == PlatformObjectType.Character && obj.objectType == PlatformObjectType.JumpThrough && move.Y <= 0));
        }
Exemple #3
0
        bool CanCollide(PlatformObject obj)
        {
            switch (obj.objectType)
            {
            case PlatformObjectType.Character:
            case PlatformObjectType.Trigger:
                return(false);

            default:
                return(true);
            }
        }
Exemple #4
0
        public override void HandleColliding(PlatformObject obj, Vector2 move)
        {
            const float CLIMBSPEED = -4.0f;

            float playerKnee = obj is ChemBlock ? bounds.Bottom - 8: bounds.Top;
            float playerFeet = bounds.Bottom;
            float objTopY    = obj.bounds.Top;

            if ((pressingLeft || pressingRight) && playerKnee < objTopY)
            {
                velocity.Y = CLIMBSPEED;
            }
        }
Exemple #5
0
        public void Update(List <PlatformObject> allObjects)
        {
            pos += velocity;

            Point windowSize = Game1.instance.Window.ClientBounds.Size;

            if (pos.X < 0 || pos.Y < 0 || windowSize.X < pos.X || windowSize.Y < pos.Y)
            {
                destroyed = true;
            }

            PlatformObject collisionObj = null;

            foreach (PlatformObject obj in allObjects)
            {
                if (CanCollide(obj) && obj.bounds.Contains(pos))
                {
                    collisionObj = obj;
                }
            }

            if (collisionObj == null)
            {
                return;
            }

            destroyed = true;

            const float VELOCITY_TRANSFER = 0.2f;

            // hit this thing
            switch (action)
            {
            case ProjectileAction.RIVET:
                if (collisionObj is ChemBlock)
                {
                    ChemBlock body = (ChemBlock)collisionObj;
                    //Vector2 nailDirection = velocity;
                    //nailDirection.Normalize();
                    body.Nailed(Vector2.Zero - GetCollisionNormal(collisionObj.bounds, pos - velocity, pos));
                    body.velocity += velocity * VELOCITY_TRANSFER;
                    body.UpdatedVelocity();
                }
                break;

            case ProjectileAction.BUBBLE:
                SpawnBubble(collisionObj, pos, GetCollisionNormal(collisionObj.bounds, pos - velocity, pos), allObjects);
                break;
            }
        }
Exemple #6
0
 public override void HandleColliding(PlatformObject obj, Vector2 move)
 {
     if (obj is ChemBlock)
     {
         ChemBlock block = (ChemBlock)obj;
         if (!IsBondedWith(block) && nailDuration > 0)
         {
             Vector2 moveDir = move;
             moveDir.Normalize();
             if (nailDirection.DotProduct(moveDir) > 0.5f)
             {
                 NailOnto(block);
                 nailDuration = 0;
             }
         }
     }
 }
Exemple #7
0
        void SpawnBubble(PlatformObject objectHit, Vector2 pos, Vector2 direction, List <PlatformObject> allObjects)
        {
            Vectangle objectBounds = objectHit.bounds;

            if (objectHit is ChemBlock)
            {
                pos = objectBounds.Center + direction * 16;
            }

            while (objectBounds.Contains(pos))
            {
                pos += direction;
            }

            pos += direction * 17;
            Vectangle bubbleBounds = new Vectangle(pos - new Vector2(16, 16), new Vector2(32, 32));

            bool failed = false;

            foreach (PlatformObject obj in allObjects)
            {
                if (obj.bounds.Intersects(bubbleBounds))
                {
                    failed = true;
                    break;
                }
            }

            if (!failed)
            {
                Game1.instance.platformLevel.Record(FactoryCommandType.SPENDCRYSTAL);

                ChemicalElement c        = ChemicalElement.WHITE;
                ChemBlock       newBlock = new ChemBlock(c, c.ToTexture(false), bubbleBounds.TopLeft, bubbleBounds.Size, c.ToColor());
                if (objectHit is ChemBlock)
                {
                    newBlock.NailOnto((ChemBlock)objectHit);
                }
                allObjects.Add(newBlock);
            }
        }
Exemple #8
0
 public virtual void HandleColliding(PlatformObject obj, Vector2 move)
 {
 }
Exemple #9
0
        protected Vector2 CheckMove(RigidBody parentObject, Vector2 currentMove, List <PlatformObject> allObjects, ref PlatformObject onGround)
        {
            const float EPSILON     = 0.01f;
            Vectangle   moveBoundsX = GetMoveBoundsX(currentMove);
            Vectangle   moveBoundsY = GetMoveBoundsY(currentMove);

            foreach (PlatformObject obj in allObjects)
            {
                if (obj == this || IgnoreCollisions(obj, currentMove))
                {
                    continue;
                }

                Vectangle objBounds = obj.bounds;
                if (currentMove.X != 0 && moveBoundsX.Intersects(objBounds))
                {
                    // TODO: need to calculate this more precisely.
                    if (currentMove.X > 0)
                    {
                        if (moveBoundsX.Intersects(objBounds.LeftSide))
                        {
                            HandleColliding(obj, currentMove);
                            currentMove.X = objBounds.X - (pos.X + size.X + EPSILON);
                            obj.CollidedX(parentObject);
                            moveBoundsX = GetMoveBoundsX(currentMove);
                        }
                    }
                    else
                    {
                        if (moveBoundsX.Intersects(objBounds.RightSide))
                        {
                            HandleColliding(obj, currentMove);
                            currentMove.X = objBounds.MaxX + EPSILON - pos.X;
                            obj.CollidedX(parentObject);
                            moveBoundsX = GetMoveBoundsX(currentMove);
                        }
                    }
                }

                if (currentMove.Y != 0 && moveBoundsY.Intersects(objBounds))
                {
                    if (currentMove.Y > 0)
                    {
                        if (moveBoundsY.Intersects(objBounds.TopSide))
                        {
                            HandleColliding(obj, currentMove);
                            currentMove.Y = objBounds.Y - (pos.Y + size.Y + EPSILON);
                            obj.CollidedY(parentObject);
                            moveBoundsY = GetMoveBoundsY(currentMove);
                            onGround    = obj;
                        }
                    }
                    else
                    {
                        if (moveBoundsY.Intersects(objBounds.BottomSide))
                        {
                            HandleColliding(obj, currentMove);
                            currentMove.Y = objBounds.MaxY + EPSILON - pos.Y;
                            obj.CollidedY(parentObject);
                            moveBoundsY = GetMoveBoundsY(currentMove);
                        }
                    }
                }
            }

            return(currentMove);
        }