コード例 #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 ();
		}
コード例 #2
0
		public override void create()
		{
			FlxG.bgColor = FlxColor.BLACK;
			_items = new FlxGroup ();
			_states = new List<FlxState> ();

			_states.Add (new Platformer());
			_states.Add (new SplitScreen());
			_states.Add (new BunnyPlayState());
			_states.Add (new ModePlayState());
			_states.Add (new Particles());
			_states.Add (new Collision());
			_states.Add (new Tilemap());

			_items.add (new FlxText(0, startY, FlxG.width, "Platformer").setFormat (null, 8, Color.White, "center", Color.Black));
			_items.add (new FlxText(0, (startY += 20), FlxG.width, "SplitScreen").setFormat (null, 8, Color.White, "center", Color.Black));
			_items.add (new FlxText(0, (startY += 20), FlxG.width, "BunnyMark").setFormat (null, 8, Color.White, "center", Color.Black));
			_items.add (new FlxText(0, (startY += 20), FlxG.width, "Mode").setFormat (null, 8, Color.White, "center", Color.Black));
			_items.add (new FlxText(0, (startY += 20), FlxG.width, "Particles").setFormat (null, 8, Color.White, "center", Color.Black));
			_items.add (new FlxText(0, (startY += 20), FlxG.width, "Collision").setFormat (null, 8, Color.White, "center", Color.Black));
			_items.add (new FlxText(0, (startY += 20), FlxG.width, "Auto Tilemap").setFormat (null, 8, Color.White, "center", Color.Black));

			add(_items);

			add (new FlxText(0, 15, FlxG.width, "-- MonoFlixel Examples --").setFormat (null, 16, Color.White, "center", Color.Black));

			_selected = new FlxText (FlxG.width/2-80, ((FlxText)_items.Members [selectedID]).Y, FlxG.width, ">").setFormat (null, 8, Color.White, "left", Color.Black);

			add (_selected);
		}
コード例 #3
0
		public override void create()
		{
			_timer = 0;
			_fading = false;
			FlxG.flash(Color.White);

			//Gibs emitted upon death
			FlxEmitter gibs = new FlxEmitter(0,-50);
			gibs.setSize((uint)FlxG.width,0);
			gibs.setXSpeed();
			gibs.setYSpeed(0,100);
			gibs.setRotation(-360,360);
			gibs.gravity = 80;
			gibs.makeParticles(ImgGibs,800,32,true,0);
			add(gibs);
			gibs.start(false,0,0.005f);

			FlxText text = new FlxText(0,FlxG.height/2-35,FlxG.width,"VICTORY\n\nSCORE: "+FlxG.score);
			/*
			if(Gdx.app.getType() == ApplicationType.WebGL)
				text.setFormat(ImgFont20,20,0xd8eba2,"center");
			else
				text.setFormat(null,16,0xd8eba2,"center");*/
			add(text);
		}
コード例 #4
0
		override public void create ()
		{
			FlxG.Framerate = 50;
			//FlxG.flashFramerate = 50;

			// Creates a new tilemap with no arguments
			collisionMap = new FlxTilemap ();

			/*
			 * FlxTilemaps are created using strings of comma seperated values (csv)
			 * This string ends up looking something like this:
			 *
			 * 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,1,0,
			 * 0,0,1,1,1,0,0,0,0,0,
			 * ...
			 *
			 * Each '0' stands for an empty tile, and each '1' stands for
			 * a solid tile
			 *
			 * When using the auto map generation, the '1's are converted into the corresponding frame
			 * in the tileset.
			 */

			// Initializes the map using the generated string, the tile images, and the tile size
			collisionMap.loadMapFile (default_auto, auto_tiles, (int)TILE_WIDTH, (int)TILE_HEIGHT, FlxTilemap.AUTO);
			add (collisionMap);

			highlightBox = new FlxObject (0, 0, TILE_WIDTH, TILE_HEIGHT);

			setupPlayer ();

			// When switching between modes here, the map is reloaded with it's own data, so the positions of tiles are kept the same
			// Notice that different tilesets are used when the auto mode is switched
			autoAltBtn = new FlxButton (4, FlxG.height - 24, "AUTO", altButtonFunc);
			add (autoAltBtn);

			resetBtn = new FlxButton (8 + autoAltBtn.Width, FlxG.height - 24, "Reset", resetButtonFunc);
			add (resetBtn);

			quitBtn = new FlxButton (FlxG.width - resetBtn.Width - 4, FlxG.height - 24, "Quit", onQuit);
			add (quitBtn);

			helperTxt = new FlxText (5, 5, 150, "Click to place tiles. Shift-Click to remove tiles\nArrow keys to move");
			add (helperTxt);

			// Show mouse pointer
			FlxG.mouse.show ();
		}
