Exemplo n.º 1
0
 protected bool IsTouchingRight(Object2D obj)
 {
     return(this.BoundingBox.Left + this.Velocity.X < obj.BoundingBox.Right &&
            this.BoundingBox.Right > obj.BoundingBox.Right &&
            this.BoundingBox.Bottom > obj.BoundingBox.Top &&
            this.BoundingBox.Top < obj.BoundingBox.Bottom);
 }
Exemplo n.º 2
0
 protected bool IsTouchingTop(Object2D obj)
 {
     return(this.BoundingBox.Top + this.Velocity.Y < obj.BoundingBox.Bottom &&
            this.BoundingBox.Bottom > obj.BoundingBox.Bottom &&
            this.BoundingBox.Right > obj.BoundingBox.Left &&
            this.BoundingBox.Left < obj.BoundingBox.Right);
 }
Exemplo n.º 3
0
        public bool Colliding(Object2D obj)
        {
            bool col = false;

            if (BoundingBox.Intersects(obj.BoundingBox))
            {
                col = true;
            }

            return(col);
        }
Exemplo n.º 4
0
        private bool CheckCollision(Object2D player, List <Object2D> objects)
        {
            bool jump  = false;
            bool floor = true;


            foreach (var obj in objects)
            {
                if (obj != null)
                {
                    if ((Velocity.X > 0 && this.IsTouchingLeft(obj)) ||
                        (Velocity.X < 0 && this.IsTouchingRight(obj)))
                    {
                        if (obj.Texture.Name == "Box")
                        {
                            MovableObject movableObj = (MovableObject)obj;
                            if (movableObj.CheckCollision(objects))
                            {
                                Velocity.X = 0;
                            }
                            else
                            {
                                Velocity.X = (int)(Velocity.X * .5);
                                movableObj.Update(Velocity.X, objects);
                            }
                        }
                        else
                        {
                            Velocity.X = 0;
                        }


                        if (obj.Texture.Name == "Exit")
                        {
                            reachedExit = true;
                        }
                        if (obj.Texture.Name == "Fireball")
                        {
                            alive = false;
                            soundEffects["fireball"].CreateInstance().Play();
                        }

                        if (obj.Texture.Name == "Cerberus")
                        {
                            alive = false;
                        }
                        if (obj.Texture.Name == "Jump")
                        {
                            jumpPower = true;
                        }
                    }

                    if ((Velocity.Y >= 0 && this.IsTouchingBottom(obj)) ||
                        (Velocity.Y <= 0 && this.IsTouchingTop(obj)))
                    {
                        if (this.IsTouchingBottom(obj))
                        {
                            floor           = false;
                            hasDoubleJumped = true;
                        }

                        Velocity.Y = 0;

                        if (obj.Texture.Name == "Exit")
                        {
                            reachedExit = true;
                        }
                        if (obj.Texture.Name == "Fireball")
                        {
                            alive = false;
                            soundEffects["fireball"].CreateInstance().Play();
                        }
                        if (obj.Texture.Name == "Cerberus")
                        {
                            alive = false;
                        }
                        if (obj.Texture.Name == "Jump")
                        {
                            jumpPower = true;
                        }
                    }

                    if (!this.IsTouchingBottom(obj))
                    {
                        jump = true;
                    }
                }
            }

            if (!floor)
            {
                return(floor);
            }
            else
            {
                return(jump);
            }
        }