예제 #1
0
        public override void update()
        {
            if (_complex)
            {
                Alpha = (.3f + .7f * Y / FlxG.height);
            }

            if ((X + Width) >= FlxG.width)
            {
                Velocity.X *= -1;
                X           = FlxG.width - Width;
            }
            else if (X <= 0)
            {
                Velocity.X *= -1;
                X           = 0;
            }

            if ((Y + Height) >= FlxG.height)
            {
                Velocity.Y *= -0.8f;
                Y           = FlxG.height - Height;

                if (FlxG.random() > 0.5f)
                {
                    Velocity.Y -= 3 + FlxG.random() * 4;
                }
            }
            else if (Y <= 0)
            {
                Velocity.Y *= -0.8f;
                Y           = 0;
            }
        }
예제 #2
0
        /// <summary>
        /// This function can be used both internally and externally to emit the next particle.
        /// </summary>
        public void emitParticle()
        {
            var particle = recycle(typeof(FlxBasic)) as FlxParticle;

            if (particle == null)
            {
                throw new Exception("RecyclingWTFException");
            }

            particle.Lifespan   = lifespan;
            particle.Elasticity = bounce;
            particle.reset(X - ((int)particle.Width >> 1) + FlxG.random() * Width, Y - ((int)particle.Height >> 1) + FlxG.random() * Height);
            particle.Visible = true;

            // jlorek: revisit

            if (minParticleSpeed.X != maxParticleSpeed.X)
            {
                particle.Velocity.X = minParticleSpeed.X + FlxG.random() * (maxParticleSpeed.X - minParticleSpeed.X);
            }
            else
            {
                particle.Velocity.X = minParticleSpeed.X;
            }

            if (minParticleSpeed.Y != maxParticleSpeed.Y)
            {
                particle.Velocity.Y = minParticleSpeed.Y + FlxG.random() * (maxParticleSpeed.Y - minParticleSpeed.Y);
            }
            else
            {
                particle.Velocity.Y = minParticleSpeed.Y;
            }

            particle.Acceleration.Y = gravity;

            if (minRotation != maxRotation)
            {
                particle.AngularVelocity = minRotation + FlxG.random() * (maxRotation - minRotation);
            }
            else
            {
                particle.AngularVelocity = minRotation;
            }

            if (particle.AngularVelocity != 0)
            {
                particle.Angle = FlxG.random() * 360 - 180;
            }

            particle.Visible = true;
            particle.Drag.X  = particleDrag.X;
            particle.Drag.Y  = particleDrag.Y;
            particle.onEmit();
        }
예제 #3
0
        public Bunny(float x, float y) : base(x, y)
        {
            loadGraphic(ImgBunny, false, false, 26, 37);
            float speedMultiplier = 50f;

            Velocity.X      = speedMultiplier * (FlxG.random() * 5f) * (FlxG.random() < 0.5f ? 1f : -1f);
            Velocity.Y      = speedMultiplier * ((FlxG.random() * 5f) - 2.5f) * (FlxG.random() < 0.5f ? 1f : -1f);
            Acceleration.Y  = 5;
            Angle           = 15 - FlxG.random() * 30;
            AngularVelocity = 30f * (FlxG.random() * 5f) * (FlxG.random() < 0.5f ? 1f : -1f);
            Elasticity      = 1;
        }
예제 #4
0
 public void setComplex(Boolean complex)
 {
     _complex = complex;
     if (_complex)
     {
         Scale.X = Scale.Y = .3f + FlxG.random();
     }
     else
     {
         Scale.X = Scale.Y = 1f;
         Alpha   = 1f;
     }
 }
        public void addBunnies()
        {
            float rx;
            float ry;

            for (int i = 0; i < 500; i++)
            {
                rx = FlxG.random() * (FlxG.width - 26);
                ry = FlxG.random() * (FlxG.height - 37);
                _bunnies.add((FlxBasic) new Bunny(rx, ry));
            }
            _bunnyCounter.text = "Bunnies: " + _bunnies.length;
        }