コード例 #5
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();
		}
コード例 #6
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();
		}
コード例 #7
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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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);
		}
コード例 #8
0
		//private FlxVirtualPad _pad;
		
		public override void create()
		{
	//		FlxG.mouse.hide();
			
			/*_sfxCount = new FlxSound().loadEmbedded(SndCount, false, false, FlxSound.SFX);*/
			/*
			_pad = new FlxVirtualPad(FlxVirtualPad.DPAD_FULL, FlxVirtualPad.A_B);
			_pad.Alpha = 0.5f;
			*/		
	//		if(Gdx.app.getType() == ApplicationType.Desktop || MenuState.attractMode)
	//			_pad.visible = false;

			//Here we are creating a pool of 100 little metal bits that can be exploded.
			//We will recycle the crap out of these!
			_littleGibs = new FlxEmitter();
			_littleGibs.setXSpeed(-150,150);
			_littleGibs.setYSpeed(-200,0);
			_littleGibs.setRotation(-720,-720);
			_littleGibs.gravity = 350;
			_littleGibs.bounce = 0.5f;
			_littleGibs.makeParticles(ImgGibs,100,10,true,0.5f);

			//Next we create a smaller pool of larger metal bits for exploding.
			_bigGibs = new FlxEmitter();
			_bigGibs.setXSpeed(-200,200);
			_bigGibs.setYSpeed(-300,0);
			_bigGibs.setRotation(-720,-720);
			_bigGibs.gravity = 350;
			_bigGibs.bounce = 0.35f;
			_bigGibs.makeParticles(ImgSpawnerGibs,50,20,true,0.5f);

			//Then we'll set up the rest of our object groups or pools
			_blocks = new FlxGroup();
			_decorations = new FlxGroup();
			_enemies = new FlxGroup();
			_spawners = new FlxGroup();
			_hud = new FlxGroup();
			_enemyBullets = new FlxGroup();
			_bullets = new FlxGroup();

			//Now that we have references to the bullets and metal bits,
			//we can create the player object.
			_player = new Player(316,300,_bullets,_littleGibs/*, _pad*/);

			//This refers to a custom function down at the bottom of the file
			//that creates all our level geometry with a total size of 640x480.
			//This in turn calls buildRoom() a bunch of times, which in turn
			//is responsible for adding the spawners and spawn-cameras.
			generateLevel();

			//Add bots and spawners after we add blocks to the state,
			//so that they're drawn on top of the level, and so that
			//the bots are drawn on top of both the blocks + the spawners.
			add(_spawners);
			add(_littleGibs);
			add(_bigGibs);
			add(_blocks);
			add(_decorations);
			add(_enemies);

			//Then we add the player and set up the scrolling camera,
			//which will automatically set the boundaries of the world.
			add(_player);
			FlxG.camera.setBounds(0,0,640,640,true);
			FlxG.camera.follow(_player,FlxCamera.StylePlatformer);

			//We add the bullets to the scene here,
			//so they're drawn on top of pretty much everything
			add(_enemyBullets);
			add(_bullets);
			add(_hud);

			//Finally we are going to sort things into a couple of helper groups.
			//We don't add these groups to the state, we just use them for collisions later!
			_hazards = new FlxGroup();
			_hazards.add(_enemyBullets);
			_hazards.add(_spawners);
			_hazards.add(_enemies);
			_objects = new FlxGroup();
			_objects.add(_enemyBullets);
			_objects.add(_bullets);
			_objects.add(_enemies);
			_objects.add(_player);
			_objects.add(_littleGibs);
			_objects.add(_bigGibs);

			//From here on out we are making objects for the HUD,
			//that is, the player score, number of spawners left, etc.
			//First, we'll create a text field for the current score
			_score = new FlxText(FlxG.width/4,0,FlxG.width/2);
			/*
			if(Gdx.app.getType() == ApplicationType.WebGL)
				_score.setFormat(ImgFont20,20,0xd8eba2,"center",0x131c1b);			
			else*/
				/*_score.setFormat(null,16,0xd8eba2,"center",0x131c1b);*/
			_hud.add(_score);
			if (FlxG.scores == null) {
				FlxG.scores = new int[2] { 0,0 };
			}

			//Then for the player's highest and last scores
			if(FlxG.score > (int)FlxG.scores.GetValue(0))
				FlxG.scores.SetValue(0, FlxG.score);
			if((int)FlxG.scores.GetValue(0) != 0)
			{
				_score2 = new FlxText(FlxG.width/2,0,FlxG.width/2);
				//_score2.setFormat(null,8,0xd8eba2,"right",_score.getShadow());
				_hud.add(_score2);
				_score2.text = "HIGHEST: "+FlxG.scores.GetValue(0)+"\nLAST: "+FlxG.score;
			}
			FlxG.score = 0;
			_scoreTimer = 0;

			//Then we create the "gun jammed" notification
			_gunjam = new FlxGroup();
			_gunjam.add(new FlxSprite(0,FlxG.height-22).makeGraphic((uint)FlxG.width,24,Color.Orange));
			/*
			if(Gdx.app.getType() == ApplicationType.WebGL)
				_gunjam.add(new FlxText(0,FlxG.height-22,FlxG.width,"GUN IS JAMMED").setFormat(ImgFont20,20,0xd8eba2,"center"));
			else*/
			_gunjam.add(new FlxText(0,FlxG.height-22,FlxG.width,"GUN IS JAMMED"));/*.setFormat(null,16,0xd8eba2,"center"));*/
			_gunjam.Visible = false;
			_hud.add(_gunjam);

			//After we add all the objects to the HUD, we can go through
			//and set any property we want on all the objects we added
			//with this sweet function.  In this case, we want to set
			//the scroll factors to zero, to make sure the HUD doesn't
			//wiggle around while we play.
			_hud.SetAll("ScrollFactor",new FlxPoint(0,0));
			_hud.SetAll("Cameras",new List<FlxCamera> {FlxG.camera});

			/*FlxG.playMusic(SndMode);*/
			FlxG.flash(Color.White);
			_fading = false;

			//Debugger Watch examples
			FlxG.watch(_player,"x");
			FlxG.watch(_player,"y");
			//FlxG.watch(FlxG.class,"score");
		}
