Exemplo n.º 1
0
 /// <summary>
 /// This function generates a new array of sprites to attach to the emitter.
 /// </summary>
 /// <param name="graphics">If you opted to not pre-configure an array of FlxSprite objects, you can simply pass in a particle image or sprite sheet.</param>
 /// <param name="quantity">The number of particles to generate when using the "create from image" option.</param>
 /// <param name="Multiple">Whether the image in the graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!).</param>
 /// <param name="Collide">Whether the particles should be flagged as not 'dead' (non-colliding particles are higher performance).  0 means no collisions, 0-1 controls scale of particle's bounding box.</param>
 /// <param name="Bounce">Whether the particles should bounce after colliding with things.  0 means no bounce, 1 means full reflection.</param>
 /// <returns>his FlxEmitter instance (nice for chaining stuff together, if you're into that).</returns>
 public FlxEmitter CreateSprites(Texture2D graphics, int quantity, bool Multiple, float Collide, float Bounce)
 {
     members = new List<FlxObject>();
     int r;
     FlxSprite s;
     int tf = 1;
     float sw;
     float sh;
     if(Multiple)
     {
         s = new FlxSprite();
         s.LoadGraphic(graphics,true);
         tf = s.frames;
     }
     int i = 0;
     while(i < quantity)
     {
         if((Collide > 0) && (Bounce > 0))
             s = new FlxParticle(Bounce) as FlxSprite;
         else
             s = new FlxSprite();
         if(Multiple)
         {
             r = (int)(FlxU.random()*tf);
             //if(BakedRotations > 0)
             //    s.loadRotatedGraphic(graphics,BakedRotations,r);
             //else
             //{
             s.LoadGraphic(graphics,true);
             s.frame = r;
             //}
         }
         else
         {
             //if(BakedRotations > 0)
             //    s.loadRotatedGraphic(graphics,BakedRotations);
             //else
             s.LoadGraphic(graphics);
         }
         if(Collide > 0)
         {
             sw = s.Width;
             sh = s.Height;
             s.Width = (int)(s.Width * Collide);
             s.Height = (int)(s.Height * Collide);
             s.offset.X = (int)(sw-s.Width)/2;
             s.offset.Y = (int)(sh-s.Height)/2;
             s.Solid = true;
         }
         else
             s.Solid = false;
         s.Exists = false;
         s.scrollFactor = scrollFactor;
         Add(s);
         i++;
     }
     return this;
 }
Exemplo n.º 2
0
        protected override void Create()
        {
            Reg.PS = this;
            //DebugDraw = false;

            Add(new FlxSprite(0, 0, "bg"));

            _scoreDisplay           = new FlxText(0, 180, FlxG.Width);
            _scoreDisplay.Alignment = FlxTextAlign.CENTER;
            _scoreDisplay.Color     = new Color(134, 134, 150);
            Add(_scoreDisplay);
            _scoreDisplay.Text = "Press Space to Start";

            Reg.HighScore = LoadScore();

            _highScore           = new FlxText(0, 40, FlxG.Width);
            _highScore.Alignment = FlxTextAlign.CENTER;
            _highScore.Color     = new Color(134, 134, 150);
            Add(_highScore);

            if (Reg.HighScore > 0)
            {
                _highScore.Text = Reg.HighScore.ToString();
            }

            _bounceLeft = new FlxSprite(1, 17);
            _bounceLeft.LoadGraphic(Reg.GetBounceImage(FlxG.Height - 34), true, 4, FlxG.Height - 34);
            _bounceLeft.Animation.Add("flash", new int[] { 1, 0 }, 8, false);
            Add(_bounceLeft);

            _bounceRight = new FlxSprite(FlxG.Width - 5, 17);
            _bounceRight.LoadGraphic(Reg.GetBounceImage(FlxG.Height - 34), true, 4, FlxG.Height - 34);
            _bounceRight.Animation.Add("flash", new int[] { 1, 0 }, 8, false);
            Add(_bounceRight);

            _paddleLeft = new Paddle(6, 1);
            Add(_paddleLeft);

            _paddleRight = new Paddle(FlxG.Width - 15, 0);
            Add(_paddleRight);

            _spikeBottom   = new FlxSprite(0, 0, "spike");
            _spikeBottom.Y = FlxG.Height - _spikeBottom.Height;
            Add(_spikeBottom);

            _spriteTop          = new FlxSprite(0, 0, "spike");
            _spriteTop.Rotation = MathHelper.ToRadians(180);
            _spriteTop.Y        = 0;
            Add(_spriteTop);

            _player = new Player();
            Add(_player);


            _feathers = new FlxEmitter();
            _feathers.Scale.Set(2, 2);
            _feathers.KeepScaleRatio = true;
            _feathers.LoadParticles("feather", 50);
            _feathers.Velocity.Set(-10, -10, 10, 10);
            _feathers.Acceleration.Set(0, 10);
            Add(_feathers);
        }