예제 #6
0
        public Spawner(int x, int y, FlxEmitter Gibs, FlxGroup Bots, FlxGroup BotBullets, FlxEmitter BotGibs, Player ThePlayer) : base(x, y)
        {
            loadGraphic(ImgSpawner, true);
            _gibs       = Gibs;
            _bots       = Bots;
            _botBullets = BotBullets;
            _botGibs    = BotGibs;
            _player     = ThePlayer;
            _timer      = FlxG.random() * 20;
            _open       = false;
            Health      = 8;

            addAnimation("open", new int[] { 1, 2, 3, 4, 5 }, 40, false);
            addAnimation("close", new int[] { 4, 3, 2, 1, 0 }, 40, false);
            addAnimation("dead", new int[] { 6 });

            _sfxExplode  = new FlxSound().loadEmbedded(SndExplode, false, false);
            _sfxExplode2 = new FlxSound().loadEmbedded(SndExplode2, false, false);
            _sfxHit      = new FlxSound().loadEmbedded(SndHit, false, false);
        }
        //Just plops down a spawner and some blocks - haphazard and crappy atm but functional!
        protected void buildRoom(int RX, int RY, bool Spawners)
        {
            //first place the spawn point (if necessary)
            int rw = 20;
            int sx = 0;
            int sy = 0;

            if (Spawners)
            {
                sx = (int)(2 + FlxG.random() * (rw - 7));
                sy = (int)(2 + FlxG.random() * (rw - 7));
            }

            //then place a bunch of blocks
            int numBlocks = (int)(3 + FlxG.random() * 4);

            if (!Spawners)
            {
                numBlocks++;
            }
            int  maxW = 10;
            int  minW = 2;
            int  maxH = 8;
            int  minH = 1;
            int  bx;
            int  by;
            int  bw;
            int  bh;
            bool check;

            for (int i = 0; i < numBlocks; i++)
            {
                do
                {
                    //keep generating different specs if they overlap the spawner
                    bw = (int)(minW + FlxG.random() * (maxW - minW));
                    bh = (int)(minH + FlxG.random() * (maxH - minH));
                    bx = (int)(-1 + FlxG.random() * (rw + 1 - bw));
                    by = (int)(-1 + FlxG.random() * (rw + 1 - bh));
                    if (Spawners)
                    {
                        check = ((sx > bx + bw) || (sx + 3 < bx) || (sy > by + bh) || (sy + 3 < by));
                    }
                    else
                    {
                        check = true;
                    }
                } while(!check);

                FlxTileblock b;
                b = new FlxTileblock(RX + bx * 8, RY + by * 8, bw * 8, bh * 8);
                b.loadTiles(ImgTech);
                _blocks.add(b);

                //If the block has room, add some non-colliding "dirt" graphics for variety
                if ((bw >= 4) && (bh >= 5))
                {
                    b = new FlxTileblock(RX + bx * 8 + 8, RY + by * 8, bw * 8 - 16, 8);
                    b.loadTiles(ImgDirtTop);
                    _decorations.add(b);

                    b = new FlxTileblock(RX + bx * 8 + 8, RY + by * 8 + 8, bw * 8 - 16, bh * 8 - 24);
                    b.loadTiles(ImgDirt);
                    _decorations.add(b);
                }
            }

            if (Spawners)
            {
                //Finally actually add the spawner
                Spawner sp = new Spawner(RX + sx * 8, RY + sy * 8, _bigGibs, _enemies, _enemyBullets, _littleGibs, _player);
                _spawners.add(sp);

                //Then create a dedicated camera to watch the spawner
                _hud.add(new FlxSprite(3 + (_spawners.length - 1) * 16, 3, ImgMiniFrame));
                FlxCamera camera = new FlxCamera(10 + (_spawners.length - 1) * 32, 10, 24, 24, 1);
                camera.follow(sp);
                FlxG.addCamera(camera);
            }
        }
예제 #8
0
 /// <summary>
 /// Tell the sprite to change to a random frame of animation
 /// Useful for instantiating particles or other weird things.
 /// </summary>
 public void randomFrame()
 {
     _curAnim  = null;
     _curIndex = (int)(FlxG.random() * (_pixels.Width / FrameWidth));
     Dirty     = true;
 }