コード例 #9
0
		public override void destroy()
		{
			base.destroy();

			_blocks = null;
			_decorations = null;
			_bullets = null;
			_player = null;
			_enemies = null;
			_spawners = null;
			_enemyBullets = null;
			_littleGibs = null;
			_bigGibs = null;
			_hud = null;
			_gunjam = null;

			//meta groups, to help speed up collisions
			_objects = null;
			_hazards = null;

			//HUD/User Interface stuff
			_score = null;
			_score2 = null;
			
			//_pad = null;
		}
コード例 #10
0
		/*private FlxVirtualPad _pad;*/

		
		public override void create()
		{
			FlxG.width = (int)FlxG.camera.Width;// ViewportWidth;
			FlxG.resetCameras();
			
			FlxG.bgColor = Color.Black;

			//Simple use of flixel save game object.
			//Tracks number of times the game has been played.
			/*FlxSave save = new FlxSave();
			if(save.bind("Mode"))
			{
				if(save.data.get("plays", Integer.class) == null)
					save.data.put("plays", 0);
				else
					save.data.put("plays", save.data.get("plays", Integer.class) + 1);
				FlxG.log("Number of plays: "+save.data.get("plays", Integer.class));
				//save.erase();
				save.close();
			}
			*/

			//All the bits that blow up when the text smooshes together
			gibs = new FlxEmitter(FlxG.width/2-50,FlxG.height/2-10);
			gibs.setSize(100,30);
			gibs.setYSpeed(-200,-20);
			gibs.setRotation(-720,720);
			gibs.gravity = 100;
			gibs.makeParticles(ImgGibs,650,32,true,0);
			add(gibs);

			//the letters "mo"
			title1 = new FlxText(FlxG.width + 16,FlxG.height/3,64,"mo");
			/*
			if(Gdx.app.getType() == ApplicationType.WebGL)
				title1.setFormat(ImgFont40, 40);
			else 
				title1.SetSize(32);
			title1.SetColor(0x3a5c39);
			title1.Antialiasing = true;
			*/
			title1.Velocity.X = -FlxG.width;
			title1.Moves = true;
			add(title1);

			//the letters "de"
			title2 = new FlxText(-60,title1.Y,(int) title1.Width,"de");
			/*
			if(Gdx.app.getType() == ApplicationType.WebGL)
				title2.setFormat(ImgFont40, 40);
			else 
				title2.SetSize(32);

			title2.SetColor(title1.GetColor());
			title2.Antialiasing = title1.Antialiasing;
			*/
			title2.Velocity.X = FlxG.width;
			title2.Moves = true;
			add(title2);

			fading = false;
			timer = 0;
			attractMode = false;
				
			//FlxG.mouse.show(FlxS.ContentManager.Load<Texture2D>(ImgCursor),2);
			/*
			_pad = new FlxVirtualPad(FlxVirtualPad.DPAD_None, FlxVirtualPad.A_B);
			_pad.setAlpha(0.5f);

			if(Gdx.app.getType() != ApplicationType.Desktop)
				add(_pad);
				*/
		}
