Beispiel #1
0
        /// <summary>
        /// Creates a meteor entity with a random position, direction, linear and rotation velocity.
        /// </summary>
        /// <param name="type">Type of the meteor.</param>
        /// <param name="inject">Whether the meteor should be injected into the entity manager.</param>
        /// <returns>Th new meteor entity.</returns>
        public Meteor CreateMeteor(MeteorType type, bool inject)
        {
            Vector2 randomPosition  = new Vector2(_random.Next(0, _gameSize.ScreenWidth), _random.Next(0, _gameSize.ScreenHeight));
            Vector2 randomDirection = VectorHelper.AngleToVector((float)(_random.NextDouble() * Math.PI * 2));

            return(CreateMeteor(type, randomPosition, randomDirection, inject));
        }
Beispiel #2
0
        /// <summary>
        /// Splits a meteor entity into 2 smaller meteors entities.
        /// </summary>
        /// <param name="meteor">The meteor that has to be split.</param>
        /// <param name="inject">Whether the smaller meteors should be injected into the entity manager.</param>
        public List <Meteor> SplitMeteor(Meteor meteor, bool inject)
        {
            if (meteor is TinyMeteor)
            {
                throw new InvalidOperationException("Can't split a meteor of type TinyMeteor");
            }

            List <Meteor> newMeteors = new List <Meteor>();

            float   currentDirection = VectorHelper.VectorToAngle(meteor.Direction);
            Vector2 newDirection     = Vector2.Zero;

            for (int i = 0; i < 2; i++)
            {
                if (i == 0)
                {
                    newDirection = VectorHelper.AngleToVector(currentDirection + (float)(Math.PI / 2));
                }
                else
                {
                    newDirection = VectorHelper.AngleToVector(currentDirection - (float)(Math.PI / 2));
                }

                if (meteor is SmallMeteor)
                {
                    newMeteors.Add(CreateMeteor(MeteorType.TINY, meteor.Position, newDirection, inject));
                }
                if (meteor is MediumMeteor)
                {
                    newMeteors.Add(CreateMeteor(MeteorType.SMALL, meteor.Position, newDirection, inject));
                }
                if (meteor is BigMeteor)
                {
                    newMeteors.Add(CreateMeteor(MeteorType.MEDIUM, meteor.Position, newDirection, inject));
                }
            }

            return(newMeteors);
        }