Beispiel #1
0
        public void ExecuteCollision(Rectangle playerRec, Rectangle newRectangle, int xOffset, int yOffset, IMove entity)
        {
            // Trap hero inside window borders
            if (entity.Position.X < -20)
            {
                entity.Position = new Vector2(-20, entity.Position.Y);
            }

            if (entity.Position.X + 20 > xOffset - playerRec.Width)
            {
                entity.Position = new Vector2(xOffset - playerRec.Width - 20, entity.Position.Y);
            }

            if (entity.Position.Y < 0)
            {
                entity.Velocity = new Vector2(entity.Velocity.X, 7.5f);
            }

            if (entity.Position.Y > yOffset - playerRec.Height)
            {
                entity.Position = new Vector2(entity.Position.X, yOffset - playerRec.Height);
            }



            if (collisionhelper.CollisionLeftOf(playerRec, newRectangle))
            {
                entity.Position = new Vector2(newRectangle.Left - playerRec.Width - 2, entity.Position.Y);
            }

            if (collisionhelper.CollisionRightOf(playerRec, newRectangle))
            {
                entity.Position = new Vector2(newRectangle.Right + 2, entity.Position.Y);
            }

            if (collisionhelper.CollisionBottomOf(playerRec, newRectangle))
            {
                entity.Velocity = new Vector2(entity.Velocity.X, 7f);
            }

            entity.OnGround = false;
            if (collisionhelper.CollisionTopOf(playerRec, newRectangle))
            {
                playerRec.Y      = newRectangle.Y - (playerRec.Height + 30);
                entity.Velocity  = new Vector2(entity.Velocity.X, 0f);
                entity.HasJumped = false;
                entity.OnGround  = true;
            }
        }
Beispiel #2
0
        public void Collision(Rectangle playerRec, Rectangle newRectangle, int xOffset, int yOffset)
        {
            //manager.Collision(playerRec, newRectangle, xOffset, yOffcet);
            //manager.setColRect(_collisionRectangle);

            if (collisionhelper.CollisionTopOf(playerRec, newRectangle))
            {
                _collisionRectangle.Y = newRectangle.Y - _collisionRectangle.Height;
                velocity.Y            = 0f;
                hasJumped             = false;
            }

            if (collisionhelper.CollisionLeftOf(playerRec, newRectangle))
            {
                Position = new Vector2(newRectangle.X - _collisionRectangle.Width - 2, Position.Y);
            }

            if (collisionhelper.CollisionRightOf(playerRec, newRectangle))
            {
                Position = new Vector2(newRectangle.X + _collisionRectangle.Width + 2, Position.Y);
            }

            if (collisionhelper.CollisionBottomOf(playerRec, newRectangle))
            {
                velocity.Y = 1f;
            }


            // Trap hero inside window borders
            if (Position.X < 0)
            {
                Position = new Vector2(0, Position.Y);
            }

            if (Position.X > xOffset - _collisionRectangle.Width)
            {
                Position = new Vector2(xOffset - _collisionRectangle.Width, Position.Y);
            }

            if (Position.Y < 0)
            {
                velocity.Y = 7.5f;
            }

            if (Position.Y > yOffset - _collisionRectangle.Height)
            {
                Position = new Vector2(Position.X, yOffset - _collisionRectangle.Height);
            }
        }
        public void Collision(Rectangle playerRec, Rectangle newRectangle, int xOffset, int yOffcet)
        {
            if (collisionhelper.CollisionTopOf(playerRec, newRectangle))
            {
                _collisionRectangle.Y = newRectangle.Y - _collisionRectangle.Height;
                velocity.Y            = 0f;
                HasJumed = false;
            }

            if (collisionhelper.CollisionLeftOf(playerRec, newRectangle))
            {
                Position = new Vector2(newRectangle.X - _collisionRectangle.Width - 2, Position.Y);
            }

            if (collisionhelper.CollisionRightOf(playerRec, newRectangle))
            {
                Position = new Vector2(newRectangle.X + _collisionRectangle.Width + 2, Position.Y);
            }

            if (collisionhelper.CollisionBottomOf(playerRec, newRectangle))
            {
                velocity.Y = 1f;
            }


            if (Position.X < 0)
            {
                Position = new Vector2(0, Position.Y);
            }

            else if (Position.X > xOffset - _collisionRectangle.Width)
            {
                Position = new Vector2(xOffset - _collisionRectangle.Width, Position.Y);
            }

            else if (Position.Y < 0)
            {
                velocity.Y = 16f;
            }

            else if (Position.Y > yOffcet - _collisionRectangle.Height)
            {
                Position = new Vector2(Position.X, yOffcet - _collisionRectangle.Height);
            }

            CollisionRectangle = _collisionRectangle;
        }