Пример #1
0
        private void CreateChildren()
        {
            double lDirection1 = Direction + 10 + 30 * mRandom.NextDouble();
            double lDirection2 = Direction - 10 - 30 * mRandom.NextDouble();

            List <Asteroid> lChildren = new List <Asteroid>();

            AsteroidSettings aChild1Settings = mSettings.Clone();

            aChild1Settings.Size = this.mSettings.Size / 2;
            AsteroidSettings aChild2Settings = mSettings.Clone();

            aChild2Settings.Size = this.mSettings.Size / 2;

            lChildren.Add(new Asteroid((BitmapFrame)Image.Source, mExplosionFrame,
                                       Position,
                                       lDirection1,
                                       1.1 * Speed,
                                       aChild1Settings));
            lChildren.Add(new Asteroid((BitmapFrame)Image.Source, mExplosionFrame,
                                       Position,
                                       lDirection2,
                                       1.1 * Speed,
                                       aChild2Settings));

            foreach (Asteroid a in lChildren)
            {
                RaiseRoomActionEvent(ERoomAction.AddObject, a);
            }
        }
Пример #2
0
        public Asteroid(BitmapFrame aBitmapFrame, BitmapFrame aExplosionFrame,
                        Point aPosition,
                        double aDirection, double aSpeed,
                        AsteroidSettings aSettings)
            : base(aSettings.Size, aSettings.Size, aBitmapFrame, aPosition, aDirection, aSpeed)
        {
            mHealth = 1;
            //Random lRandom = new Random();
            mAngle          = Direction;
            mExplosionFrame = aExplosionFrame;

            mCollisionBehavior.Add(typeof(Asteroid), CollisionWithAsteroid);
            mCollisionBehavior.Add(typeof(BasicProjectile), CollisionWithProjectile);
            mCollisionBehavior.Add(typeof(GuidedMissile), CollisionWithProjectile);
            mCollisionBehavior.Add(typeof(Rocket), DefaultCollisionSolve);

            InvincibleSteps = 20;

            mSettings = aSettings;

            double lRadius = mSettings.Size / 2 * 4.5 / 5;

            //Circle mask
            CollisionMask.Add(new Circle(lRadius, this.Position, 0, 0));
            //Line mask
            //CollisionMask.Add(new Ray(this.Position, -lRadius, 0, 2 * lRadius, 0));
            //CollisionMask.Add(new Ray(this.Position, -lRadius, 90, 2 * lRadius, 90));
            Depth = -1;
        }
Пример #3
0
        private Asteroid CreateAsteroid(AsteroidType aType)
        {
            double lAsteroidX = 0;
            double lAsteroidY = 0;
            double lDirection = 0;

            double lAsteroidSize = aType.MinSize + mRandom.NextDouble() * (aType.MaxSize - aType.MinSize);

            //left /right
            if (mRandom.Next(2) == 0)
            {
                lAsteroidY = mRandom.Next((int)GameRoom.RoomHeight);
                //left
                if (mRandom.Next(2) == 0)
                {
                    lAsteroidX = -lAsteroidSize / 2;
                    lDirection = -90 + mRandom.Next(181);
                }
                else//right
                {
                    lAsteroidX = (int)GameRoom.RoomWidth + lAsteroidSize / 2;
                    lDirection = 90 + mRandom.Next(181);
                }
            }
            else //top/bottom
            {
                lAsteroidX = mRandom.Next((int)GameRoom.RoomWidth);
                //top
                if (mRandom.Next(2) == 0)
                {
                    lAsteroidY = -lAsteroidSize / 2;
                    lDirection = mRandom.Next(181);
                }
                else //bottom
                {
                    lAsteroidY = (int)GameRoom.RoomHeight + lAsteroidSize / 2;
                    lDirection = 180 + mRandom.Next(181);
                }
            }

            double lRotationSpeed = (mRandom.NextDouble() - .5) * 2 * aType.MaxRotationSpeed;

            AsteroidSettings lSettings = new AsteroidSettings()
            {
                MinSizeForChildren = aType.MinSizeForChildren,
                MissileDamage      = aType.MissileDamage,
                ProjectileDamage   = aType.ProjectileDamage,
                Size             = lAsteroidSize,
                Strength         = aType.Strength,
                TypeName         = aType.TypeName,
                PointsMultiplier = aType.PointsMultiplier,
                RotationSpeed    = lRotationSpeed
            };

            double lSpeed = aType.MinSpeed + mRandom.NextDouble() * (aType.MaxSpeed - aType.MinSpeed);

            return(new Asteroid(aType.BitmapFrame, aType.ExplosionFrame,
                                new Point(lAsteroidX, lAsteroidY),
                                lDirection, lSpeed,
                                lSettings));
        }