Exemplo n.º 1
1
		public override void create ()
		{

			FlxG.debug = true;
					
			// The grass background
			FlxSprite grass = new FlxSprite (0, 0).loadGraphic (ImgGrass, false, false, FlxG.width, FlxG.height);
			add (grass);

			add (_bunnies = new FlxGroup ());
			
			
			// Text display
			add (_bunnyCounter = new FlxText (0, FlxG.height - 20, FlxG.width).setFormat (null, 8, Color.White, "right", Color.Black));
			add (_memoryUsage = new FlxText (5, FlxG.height - 20, 200).setFormat (null, 8, Color.White, "left", Color.Black));
			
			// Buttons Left side
			float leftBtnY = 20;

			add (new FlxButton (leftBtnY, 25, "+" + INITIAL_AMOUNT, addBunnies));
			add (new FlxButton (leftBtnY, 50, "-" + INITIAL_AMOUNT, removeBunnies));
			
			// Buttons right side
			float rightBtnX = FlxG.width - 100;
			add (_complexityButton = new FlxButton (rightBtnX, 25, "Complex", ComplexityCallback));			
			add (_collisionButton = new FlxButton (rightBtnX, 65, "Collision ON", CollisionCallback));			
			
			// Finally create the bunnies
			addBunnies ();
			
			// Force GC
			GC.Collect ();
			
			// Timer to update the memory usage
			_memoryTimer = new FlxTimer ();
			updateMemoryUsage ();

			// Show mouse pointer
			FlxG.mouse.show ();
		}
