Exemplo n.º 1
0
        /// <summary>
        /// Method for resolving collisions with given Item
        /// </summary>
        /// <param name="Item">Item that has collided with this</param>
        public override void CollisionResolution(GameObject Item)
        {
            if (Item.GetType() == typeof(MazeBlock))
            {
                return;
            }
            if (Item.GetType() == typeof(Avatar))
            {
                if (!Walkable)
                {
                    float margin = (float)Math.Ceiling(Avatar.Instance().speed) + 1;
                    //Down
                    if (Item.kinetics.boundingBox.Bottom >= kinetics.boundingBox.Top && Item.kinetics.boundingBox.Bottom <= kinetics.boundingBox.Top + margin)
                    {
                        if (ControllerInput.Instance().GetKey(Microsoft.Xna.Framework.Input.Keys.Space).Pressed)
                        {
                            MazeBlock target = Down;
                            if (target.Walkable == true)
                            {
                                Item.kinetics.position.X = target.kinetics.position.X + 10;
                                Item.kinetics.position.Y = target.kinetics.position.Y - 25;

                                Item.kinetics.boundingBox.X = (int)target.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X;
                                Item.kinetics.boundingBox.Y = (int)target.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y;
                                Avatar.Instance().Teleported();
                            }
                        }
                        else
                        {
                            float offset = Item.kinetics.boundingBox.Top - Item.kinetics.position.Y;
                            Item.kinetics.position.Y    = kinetics.boundingBox.Top - Item.kinetics.boundingBox.Height - Item.kinetics.BoundingBoxOffset.Y;
                            Item.kinetics.boundingBox.Y = (int)(Item.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y);
                        }
                        return;
                    }

                    //Left
                    if (Item.kinetics.boundingBox.Right >= kinetics.boundingBox.Left && Item.kinetics.boundingBox.Right <= kinetics.boundingBox.Left + margin)
                    {
                        if (ControllerInput.Instance().GetKey(Microsoft.Xna.Framework.Input.Keys.Space).Pressed)
                        {
                            MazeBlock target = Right;
                            if (target.Walkable == true)
                            {
                                Item.kinetics.position.X = target.kinetics.position.X + 10;
                                Item.kinetics.position.Y = target.kinetics.position.Y - 25;

                                Item.kinetics.boundingBox.X = (int)target.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X;
                                Item.kinetics.boundingBox.Y = (int)target.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y;
                                Avatar.Instance().Teleported();
                            }
                        }
                        else
                        {
                            Item.kinetics.position.X    = kinetics.boundingBox.Left - Item.kinetics.boundingBox.Width - Item.kinetics.BoundingBoxOffset.X;
                            Item.kinetics.boundingBox.X = (int)(Item.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X);
                            return;
                        }
                    }

                    if (Item.kinetics.boundingBox.Left <= kinetics.boundingBox.Right && Item.kinetics.boundingBox.Left >= kinetics.boundingBox.Right - margin)
                    {
                        if (Item.kinetics.boundingBox.Top <= kinetics.boundingBox.Bottom && Item.kinetics.boundingBox.Top >= kinetics.boundingBox.Bottom - margin)
                        {
                            if (Right != null)
                            {
                                if (!Right.Walkable)
                                {
                                    if (ControllerInput.Instance().GetKey(Microsoft.Xna.Framework.Input.Keys.Space).Pressed)
                                    {
                                        MazeBlock target = Up;
                                        if (target.Walkable == true)
                                        {
                                            Item.kinetics.position.X = target.kinetics.position.X + 10;
                                            Item.kinetics.position.Y = target.kinetics.position.Y - 25;

                                            Item.kinetics.boundingBox.X = (int)target.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X;
                                            Item.kinetics.boundingBox.Y = (int)target.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y;
                                            Avatar.Instance().Teleported();
                                        }
                                    }
                                    else
                                    {
                                        float offset = Item.kinetics.boundingBox.Top - Item.kinetics.position.Y;
                                        Item.kinetics.position.Y    = kinetics.boundingBox.Bottom - Item.kinetics.BoundingBoxOffset.Y;
                                        Item.kinetics.boundingBox.Y = (int)(Item.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y);
                                        Item.kinetics.velocity.Y    = 0;
                                        return;
                                    }
                                }
                            }
                        }

                        if (ControllerInput.Instance().GetKey(Microsoft.Xna.Framework.Input.Keys.Space).Pressed)
                        {
                            MazeBlock target = Left;
                            if (target.Walkable == true)
                            {
                                Item.kinetics.position.X = target.kinetics.position.X + 10;
                                Item.kinetics.position.Y = target.kinetics.position.Y - 25;

                                Item.kinetics.boundingBox.X = (int)target.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X;
                                Item.kinetics.boundingBox.Y = (int)target.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y;
                                Avatar.Instance().Teleported();
                            }
                        }
                        else
                        {
                            Item.kinetics.position.X    = kinetics.boundingBox.Right - Item.kinetics.BoundingBoxOffset.X;
                            Item.kinetics.boundingBox.X = (int)(Item.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X);
                        }
                        return;
                    }

                    if (Item.kinetics.boundingBox.Top <= kinetics.boundingBox.Bottom && Item.kinetics.boundingBox.Top >= kinetics.boundingBox.Bottom - margin)
                    {
                        if (ControllerInput.Instance().GetKey(Microsoft.Xna.Framework.Input.Keys.Space).Pressed)
                        {
                            MazeBlock target = Up;
                            if (target.Walkable == true)
                            {
                                Item.kinetics.position.X = target.kinetics.position.X + 10;
                                Item.kinetics.position.Y = target.kinetics.position.Y - 25;

                                Item.kinetics.boundingBox.X = (int)target.kinetics.position.X + Item.kinetics.BoundingBoxOffset.X;
                                Item.kinetics.boundingBox.Y = (int)target.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y;
                                Avatar.Instance().Teleported();
                            }
                        }
                        else
                        {
                            float offset = Item.kinetics.boundingBox.Top - Item.kinetics.position.Y;
                            Item.kinetics.position.Y    = kinetics.boundingBox.Bottom - Item.kinetics.BoundingBoxOffset.Y;
                            Item.kinetics.boundingBox.Y = (int)(Item.kinetics.position.Y + Item.kinetics.BoundingBoxOffset.Y);
                            Item.kinetics.velocity.Y    = 0;
                        }
                        return;
                    }
                }
                else
                {
                    if (!discovered)
                    {
                        LevelManager.Instance().Discovered();
                        color = Color.White;
                    }
                    discovered = true;
                }
            }
        }