예제 #9
0
        public override void create()
        {
            //Kick the framerate back up
            FlxG.Framerate = 60;
            //FlxG.flashFramerate = 60;

            //Let's setup our elevator, for some wonderful crate bashing goodness
            elevator = new FlxSprite((FlxG.width / 2) - 100, 250, elevatorPNG);
            //Make it able to collide, and make sure it's not tossed around
            elevator.Solid = elevator.Immovable = true;
            //And add it to the state
            add(elevator);

            //Now lets get some crates to smash around, normally I would use an emitter for this
            //kind of scene, but for this demo I wanted to use regular sprites
            //(See ParticlesDemo for an example of an emitter with colliding particles)
            //We'll need a group to place everything in - this helps a lot with collisions
            crateStormGroup = new FlxGroup();
            for (int i = 0; i < numCrates; i++)
            {
                crate = new FlxSprite((FlxG.random() * 200) + 100, 20);
                crate.loadRotatedGraphic(cratePNG, 16, 0);        //This loads in a graphic, and 'bakes' some rotations in so we don't waste resources computing real rotations later
                crate.AngularVelocity = FlxG.random() * 50 - 150; //Make it spin a tad
                crate.Acceleration.Y  = 300;                      //Gravity
                crate.Acceleration.X  = -50;                      //Some wind for good measure
                crate.MaxVelocity.Y   = 500;                      //Don't fall at 235986mph
                crate.MaxVelocity.X   = 200;                      //"      fly  "  "
                crate.Elasticity      = FlxG.random();            //Let's make them all bounce a little bit differently
                crateStormGroup.add(crate);
            }
            add(crateStormGroup);
            //And another group, this time - Red crates
            crateStormGroup2 = new FlxGroup();
            for (int i = 0; i < numCrates; i++)
            {
                crate = new FlxSprite((FlxG.random() * 200) + 100, 20);
                crate.loadRotatedGraphic(cratePNG, 16, 1);
                crate.AngularVelocity = FlxG.random() * 50 - 150;
                crate.Acceleration.Y  = 300;
                crate.Acceleration.X  = 50;
                crate.MaxVelocity.Y   = 500;
                crate.MaxVelocity.X   = 200;
                crate.Elasticity      = FlxG.random();
                crateStormGroup2.add(crate);
            }
            add(crateStormGroup2);

            //Now what we're going to do here is add both of those groups to a new containter group
            //This is useful if you had something like, coins, enemies, special tiles, etc.. that would all need
            //to check for overlaps with something like a player.
            crateStormMegaGroup = new FlxGroup();
            crateStormMegaGroup.add(crateStormGroup);
            crateStormMegaGroup.add(crateStormGroup2);

            //Cute little flixel logo that will ride the elevator
            flixelRider                = new FlxSprite((FlxG.width / 2) - 13, 0, flixelRiderPNG);
            flixelRider.Solid          = flixelRider.Visible = flixelRider.Exists = false;    //But we don't want him on screen just yet...
            flixelRider.Acceleration.Y = 800;
            add(flixelRider);

            //This is for the text at the top of the screen
            topText = new FlxText(0, 2, FlxG.width, "Welcome");
            topText.setAlignment("center");
            add(topText);

            //Lets make a bunch of buttons! YEAH!!!
            crateStorm = new FlxButton(2, FlxG.height - 22, "Crate Storm", onCrateStorm);
            add(crateStorm);
            flxRiderButton = new FlxButton(82, FlxG.height - 22, "Flixel Rider", onFlixelRider);
            add(flxRiderButton);
            crateStormG1 = new FlxButton(162, FlxG.height - 22, "Blue Group", onBlue);
            add(crateStormG1);
            crateStormG2 = new FlxButton(242, FlxG.height - 22, "Red Group", onRed);
            add(crateStormG2);
            groupCollision = new FlxButton(202, FlxG.height - 42, "Collide Groups", onCollideGroups);
            add(groupCollision);
            quitButton = new FlxButton(320, FlxG.height - 22, "Quit", onQuit);
            add(quitButton);

            //And lets get the flixel cursor visible again
            FlxG.mouse.show();
            //Mouse.hide();
        }