Exemplo n.º 2
0
        /// <summary>
        /// This function draws or stamps one <code>FlxSprite</code> onto another.
        /// This function is NOT intended to replace <code>draw()</code>!
        /// </summary>
        /// <param name="brush">The image you want to use as a brush or stamp or pen or whatever.</param>
        /// <param name="x">The X coordinate of the brush's top left corner on this sprite.</param>
        /// <param name="y">They Y coordinate of the brush's top left corner on this sprite.</param>
        public void stamp(FlxSprite brush, int x = 0, int y = 0)
        {
            throw new NotImplementedException();

            /*
             *          Brush.drawFrame();
             *          var bitmapData:BitmapData = Brush.framePixels;
             *
             *          //Simple draw
             *          if(((Brush.angle == 0) || (Brush._bakedRotation > 0)) && (Brush.scale.x == 1) && (Brush.scale.y == 1) && (Brush.blend == null))
             *          {
             *                  _flashPoint.x = X;
             *                  _flashPoint.y = Y;
             *                  _flashRect2.width = bitmapData.width;
             *                  _flashRect2.height = bitmapData.height;
             *                  _pixels.copyPixels(bitmapData,_flashRect2,_flashPoint,null,null,true);
             *                  _flashRect2.width = _pixels.width;
             *                  _flashRect2.height = _pixels.height;
             *                  calcFrame();
             *                  return;
             *          }
             *
             *          //Advanced draw
             *          _matrix.identity();
             *          _matrix.translate(-Brush.origin.x,-Brush.origin.y);
             *          _matrix.scale(Brush.scale.x,Brush.scale.y);
             *          if(Brush.angle != 0)
             *                  _matrix.rotate(Brush.angle * 0.017453293);
             *          _matrix.translate(X+Brush.origin.x,Y+Brush.origin.y);
             *          _pixels.draw(bitmapData,_matrix,null,Brush.blend,null,Brush.antialiasing);
             *          calcFrame();
             */
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public FlxMouse()
 {
     screenX = 0;
     screenY = 0;
     cursor = new FlxSprite();
     cursor.Visible = false;
     lastTouchEvent = false;
     _lastTouch = TouchLocationState.Released;
 }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
0
 public FlxConsole()
     : base()
 {
     bg = new FlxSprite(80, 40);
     bg.makeGraphic((uint)FlxS.GraphicsDevice.Viewport.Width - 160, (uint)FlxS.GraphicsDevice.Viewport.Height - 80, FlxColor.WHITE * 0.45f);
     bg.Alpha = 0.5f;
     add(bg);
     ScrollFactor.X = ScrollFactor.Y = 0;
     Visible = false;
     //text = new FlxText(100, 60, FlxS.GraphicsDevice.Viewport.Width - 160, "internal console is a work in progress", FlxG.defaultFont);
     //text.setFormat(FlxColor.WHITE);
     text.Alpha = 0.75f;
     add(text);
 }
Exemplo n.º 6
0
 public FlxConsole()
     : base()
 {
     bg = new FlxSprite(80, 40);
     bg.makeGraphic((uint)FlxS.GraphicsDevice.Viewport.Width - 160, (uint)FlxS.GraphicsDevice.Viewport.Height - 80, FlxColor.WHITE * 0.45f);
     bg.Alpha = 0.5f;
     add(bg);
     ScrollFactor.X = ScrollFactor.Y = 0;
     Visible        = false;
     //text = new FlxText(100, 60, FlxS.GraphicsDevice.Viewport.Width - 160, "internal console is a work in progress", FlxG.defaultFont);
     //text.setFormat(FlxColor.WHITE);
     text.Alpha = 0.75f;
     add(text);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Clean up memory.
        /// </summary>
        public override void destroy()
        {
            screen.destroy();
            screen   = null;
            Target   = null;
            Scroll   = null;
            Deadzone = null;
            Bounds   = null;
            Buffer   = null;
            //_flashBitmap = null;
            //_flashRect = null;
            //_flashPoint = null;
            fxFlashComplete = null;
            fxFadeComplete  = null;
            fxShakeComplete = null;
            fxShakeOffset   = null;
            //_fill = null;

            base.destroy();
        }
Exemplo n.º 8
0
		//creates a new coin located on the specified tile
		public void createCoin (int X, int Y)
		{
			FlxSprite coin = new FlxSprite (X * 8 + 3, Y * 8 + 2);
			coin.makeGraphic (2, 4, FlxColor.YELLOW);
			coins.add (coin);
		}
Exemplo n.º 9
0
		public override void create()
		{
			FlxG.Framerate = 50;
			//FlxG.FlashFramerate = 50;

			// set the background color to white
			FlxG.bgColor = FlxColor.WHITE;

			//Setup the level (40 x 40 tiles) Addapted from Adam Atomic's EZPlatformer
			int[] levelData = {
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };

			// Create the tilemap from the levelData we just created
			level = new FlxTilemap();
			level.loadMap(FlxTilemap.arrayToCSV(levelData, 40), FlxTilemap.ImgAuto,0,0,FlxTilemap.AUTO);
			add(level);

			//Create the two players
			player1 = new FlxSprite(65, 200).makeGraphic(10,12, FlxColor.RED); //player 1 is red and starts at 65, 200
			player1.MaxVelocity.X = 80;   // Theses are pysics settings,
			player1.MaxVelocity.Y = 200;  // controling how the players behave
			player1.Acceleration.Y = 200; // in the game
			player1.Drag.X = player1.MaxVelocity.X*4;
			add(player1);

			player2 = new FlxSprite(265, 200).makeGraphic(10,12, FlxColor.BLUE); // player2 is blue and starts at 265, 200
			player2.MaxVelocity.X = 80; // Same thing than player 1
			player2.MaxVelocity.Y = 200;
			player2.Acceleration.Y = 200;
			player2.Drag.X = player2.MaxVelocity.X*4;
			add(player2);

			// Then we setup two cameras to follow each of the two players

			FlxCamera cam = new FlxCamera(0,0, FlxG.width/2, FlxG.height); // we put the first one in the top left corner
			cam.follow(player2);
			// this sets the limits of where the camera goes so that it doesn't show what's outside of the tilemap
			cam.setBounds(0,0,level.Width, level.Height);
			cam.Color = FlxColor.PINK; // add a light red tint to the camera to differentiate it from the other
			FlxG.resetCameras (cam);

			// Almost the same thing as the first camera
			cam = new FlxCamera(FlxG.width/2,0, FlxG.width/2, FlxG.height);    // and the second one in the top middle of the screen
			cam.follow(player1);
			cam.setBounds(0,0,level.Width, level.Height);
			cam.Color = FlxColor.CADETBLUE; // Add a light blue tint to the camera
			FlxG.addCamera(cam);
		}
Exemplo n.º 10
0
		private void setupPlayer ()
		{
			player = new FlxSprite (64, 220);
			player.loadGraphic (ImgSpaceman, true, true, 16);

			//bounding box tweaks
			player.Width = 14;
			player.Height = 14;
			player.Offset.X = 1;
			player.Offset.Y = 1;

			//basic player physics
			player.Drag.X = 640;
			player.Acceleration.Y = 420;
			player.MaxVelocity.X = 80;
			player.MaxVelocity.Y = 200;

			//animations
			player.addAnimation ("idle", new int[]{ 0 });
			player.addAnimation ("run", new int[]{ 1, 2, 3, 0 }, 12);
			player.addAnimation ("jump", new int[]{ 4 });

			add (player);
		}
Exemplo n.º 11
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();
		}
Exemplo n.º 12
0
		override public void create()
		{
			FlxG.Framerate = 60;
			//FlxG.flashFramerate = 60;

			//Here we actually initialize out emitter
			//The parameters are        X   Y                Size (Maximum number of particles the emitter can store)
			theEmitter = new FlxEmitter(10, FlxG.height / 2, 200);

			//Now by default the emitter is going to have some properties set on it and can be used immediately
			//but we're going to change a few things.

			//First this emitter is on the side of the screen, and we want to show off the movement of the particles
			//so lets make them launch to the right.
			theEmitter.setXSpeed(100, 200);

			//and lets funnel it a tad
			theEmitter.setYSpeed( -50, 50);

			//Let's also make our pixels rebound off surfaces
			theEmitter.bounce = 0.8f;

			//Now let's add the emitter to the state.
			add(theEmitter);

			//Now it's almost ready to use, but first we need to give it some pixels to spit out!
			//Lets fill the emitter with some white pixels
			for (int i = 0; i < theEmitter.maxSize/2; i++) {
				whitePixel = new FlxParticle();
				whitePixel.makeGraphic(2, 2, new Color(0xFF,0xFF,0xFF));
				whitePixel.Visible = false; //Make sure the particle doesn't show up at (0, 0)
				theEmitter.add(whitePixel);
				whitePixel = new FlxParticle();
				whitePixel.makeGraphic(1, 1, new Color(0xFF,0xFF,0xFF));
				whitePixel.Visible = false;
				theEmitter.add(whitePixel);
			}

			//Now let's setup some buttons for messing with the emitter.
			collisionButton = new FlxButton(0, FlxG.height - 22, "Collision", onCollision);
			add(collisionButton);
			gravityButton = new FlxButton(80, FlxG.height - 22, "Gravity", onGravity);
			add(gravityButton);
			quitButton = new FlxButton(FlxG.width-80, FlxG.height - 22, "Quit", onQuit);
			add(quitButton);

			//I'll just leave this here
			topText = new FlxText(0, 2, FlxG.width, "Welcome");
			topText.setAlignment("center");
			add(topText);

			//Lets setup some walls for our pixels to collide against
			collisionGroup = new FlxGroup();
			wall= new FlxSprite(100, (FlxG.height/2)-50);
			wall.makeGraphic(10, 100, new Color(0xFF,0xFF,0xFF,0x50));//Make it darker - easier on the eyes :)
			wall.Visible = wall.Solid = false;//Set both the visibility AND the solidity to false, in one go
			wall.Immovable = true;//Lets make sure the pixels don't push out wall away! (though it does look funny)
			collisionGroup.add(wall);
			//Duplicate our wall but this time it's a floor to catch gravity affected particles
			floor = new FlxSprite(10, 267);
			floor.makeGraphic((uint)FlxG.width - 20, 10, new Color(0xFF,0xFF,0xFF,0x50));
			floor.Visible = floor.Solid = false;
			floor.Immovable = true;
			collisionGroup.add(floor);

			//Please note that this demo makes the walls themselves not collide, for the sake of simplicity.
			//Normally you would make the particles have solid = true or false to make them collide or not on creation,
			//because in a normal environment your particles probably aren't going to change solidity at a mouse 
			//click. If they did, you would probably be better suited with emitter.setAll("solid", true)
			//I just don't feel that setAll is applicable here(Since I would still have to toggle the walls anyways)

			//Don't forget to add the group to the state(Like I did :P)
			add(collisionGroup);

			//Now lets set our emitter free.
			//Params:        Explode, Particle Lifespan, Emit rate(in seconds)
			theEmitter.start(false, 3, .01f);

			//Let's re show the cursors
			FlxG.mouse.show();
			//Mouse.hide();
		}
Exemplo n.º 13
0
        /// <summary>
        /// This function draws or stamps one <code>FlxSprite</code> onto another.
        /// This function is NOT intended to replace <code>draw()</code>!
        /// </summary>
        /// <param name="brush">The image you want to use as a brush or stamp or pen or whatever.</param>
        /// <param name="x">The X coordinate of the brush's top left corner on this sprite.</param>
        /// <param name="y">They Y coordinate of the brush's top left corner on this sprite.</param>
        public void stamp(FlxSprite brush, int x = 0, int y = 0)
        {
            throw new NotImplementedException();

            /*
            Brush.drawFrame();
            var bitmapData:BitmapData = Brush.framePixels;

            //Simple draw
            if(((Brush.angle == 0) || (Brush._bakedRotation > 0)) && (Brush.scale.x == 1) && (Brush.scale.y == 1) && (Brush.blend == null))
            {
                _flashPoint.x = X;
                _flashPoint.y = Y;
                _flashRect2.width = bitmapData.width;
                _flashRect2.height = bitmapData.height;
                _pixels.copyPixels(bitmapData,_flashRect2,_flashPoint,null,null,true);
                _flashRect2.width = _pixels.width;
                _flashRect2.height = _pixels.height;
                calcFrame();
                return;
            }

            //Advanced draw
            _matrix.identity();
            _matrix.translate(-Brush.origin.x,-Brush.origin.y);
            _matrix.scale(Brush.scale.x,Brush.scale.y);
            if(Brush.angle != 0)
                _matrix.rotate(Brush.angle * 0.017453293);
            _matrix.translate(X+Brush.origin.x,Y+Brush.origin.y);
            _pixels.draw(bitmapData,_matrix,null,Brush.blend,null,Brush.antialiasing);
            calcFrame();
            */
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
		public override void create()
		{
			// Background color
			FlxG.bgColor = (FlxColor.GREEN);
			FlxG.worldBounds = new FlxRect(0, 0, 320, 240);

			//Design your platformer level with 1s and 0s (at 40x30 to fill 320x240 screen)		
			int[] data = {
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
				1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
				1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1,
				1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1,
				1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};

			//Create a new tilemap using our level data
			level = new FlxTilemap ();
			level.loadMap (FlxTilemap.arrayToCSV (data, 40), FlxTilemap.ImgAuto, 0, 0, FlxTilemap.AUTO);
			add (level);

			//Create the level exit, a dark gray box that is hidden at first
			exit = new FlxSprite (35 * 8 + 1, 25 * 8);
			exit.makeGraphic (14, 16, FlxColor.BLUE);
			exit.Exists = false;
			add (exit);

			//Create coins to collect (see createCoin() function below for more info)
			coins = new FlxGroup ();
			//Top left coins
			createCoin (18, 4);
			createCoin (12, 4);
			createCoin (9, 4);
			createCoin (8, 11);
			createCoin (1, 7);
			createCoin (3, 4);
			createCoin (5, 2);
			createCoin (15, 11);
			createCoin (16, 11);

			//Bottom left coins
			createCoin (3, 16);
			createCoin (4, 16);
			createCoin (1, 23);
			createCoin (2, 23);
			createCoin (3, 23);
			createCoin (4, 23);
			createCoin (5, 23);
			createCoin (12, 26);
			createCoin (13, 26);
			createCoin (17, 20);
			createCoin (18, 20);

			//Top right coins
			createCoin (21, 4);
			createCoin (26, 2);
			createCoin (29, 2);
			createCoin (31, 5);
			createCoin (34, 5);
			createCoin (36, 8);
			createCoin (33, 11);
			createCoin (31, 11);
			createCoin (29, 11);
			createCoin (27, 11);
			createCoin (25, 11);
			createCoin (36, 14);

			//Bottom right coins
			createCoin (38, 17);
			createCoin (33, 17);
			createCoin (28, 19);
			createCoin (25, 20);
			createCoin (18, 26);
			createCoin (22, 26);
			createCoin (26, 26);
			createCoin (30, 26);

			add (coins);

			//Create player (a red box)
			player = new FlxSprite (FlxG.width / 2 - 5);
			player.makeGraphic (10, 12, FlxColor.RED);
			player.MaxVelocity.X = 80;
			player.MaxVelocity.Y = 200;
			player.Acceleration.Y = 200;
			player.Drag.X = player.MaxVelocity.X * 4;
			add (player);

			score = new FlxText (2, 2, 80, "SCORE: ");
			//score.setShadow(FlxColor.BLACK);
			score.text = "SCORE: " + (coins.CountDead () * 100);
			add (score);

			status = new FlxText (FlxG.width - 160 - 2, 2, 160);
			//status.setShadow(0xff000000);
			//status.setAlignment("right");
			switch (FlxG.score) {
			case 0:
				status.text = "Collect coins.";
				break;
			case 1:
				status.text = "Aww, you died!";
				break;
			}
			add (status);
		}
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Instantiates a new camera at the specified location, with the specified size and zoom level.
        /// </summary>
        /// <param name="x">X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.</param>
        /// <param name="y">Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.</param>
        /// <param name="width">The width of the camera display in pixels.</param>
        /// <param name="height">The height of the camera display in pixels.</param>
        /// <param name="zoom">The initial zoom level of the camera. A zoom level of 2 will make all pixels display at 2x resolution.</param>
        public FlxCamera(float x, float y, int width, int height, float zoom = 0)
            : base()
        {
            X        = x;
            Y        = y;
            Width    = width;
            Height   = height;
            Target   = null;
            Deadzone = null;
            Scroll   = new FlxPoint();
            _point   = new FlxPoint();
            Bounds   = null;
            screen   = new FlxSprite();
            screen.makeGraphic((uint)width, (uint)height, new Color(0, 0, 0, 0));
            screen.setOriginToCorner();
            //Buffer = (RenderTarget2D)screen.Pixels;
            BgColor = FlxG.bgColor;

            _color = Color.White;

            /*
             * _flashBitmap = new Bitmap(buffer);
             * _flashBitmap.x = -width*0.5;
             * _flashBitmap.y = -height*0.5;
             * _flashSprite = new Sprite();
             */
            zoom = Zoom;             //sets the scale of flash sprite, which in turn loads flashoffset values

            /*
             * _flashOffsetX = width*0.5*zoom;
             * _flashOffsetY = height*0.5*zoom;
             * _flashSprite.x = x + _flashOffsetX;
             * _flashSprite.y = y + _flashOffsetY;
             * _flashSprite.addChild(_flashBitmap);
             * _flashRect = new Rectangle(0,0,width,height);
             * _flashPoint = new Point();
             */
            fxFlashColor    = Color.Black;
            fxFlashDuration = 0.0f;
            fxFlashComplete = null;
            fxFlashAlpha    = 0.0f;

            fxFadeColor    = Color.Black;
            fxFadeDuration = 0.0f;
            fxFadeComplete = null;
            fxFadeAlpha    = 0.0f;

            fxShakeIntensity = 0.0f;
            fxShakeDuration  = 0.0f;
            fxShakeComplete  = null;
            fxShakeOffset    = new FlxPoint();
            fxShakeDirection = 0;

            //_fill = new BitmapData(width,height,true,0);

            // flx#
            //DefaultZoom = 1.0f;
            rotating    = 0.0f;
            Zoom        = zoom;
            FlashSprite = new FlxObject();
            //BgColor = Color.Black;

            _fxHelperTexture = new Texture2D(FlxS.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            _fxHelperTexture.SetData(new[] { Color.White });

            _fillTexture = new Texture2D(FlxS.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            _fillTexture.SetData(new[] { Color.White });

            UpdateHelpers();
        }
Exemplo n.º 19
0
        /// <summary>
        /// Clean up memory.
        /// </summary>
        public override void destroy()
        {
            screen.destroy();
            screen = null;
            Target = null;
            Scroll = null;
            Deadzone = null;
            Bounds = null;
            Buffer = null;
            //_flashBitmap = null;
            //_flashRect = null;
            //_flashPoint = null;
            fxFlashComplete = null;
            fxFadeComplete = null;
            fxShakeComplete = null;
            fxShakeOffset = null;
            //_fill = null;

            base.destroy();
        }
Exemplo n.º 20
0
        /// <summary>
        /// Instantiates a new camera at the specified location, with the specified size and zoom level.
        /// </summary>
        /// <param name="x">X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.</param>
        /// <param name="y">Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.</param>
        /// <param name="width">The width of the camera display in pixels.</param>
        /// <param name="height">The height of the camera display in pixels.</param>
        /// <param name="zoom">The initial zoom level of the camera. A zoom level of 2 will make all pixels display at 2x resolution.</param>
        public FlxCamera(float x, float y, int width, int height, float zoom = 0)
            : base()
        {
            X = x;
            Y = y;
            Width = width;
            Height = height;
            Target = null;
            Deadzone = null;
            Scroll = new FlxPoint();
            _point = new FlxPoint();
            Bounds = null;
            screen = new FlxSprite();
            screen.makeGraphic((uint) width, (uint) height, new Color(0, 0, 0, 0));
            screen.setOriginToCorner();
            //Buffer = (RenderTarget2D)screen.Pixels;
            BgColor = FlxG.bgColor;

            _color = Color.White;
            /*
            _flashBitmap = new Bitmap(buffer);
            _flashBitmap.x = -width*0.5;
            _flashBitmap.y = -height*0.5;
            _flashSprite = new Sprite();
            */
            zoom = Zoom; //sets the scale of flash sprite, which in turn loads flashoffset values
            /*
            _flashOffsetX = width*0.5*zoom;
            _flashOffsetY = height*0.5*zoom;
            _flashSprite.x = x + _flashOffsetX;
            _flashSprite.y = y + _flashOffsetY;
            _flashSprite.addChild(_flashBitmap);
            _flashRect = new Rectangle(0,0,width,height);
            _flashPoint = new Point();
            */
            fxFlashColor = Color.Black;
            fxFlashDuration = 0.0f;
            fxFlashComplete = null;
            fxFlashAlpha = 0.0f;

            fxFadeColor = Color.Black;
            fxFadeDuration = 0.0f;
            fxFadeComplete = null;
            fxFadeAlpha = 0.0f;

            fxShakeIntensity = 0.0f;
            fxShakeDuration = 0.0f;
            fxShakeComplete = null;
            fxShakeOffset = new FlxPoint();
            fxShakeDirection = 0;

            //_fill = new BitmapData(width,height,true,0);

            // flx#
            //DefaultZoom = 1.0f;
            rotating = 0.0f;
            Zoom = zoom;
            FlashSprite = new FlxObject();
            //BgColor = Color.Black;

            _fxHelperTexture = new Texture2D(FlxS.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            _fxHelperTexture.SetData(new[] { Color.White });

            _fillTexture = new Texture2D(FlxS.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            _fillTexture.SetData(new[] { Color.White });

            UpdateHelpers();
        }