Example #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="player"></param>
        public InActiveState(PickUpItem pickUpItem)
        {
            PickUpItem = pickUpItem;
            PickUpItem.Sprite.PlayAnimation(PickUpItem.ItemType);
            PickUpItem.Velocity = new Vector2(0, 0);

            //MagicItem.Velocity = new Vector2(2, 10);
        }
Example #2
0
        public static Vector2 ResolvePickUpStaticCollisions(PickUpItem item, Vector2 nextPosition, Vector2 vel)
        {
            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 XCollision = false;
            Rectangle tileBounds;
            Vector2 depth1 = new Vector2(0.0f, 0.0f);
            Vector2 depth2 = new Vector2(0.0f, 0.0f);

            // 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 (vel.Y > 0)
            {
                for (int x = leftTile; x <= rightTile; ++x)
                {
                    int collision = GV.Level.GetCollision(x, bottomTile);
                    if (collision != Layer.Passable)
                    {
                        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);
        }
Example #3
0
        /// <summary>
        /// Checks to see if an item is lit by the lights in the level
        /// </summary>
        /// <param name="item">The item being checked</param>
        /// <param name="min">The number of lights being checked</param>
        private static bool IsLitByStaticLighting(PickUpItem item, int min)
        {
            Vector2 position = new Vector2(item.Position.X - item.Bounds.Width - 16, item.Position.Y - (item.Bounds.Height / 3));
            LightSource[] lights = GV.Level.Lights;

            for (int i = 0; i < min; i += 1)
            {
                Vector2 pVector = position - lights[i].Centre;
                double distance = Math.Sqrt((Math.Pow((pVector.X), 2) + Math.Pow((pVector.Y), 2)));
                pVector.Normalize();
                Vector2 normalisedDirection = lights[i].Direction;
                normalisedDirection.Normalize();
                float angle = Vector2.Dot(normalisedDirection, pVector);
                if (angle >= lights[i].IlluminationAngle && (float)distance <= lights[i].Radius)
                {
                    return true;
                }
            }

            return false;
        }
Example #4
0
        /// <summary>
        /// Checks to see if an item is lit by the light spell
        /// </summary>
        /// <param name="item">The item being checked</param>
        /// <param name="min">The number of lights being checked</param>
        private static bool IsLitByMagic(PickUpItem item, int min)
        {
            Vector2 position = new Vector2(item.Position.X - item.Bounds.Width - 16, item.Position.Y - (item.Bounds.Height / 3));
            Vector2[] lightSpells = MagicItemManager.GetLightMagicArray(min);

            for (int i = 0; i < min; i += 1)
            {
                Vector2 pVector = position - lightSpells[i];
                float distance = (float)Math.Sqrt((Math.Pow((pVector.X), 2) + Math.Pow((pVector.Y), 2)));
                if (distance <= 200)
                {
                    return true;
                }
            }

            return false;
        }