예제 #10
0
        /// <summary>
        /// Updates the camera scroll as well as special effects like screen-shake or fades.
        /// </summary>
        public override void update()
        {
            //Either follow the object closely,
            //or doublecheck our deadzone and update accordingly.
            if (Target != null)
            {
                if (Deadzone == null)
                {
                    focusOn(Target.getMidpoint(_point));
                }
                else
                {
                    float edge;
                    //float targetX = FlxU.ceil(Target.X + ((Target.X > 0) ? 0.0000001f : -0.0000001f));
                    //float targetY = FlxU.ceil(Target.Y + ((Target.Y > 0) ? 0.0000001f : -0.0000001f));
                    float targetX = Target.X + ((Target.X > 0) ? 0.0000001f : -0.0000001f);
                    float targetY = Target.Y + ((Target.Y > 0) ? 0.0000001f : -0.0000001f);

                    edge = targetX - Deadzone.X;
                    if (Scroll.X > edge)
                    {
                        Scroll.X = edge;
                    }

                    edge = targetX + Target.Width - Deadzone.X - Deadzone.Width;
                    if (Scroll.X < edge)
                    {
                        Scroll.X = edge;
                    }

                    edge = targetY - Deadzone.Y;
                    if (Scroll.Y > edge)
                    {
                        Scroll.Y = edge;
                    }

                    edge = targetY + Target.Height - Deadzone.Y - Deadzone.Height;
                    if (Scroll.Y < edge)
                    {
                        Scroll.Y = edge;
                    }
                }
            }

            // Make sure we didn't go outside the camera's bounds
            if (Bounds != null)
            {
                //FlxG.log("bounds is not null");
                if (Scroll.X < Bounds.Left)
                {
                    Scroll.X = Bounds.Left;
                }

                if (Scroll.X > Bounds.Right - Width)
                {
                    Scroll.X = Bounds.Right - Width;
                }

                if (Scroll.Y < Bounds.Top)
                {
                    Scroll.Y = Bounds.Top;
                }

                if (Scroll.Y > Bounds.Bottom - Height)
                {
                    Scroll.Y = Bounds.Bottom - Height;
                }
            }

            // Update the "flash" special effect
            if (fxFlashAlpha > 0.0)
            {
                fxFlashAlpha -= FlxG.elapsed / fxFlashDuration;
                if (fxFlashAlpha <= 0)
                {
                    fxFlashAlpha = 0;
                    if (fxFlashComplete != null)
                    {
                        fxFlashComplete();
                    }
                }
            }

            // Update the "fade" special effect
            if ((fxFadeAlpha > 0.0) && (fxFadeAlpha < 1.0))
            {
                fxFadeAlpha += FlxG.elapsed / fxFadeDuration;
                if (fxFadeAlpha >= 1.0)
                {
                    //fxFadeAlpha = 1.0f;
                    fxFadeAlpha = 0;
                    if (fxFadeComplete != null)
                    {
                        fxFadeComplete();
                    }
                }
            }

            // Update the "shake" special effect
            if (fxShakeDuration > 0)
            {
                fxShakeDuration -= FlxG.elapsed;
                if (fxShakeDuration <= 0)
                {
                    fxShakeOffset.make();
                    if (fxShakeComplete != null)
                    {
                        fxShakeComplete();
                    }
                }
                else
                {
                    if ((fxShakeDirection == ShakeBothAxes) || (fxShakeDirection == ShakeHorizontalOnly))
                    {
                        fxShakeOffset.X = (FlxG.random() * fxShakeIntensity * Width * 2 - fxShakeIntensity * Width) * _zoom;
                    }

                    if ((fxShakeDirection == ShakeBothAxes) || (fxShakeDirection == ShakeVerticalOnly))
                    {
                        fxShakeOffset.Y = (FlxG.random() * fxShakeIntensity * Height * 2 - fxShakeIntensity * Height) * _zoom;
                    }
                }
            }

            // flx#
            //Scroll.X -= fxShakeOffset.X;
            //Scroll.Y -= fxShakeOffset.Y;

            //if (zooming < 1)
            //    zooming = 1;
        }
