/**
        **********************************************************************************************

        **********************************************************************************************
        **/
        public void addRocket(Rocket rocket)
        {
            try
            {

                if (firstRocket == null)
                {
                    firstRocket = rocket;
                    lastRocket = rocket;
                }
                else if (firstRocket == lastRocket)
                {
                    firstRocket.setNextRocket(rocket);
                    lastRocket = rocket;
                }
                else
                {
                    lastRocket.setNextRocket(rocket);
                    lastRocket = rocket;
                }

            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 2
0
        private void Init()
        {
            //Resize the Image Control
            int w = (int)canvas1.ActualWidth + 2;
            int h = (int)canvas1.ActualHeight + 2;

            Image1.Width   = w;
            Image1.Height  = h;
            Image1.Stretch = Stretch.Fill;
            //Make a writeable bitmap the size of the Image control
            Writebitmap  = new WriteableBitmap(w + 1, h + 1, 96, 96, PixelFormats.Bgra32, null);
            Stride       = (int)(Writebitmap.PixelWidth * Writebitmap.Format.BitsPerPixel / 8);
            PixelData    = new byte[Stride * Writebitmap.PixelHeight];
            myFireworks  = new Rocket[RocketCount];
            my_Particles = new List <Particle>();
            gravity      = new Vector(0, 0.02);
            for (int I = 0; I < RocketCount; I++)
            {
                myFireworks[I] = new Rocket();
            }
            Rendering();
        }
Ejemplo n.º 3
0
        private void UpdateTrail(Rocket rocket)
        {
            rocket.Trail.ForEach(p => {
                p.Age += Timer.DeltaTimeMilliseconds;
            });
            rocket.Trail.RemoveAll(p => p.IsDead);
            rocket.TrailTimeSinceLastEmit += Timer.DeltaTimeMilliseconds;

            if (rocket.HasFuel && rocket.TrailTimeSinceLastEmit >= rocket.TrailEmitTime)
            {
                rocket.TrailTimeSinceLastEmit = 0;
                rocket.Trail.Add(new Particle
                {
                    Position      = rocket.Position,
                    TotalLifetime = 150,
                    Mass          = 1f,
                    R             = 255,
                    G             = 165,
                    B             = 74
                });
            }
        }
        /**
        **********************************************************************************************

        **********************************************************************************************
        **/
        public void addRandomRocket()
        {
            try
            {

                int width = _canvas.Width;
                int height = _canvas.Height;

                int widthDivision = 100;
                int widthInner = width - (widthDivision * 2);
                int height4 = (int)(height / 4);

                double angle = (_rng.NextDouble() * 30.0d) + 75.0d; ;
                double speed = (_rng.NextDouble() * 45.0) + (double)height4;
                double explode = (_rng.NextDouble() * 2.0) + 1.5d;

                int xPos = (int)(widthDivision + ((double)_rng.NextDouble() * widthInner));
                int yPos = height;
                Point position = new Point(xPos, yPos);

                Rocket rocket = new Rocket(_rng, angle, speed);
                rocket.setExplodeTime(explode);
                rocket.setPosition(position);

                //double sparkLifespan = 1.5;
                //rocket.setSparkLifespan(sparkLifespan);

                //rocket.setColor(Color.FromArgb(213, 141, 27));
                rocket.setColor(Color.WhiteSmoke);

                addRocket(rocket);

            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 5
0
 private bool IntersectsWithEarth(Rocket rocket)
 {
     return((rocket.Position - _game.Earth.Position).Length() <= _game.Earth.Radius);
 }
Ejemplo n.º 6
0
 private void UpdateAge(Rocket rocket)
 {
     rocket.Age += Timer.DeltaTimeMilliseconds;
 }
Ejemplo n.º 7
0
 private void UseFuel(Rocket rocket)
 {
     rocket.Fuel = Math.Max(0f, rocket.Fuel - (200 * Timer.DeltaTimeSeconds)); // fuel lasts 1 sec
 }
Ejemplo n.º 8
0
 public void setNextRocket(Rocket nextRocket)
 {
     this.nextRocket = nextRocket;
 }
Ejemplo n.º 9
0
        /**
        **********************************************************************************************

        **********************************************************************************************
        **/
        public void checkExplode(RocketQueue rocketQueue)
        {
            try
            {

                if (lastRocket || exploded || dead)
                {
                    return;
                }

                if (time >= explodeTime)
                {

                    int[] numSparkChoice = new int[] { 5, 8, 10 };

                    int numSparks = numSparkChoice[_rng.Next(0, 2)];

                    //int numSparks = 20;
                    //System.out.println(numSparks);

                    double rotation = (360 / numSparks);
                    double sparkAngle = 5;
                    double sparkSpeed = _rng.NextDouble() * 20 + 10 ;
                    double lifespan = 2.0;
                    double sparkLifespan = 1.5;
                    int sparkSize = 2;

                    Color randomColor = makeRandomColor();

                    for (int i = 0; i < numSparks; i++)
                    {
                        Rocket rocket = new Rocket(_rng, sparkAngle, sparkSpeed);
                        rocket.setPosition(calculatePosition());
                        rocket.setSparkLifespan(sparkLifespan);
                        rocket.setLifespan(lifespan);
                        rocket.setLastRocket(true);
                        rocket.setColor(randomColor);
                        rocket.setSize(sparkSize);

                        rocketQueue.addRocket(rocket);

                        sparkAngle += rotation;
                    }

                    exploded = true;
                    dead = true;

                }

            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 10
0
        /**
        **********************************************************************************************

        **********************************************************************************************
        **/
        public void makeSparks(SparkQueue sparkQueue)
        {
            try
            {

                if (firstRocket == null)
                {
                    return;
                }
                else if (firstRocket.getNextRocket() == null && firstRocket.isDead())
                {
                    firstRocket = null;
                    lastRocket = null;
                    return;
                }

                Rocket rocket = firstRocket;
                bool hasMoreRockets = true;
                while (hasMoreRockets)
                {

                    // if the rocket is ready to explode, add the new rockets
                    // to the end of the queue for painting
                    rocket.checkExplode(this);
                    rocket.makeSparks(sparkQueue);

                    // loop until we find the next alive rocket, clipping out the finished rockets
                    Rocket nextRocket = rocket.getNextRocket();
                    bool finished = false;
                    while (!finished)
                    {
                        if (nextRocket == null)
                        {
                            // the end of the queue
                            rocket.setNextRocket(null);
                            lastRocket = rocket;
                            hasMoreRockets = false;
                            finished = true;
                        }
                        else if (nextRocket.isDead())
                        {
                            nextRocket = nextRocket.getNextRocket();
                        }
                        else
                        {
                            rocket.setNextRocket(nextRocket);
                            rocket = nextRocket;
                            finished = true;
                        }
                    }

                    // This must be done at the end of the loop incase the last
                    // rocket explodes and adds more rockets to the queue
                    if (rocket == lastRocket)
                    {
                        //hasMoreRockets = false;
                    }

                }

            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 11
0
 public void Clear()
 {
     firstRocket = lastRocket = null;
 }