Пример #1
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();
		}