コード例 #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
		public override void destroy()
		{
			base.destroy();
			gibs = null;
			/*playButton = null;*/
			title1 = null;
			title2 = null;
		}
コード例 #13
0
ファイル: FlxButton.cs プロジェクト: IndrekV/MonoFlixel
        public override void destroy()
        {
            /*
            if(FlxG.getStage() != null)
                FlxG.getStage().removeEventListener(MouseEvent.MOUSE_UP, mouseUpListener);
            */

            if (FlxG.mouse != null)
                FlxG.mouse.removeMouseListener(OnMouseUp);

            if(Label != null)
            {
                Label.destroy();
                Label = null;
            }
            /*
            OnUp = null;
            OnDown = null;
            OnOut = null;
            OnOver = null;
            */
            if(SoundOver != null)
                SoundOver.destroy();
            if(SoundOut != null)
                SoundOut.destroy();
            if(SoundDown != null)
                SoundDown.destroy();
            if(SoundUp != null)
                SoundUp.destroy();
            base.destroy();
        }
コード例 #14
0
ファイル: FlxButton.cs プロジェクト: IndrekV/MonoFlixel
        /**
         * Creates a new <code>FlxButton</code> object with a gray background and a
         * callback function on the UI thread.
         *
         * @param X The X position of the button.
         * @param Y The Y position of the button.
         * @param Label The text that you want to appear on the button.
         * @param OnClick The function to call whenever the button is clicked.
         */
        public FlxButton(float x = 0, float y = 0, String label = null, FlxButtonEvent Callback = null)
            : base(x, y)
        {
            if(label != null)
            {
                Label = new FlxText(x-1, y+3, 80, label);
                Label.setFormat(null, 8, new Color(0x33,0x33,0x33), "center", Color.Transparent);
                LabelOffset = new FlxPoint(-1, 3);
            }
            loadGraphic(ImgDefaultButton, true, false, 80, 20);
            _callback = Callback;
            /*
            onUp = OnClick;

            onDown = null;
            onOut = null;
            onOver = null;
            */
            SoundOver = null;
            SoundOut = null;
            SoundDown = null;
            SoundUp = null;

            Status = Normal;
            _onToggle = false;
            _pressed = false;
            _initialized = false;
        }