Example #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="player"></param>
        public InUseState(MagicItem magicItem)
        {
            MagicItem = magicItem;
            MagicItem.Sprite.PlayAnimation(MagicItem.ItemType);

            //CollisionManager.ResolveEnemyCollisions(enemy, Enemy.EnemyBounds);

            //MagicItem.Velocity = new Vector2(2, 10);
        }
Example #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="player"></param>
        public InAirState(MagicItem magicItem)
        {
            MagicItem = magicItem;
            MagicItem.Sprite.PlayAnimation("base");

            //CollisionManager.ResolveEnemyCollisions(enemy, Enemy.EnemyBounds);
            if (GV.Player.Direction == "left")
                MagicItem.Velocity = new Vector2(-10, -20);
            else if (GV.Player.Direction == "right")
                MagicItem.Velocity = new Vector2(10, -20);
            //MagicItem.Velocity = new Vector2(2, 10);
        }
Example #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="player"></param>
        public InAirState(MagicItem magicItem)
        {
            MagicItem = magicItem;
            MagicItem.Sprite.PlayAnimation("base");
            GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
            MagicItem.Velocity = new Vector2(  gamePadState.ThumbSticks.Right.X * 10.0f, gamePadState.ThumbSticks.Right.Y * -20.0f);

            /*if (GV.Player.Direction == "left")
                MagicItem.Velocity = new Vector2(-10, -20);
            else if (GV.Player.Direction == "right")
                MagicItem.Velocity = new Vector2(10, -20);*/
        }
Example #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="player"></param>
        public FireState(MagicItem magicItem)
        {
            MagicItem = magicItem;
            MagicItem.Sprite.PlayAnimation("fireRow");

            //CollisionManager.ResolveEnemyCollisions(enemy, Enemy.EnemyBounds);
            if (MagicItem.Enemy.Direction == "left")
                MagicItem.Velocity = new Vector2(0, 0);
            else if (MagicItem.Enemy.Direction == "right")
                MagicItem.Velocity = new Vector2(0, 0);
            //MagicItem.Velocity = new Vector2(2, 10);
        }
Example #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="player"></param>
        public EggState(MagicItem magicItem)
        {
            Random random = new Random();
            randomx = random.Next(10, 30);
            randomy = random.Next(10, 20);

            MagicItem = magicItem;
            MagicItem.Sprite.PlayAnimation("light");
            MagicItem.IsOnGround = false;
            //CollisionManager.ResolveEnemyCollisions(enemy, Enemy.EnemyBounds);
            if (MagicItem.Enemy.Direction == "left")
                MagicItem.Velocity = new Vector2(-randomx, -randomy);
            else if (MagicItem.Enemy.Direction == "right")
                MagicItem.Velocity = new Vector2(randomx, -randomy);
        }
Example #6
0
        public static Vector2 ResolveMagicStaticCollisions(MagicItem item, Vector2 nextPosition, Vector2 vel, List<MagicItem> magicItemList)
        {
            float xVel = vel.X, yVel = vel.Y;

            if (vel.Y >= 32)
                yVel = 31;
            if (Math.Abs(vel.X) > 32)
            {
                if (vel.X < 0)
                    vel.X = -31;
                else
                    vel.X = 31;
            }

            // Get the player's bounding rectangle and find neighboring tiles.

            Rectangle nextBounds = item.getBounds(nextPosition);
            //Rectangle pBounds = GV.Player.Bounds;
            int leftTile = (int)Math.Floor((float)nextBounds.Left / Layer.TileWidth);
            int rightTile = (int)Math.Ceiling(((float)nextBounds.Right / Layer.TileWidth)) - 1;
            int topTile = (int)Math.Floor((float)nextBounds.Top / Layer.TileHeight);
            int bottomTile = (int)Math.Ceiling(((float)nextBounds.Bottom / Layer.TileHeight)) - 1;

            // Reset flag to search for ground collision.
            item.IsOnGround = false;

            bool BottomCollision = false;
            bool LeftCollision = false;
            bool TopCollision = false;

            bool XCollision = false;
            Rectangle tileBounds;
            Vector2 depth1 = new Vector2(0.0f, 0.0f);
            Vector2 depth2 = new Vector2(0.0f, 0.0f);
            //depth2 = new Vector2(0.0f, 0.0f);
            if (vel.Y < 0)
            {
                if (!item.IsOnGround)
                {
                    for (int x = leftTile; x <= rightTile; ++x)
                    {
                        int collision = GV.Level.GetCollision(x, topTile);
                        if (collision == Layer.Impassable)
                        {
                            TopCollision = true;
                        }

                    }
                }
            }
            // For each potentially colliding tile,
            for (int y = topTile; y < bottomTile; ++y)
            {

                int lCollision = GV.Level.GetCollision(leftTile, y);
                if (lCollision == Layer.Impassable)
                {
                    LeftCollision = true;
                    XCollision = true;
                }
                int rCollision = GV.Level.GetCollision(rightTile, y);

                if (rCollision == Layer.Impassable)
                {
                    XCollision = true;
                }
            }

            if (XCollision && item.State.GetType().ToString() != "KismetDataTypes.InUseState")
            {
                if (LeftCollision)
                {
                    tileBounds = GV.Level.GetBounds(leftTile, bottomTile);
                }
                else
                {
                    tileBounds = GV.Level.GetBounds(rightTile, bottomTile);
                }
                depth2 = RectangleExtensions.GetIntersectionDepth(nextBounds, tileBounds);

                xVel = vel.X + depth2.X;

                nextBounds = new Rectangle(nextBounds.X + (int)depth2.X, nextBounds.Y, nextBounds.Width, nextBounds.Height);
                leftTile = (int)Math.Floor((float)nextBounds.Left / Layer.TileWidth);
                rightTile = (int)Math.Ceiling(((float)nextBounds.Right / Layer.TileWidth)) - 1;
                topTile = (int)Math.Floor((float)nextBounds.Top / Layer.TileHeight);
                bottomTile = (int)Math.Ceiling(((float)nextBounds.Bottom / Layer.TileHeight)) - 1;
                if (item.State.GetType().ToString() == "KismetDataTypes.ArrowState")
                    item.Active = false;
            }

            if (TopCollision)
            {
                tileBounds = GV.Level.GetBounds(leftTile, topTile);
                depth1 = RectangleExtensions.GetIntersectionDepth(nextBounds, tileBounds);
                float absDepthY = Math.Abs(depth1.Y);
                float absDepthX = Math.Abs(depth1.X);

                yVel = 0;// vel.Y + absDepthY;

                nextBounds = new Rectangle(nextBounds.X, nextBounds.Y + (int)depth1.Y, nextBounds.Width, nextBounds.Height);
                xVel = 0;
            }

            if (vel.Y > 0)
            {
                for (int x = leftTile; x <= rightTile; ++x)
                {
                    int collision = GV.Level.GetCollision(x, bottomTile);
                    if (collision != Layer.Passable && item.ItemType != "arrow")
                    {
                        BottomCollision = true;
                    }

                }
            }
            if (BottomCollision)
            {
                tileBounds = GV.Level.GetBounds(leftTile, bottomTile);
                depth1 = RectangleExtensions.GetIntersectionDepth(nextBounds, tileBounds);
                float absDepthY = Math.Abs(depth1.Y);
                float absDepthX = Math.Abs(depth1.X);
                if (item.PreviousBottom <= tileBounds.Top)
                    yVel = vel.Y + depth1.Y;

               item.IsOnGround = true;

            }
            return new Vector2(xVel, yVel);
        }