예제 #11
0
		public override void update()
		{			
			base.update();

			if(title2.X > title1.X + title1.Width - 4)
			{
				//Once mo and de cross each other, fix their positions
				title2.X = title1.X + title1.Width - 4;
				title1.Velocity.X = 0;
				title2.Velocity.X = 0;

				//Then, play a cool sound, change their color, and blow up pieces everywhere
				/*
				FlxG.play(SndHit, 1f, false, false);
				*/
				FlxG.flash(Color.White,0.5f);
				FlxG.shake(0.035f,0.5f);
				title1.Color = Color.White;
				title2.Color = Color.White;
				gibs.start(true,5);
				title1.Angle = FlxG.random()*30-15;
				title2.Angle = FlxG.random()*30-15;

				//Then we're going to add the text and buttons and things that appear
				//If we were hip we'd use our own button animations, but we'll just recolor
				//the stock ones for now instead.
				FlxText text;
				text = new FlxText(FlxG.width/2-50,FlxG.height/3+39,100,"by Adam Atomic");
				/*text.Alignment = "center";*/
				text.Color = Color.White;
				add(text);
				/*
				FlxButton flixelButton = new FlxButton(FlxG.width/2-40,FlxG.height/3+54,"flixel.org",new IFlxButton(){ public void callback(){onFlixel();}});
				flixelButton.setColor(0xff729954);
				flixelButton.label.setColor(0xffd8eba2);
				ModeMenuState(flixelButton);

				FlxButton dannyButton = new FlxButton(flixelButton.X,flixelButton.Y + 22,"music: dannyB",new IFlxButton(){ public void callback(){onDanny();}});
				dannyButton.setColor(flixelButton.getColor());
				dannyButton.label.setColor(flixelButton.label.getColor());
				add(dannyButton);
				*/

				text = new FlxText(FlxG.width/2-40,FlxG.height/3+139,80,"X+C TO PLAY");
				text.Color = Color.White;
				//text.setAlignment("center");
				add(text);
				/*
				playButton = new FlxButton(flixelButton.X,flixelButton.Y + 82,"CLICK HERE", onPlay());
				playButton.setColor(flixelButton.getColor());
				playButton.label.setColor(flixelButton.label.getColor());
				add(playButton);
				*/
			}

			//X + C were pressed, fade out and change to play state.
			//OR, if we sat on the menu too long, launch the attract mode instead!
			timer += FlxG.elapsed;
			if(timer >= 10) //go into demo mode if no buttons are pressed for 10 seconds
				attractMode = true;
			if(!fading 
				&& ((FlxG.keys.pressed(Keys.X) && FlxG.keys.pressed(Keys.C)) 
				/*|| (_pad.buttonA.status == FlxButton.Pressed && _pad.buttonB.status == FlxButton.Pressed) */
				|| attractMode)) 
			{
				fading = true;
				/*FlxG.play(SndHit2, 1f, false, false);*/
				FlxG.flash(Color.White,0.5f);
				FlxG.fade(Color.Black,1, onFade);
			}
		}
예제 #12
0
        /// <summary>
        /// This function generates a new array of particle sprites to attach to the emitter.
        /// </summary>
        /// <param name="graphics">Texture for the particles - can be one square or a spritesheet.  Set Multiple to true if it is a spritesheet and it will automatically create the particles as long as each frame on the spritesheet is square</param>
        /// <param name="Multiple">Whether or not the Texture contains multiple sprites for particles</param>
        /// <param name="Quantity">The number of particles to generate</param>
        /// <param name="Rotation">The amount of rotation in degrees per frame, so keep this number low</param>
        /// <param name="Collide">The collidability of the particle, 1 = Full and 0 = None</param>
        /// <returns>This FlxEmitter instance (nice for chaining stuff together, if you're into that).</returns>
        //public FlxEmitter makeParticles(Texture2D graphics, bool Multiple=false, uint Quantity = 50, float Rotation = 1f, float Collide = 0.8f)
        public FlxEmitter makeParticles(string graphics, uint Quantity = 50, uint BakedRotations = 0, bool Multiple = false, float Collide = 0.8f)
        {
            maxSize = Quantity;
            uint totalFrames = 0;

            if (Multiple)
            {
                FlxSprite sprite = new FlxSprite();
                sprite.loadGraphic(graphics, true);
                totalFrames = sprite.Frames;
                sprite.destroy();
            }

            uint        randomFrame;
            FlxParticle particle;
            int         i = 0;

            while (i < Quantity)
            {
                particle = new FlxParticle();

                /*
                 * if(particleClass == null)
                 *      particle = new FlxParticle();
                 * else
                 *      particle = new particleClass();
                 */
                if (Multiple)
                {
                    randomFrame = (uint)(FlxG.random() * totalFrames);
                    if (BakedRotations > 0)
                    {
                        particle.loadRotatedGraphic(graphics, BakedRotations, (int)randomFrame);
                    }
                    else
                    {
                        particle.loadGraphic(graphics, true);
                        particle.Frame = (int)randomFrame;
                    }
                }
                else
                {
                    if (BakedRotations > 0)
                    {
                        particle.loadRotatedGraphic(graphics, BakedRotations);
                    }
                    else
                    {
                        particle.loadGraphic(graphics);
                    }
                }
                if (Collide > 0)
                {
                    particle.Width  *= Collide;
                    particle.Height *= Collide;
                    particle.centerOffsets();
                }
                else
                {
                    particle.AllowCollisions = FlxObject.None;
                }
                particle.Exists = false;
                add(particle);
                i++;
            }

            return(this);
        }
예제 #13
0
        /**
         * Fills the block with a randomly arranged selection of graphics from the image provided.
         *
         * @param	TileGraphic     The graphic class that contains the tiles that should fill this block.
         * @param	TileWidth		The width of a single tile in the graphic.
         * @param	TileHeight		The height of a single tile in the graphic.
         * @param	Empties			The number of "empty" tiles to add to the auto-fill algorithm (e.g. 8 tiles + 4 empties = 1/3 of block will be open holes).
         */
        public FlxTileblock loadTiles(string TileGraphic, uint TileWidth = 0, uint TileHeight = 0, uint Empties = 0)
        {
            if (TileGraphic == null)
            {
                return(this);
            }

            //First create a tile brush
            FlxSprite sprite = new FlxSprite();

            sprite.loadGraphic(TileGraphic, true, false, TileWidth, TileHeight);
            uint spriteWidth  = (uint)sprite.Width;
            uint spriteHeight = (uint)sprite.Height;
            uint total        = sprite.Frames + Empties;

            //Then prep the "canvas" as it were (just doublechecking that the size is on tile boundaries)
            bool regen = false;

            if (Width % sprite.Width != 0)
            {
                Width = (uint)(Width / spriteWidth + 1) * spriteWidth;
                regen = true;
            }
            if (Height % sprite.Height != 0)
            {
                Height = (uint)(Height / spriteHeight + 1) * spriteHeight;
                regen  = true;
            }
            if (regen)
            {
                makeGraphic((uint)Width, (uint)Height, Color.Green, true);
            }
            else
            {
                this.fill(Color.Green);
            }

            //Stamp random tiles onto the canvas
            uint row = 0;
            uint column;
            int  destinationX;
            int  destinationY  = 0;
            uint widthInTiles  = (uint)Width / spriteWidth;
            uint heightInTiles = (uint)Height / spriteHeight;

            while (row < heightInTiles)
            {
                destinationX = 0;
                column       = 0;
                while (column < widthInTiles)
                {
                    if (FlxG.random() * total > Empties)
                    {
                        sprite.randomFrame();
                        sprite.drawFrame();
                        stamp(sprite, destinationX, destinationY);
                    }
                    destinationX += (int)spriteWidth;
                    column++;
                }
                destinationY += (int)spriteHeight;
                row++;
            }

            return(this);
        }