Log in
Please log in or register.
Pages: [1]
  Print  
Author Topic: TUTORIAL: mode Jetpack Mod  (Read 6513 times)
adamrobo
Newbie
*
Posts: 10



View Profile WWW
« on: Sun, Jun 7, 2009 »

I figure one of the best ways to learn Flixel is to attempt some mods to the already awesome mode. This mod will add jetpack functionality and a particle emitter to the player character.

I'm a newbie to AS3 (and to making games for the most part), so feel free to offer suggestions on how to clean up the code.



Play the Jetpack Mod

Update 06/08/09: Added code to kill the jets in step four.



The only file you will be altering for this tutorial is Player.as

1. Open Player.as

2. In the Player class, embed the jet image that is currently being used for the enemies.

Code:
[Embed(source="../../../data/jet.png")] private var ImgJet:Class;

3. Also in the Player class, add some variables. _boosters will keep track of whether the jetpack is on or not. _fuel will keep track of how much juice is in the tank. _jets will emit particles and make you look cool.

Code:
private var _boosters:Boolean;
private var _fuel:int;
private var _jets:FlxEmitter;

4. In the Player function, set the values of _fuel and _jets. Kill the jets so they aren't firing when the game starts.

Code:
_fuel = 500;
_jets = FlxG.state.add(new FlxEmitter(0,0,0,0,null,0.01,-10,10,20,50,0,0,0,0,ImgJet,15)) as FlxEmitter;
_jets.kill();

The code for the rest of the steps should be placed in the update function.

5. If you are holding down the jump button and are at the height of your jump, turn on boosters and start the jets. Starting the jets will make particles start shooting out.

Code:
if(FlxG.kA && (velocity.y >= -40 && velocity.y <= 20))
{
_boosters = true;
_jets.reset()
}

6. If the boosters are on and you let go of the jump button, turn the boosters off and kill the jets.

Code:
if(_boosters && !FlxG.kA)
{
_boosters = false;
_jets.kill();
}

7. If the boosters are on and you have fuel, make the player go up, drain fuel, and center the jets on the x and y position of player.

Code:
if(_boosters && _fuel>0)
{
velocity.y = -70;
_fuel += -10;
_jets.y = this.y;
_jets.x = this.x + 3;
}

8. If the boosters are off and fuel isn't maxed out, increase the fuel.

Code:
if(!_boosters && _fuel<400)
{
_fuel += 20;
}

9. Save, compile, and play.  Cheesy



That's it! 9 easy steps.

I think I might work on this a bit more and add a fuel gauge to the HUD.
« Last Edit: Mon, Jun 8, 2009 by adamrobo » Logged

Adam Atomic
Administrator
Hero Member
*****
Posts: 724


hostest w/ the mostest


View Profile WWW
« Reply #1 on: Sun, Jun 7, 2009 »

Awesome!!  Can you link to a playable version of this on the web somewhere?  Or did I just miss the link
Logged

adamrobo
Newbie
*
Posts: 10



View Profile WWW
« Reply #2 on: Sun, Jun 7, 2009 »

Good call, Adam. I just added a link and a screenshot to the tut above.

You can play the game at http://www.adamrobezzoli.com/flixel/mode-jetpack-mod/
Logged

PhantomTollbooth
Newbie
*
Posts: 15


View Profile
« Reply #3 on: Sun, Jun 7, 2009 »

Totally awesome, you have earned several points of respect
Logged
Adam Atomic
Administrator
Hero Member
*****
Posts: 724


hostest w/ the mostest


View Profile WWW
« Reply #4 on: Sun, Jun 7, 2009 »

mad props adamrobo Cheesy  added it to the official help resources thread
Logged

adamrobo
Newbie
*
Posts: 10



View Profile WWW
« Reply #5 on: Sun, Jun 7, 2009 »

Thanks, guys!

I'm going to attempt a few more mods. As long as they are successful, I'll be sure to post them too.
Logged

SMRobot
Newbie
*
Posts: 14


View Profile
« Reply #6 on: Mon, Jun 8, 2009 »

This really helps avoid those situations where you can't quite make the jump to continue through the level.
Logged
Jazmeister
Newbie
*
Posts: 8


View Profile
« Reply #7 on: Mon, Jun 8, 2009 »

This really helps avoid those situations where you can't quite make the jump to continue through the level.

This is the only way I can even approach completing Mode.
Logged
Hot Trout
Newbie
*
Posts: 1


View Profile
« Reply #8 on: Wed, Jun 10, 2009 »

I had a bit of play around with the jetpack idea and thought I'd post my tweakings here:

This jetpack is fired by pressing jump again while in the air, however it only recharges when you're on the ground to stop you tapping boost indefinitely (although tapping still gets you the farthest, maybe the jetpack needs to boost for a little bit before hitting full power or a add a delay in re-triggering it)

This is my boosters section that sits in the player's update function:

I've repositioned the emitter on every update so I don't have to worry about where it is, just if it's firing or not. I've also tied it to the facingRight boolean, so I can place it under his backpack when he turns around.
Code:
//BOOSTERS
_jets.y = this.y + 2;
if(facingRight) _jets.x = this.x + 1;
else _jets.x = this.x + 5;

Since I wanted the jetpack to fire at any point in the jump I used another bool to check if I should be making the player jump or if I should be firing the jetpack . Here I'm checking if the player's on the ground and disabling the jetpack.
Then I'm enabling it if the player just jumped or is falling
Code:

if (!velocity.y) {
_canBoost = false;
}
if (velocity.y && FlxG.justReleased(FlxG.A)) {
_canBoost = true;
}
if (velocity.y > 0) {
_canBoost = true;
}


Here we're firing the jetpack if jump was just pushed (not if it's just still being held down) whilst we're not boosting but can boost and stopping as soon as jump isn't held anymore or we run out of fuel.
Code:

if(FlxG.justPressed(FlxG.A) && !_boosters && _canBoost) {
_boosters = true;
_jets.reset();

}
if(!FlxG.kA && _boosters)
{
_boosters = false;
_jets.kill();
}
if (_boosters && _fuel <= 0) {
_boosters = false;
_jets.kill();
}

I added some more vars for the jetpack's settings so I could fiddle with different jetpack settings, these are all set in the Player function the same as _fuel.
Here's my fuel stuff, only recharge when we're back on the ground and an extra always triggered test to see if we have more fuel than max in case we've run over _fuelMax anywhere.
Code:
if(!_boosters && _fuel < _fuelMax && !velocity.y) {
_fuel += _fuelRecharge;
}

if(_fuel > _fuelMax) _fuel = _fuelMax;

if (_boosters && _fuel > 0) {
velocity.y = -_boostersStrength;
_fuel += -_fuelCost;
}

And lastly I stuck a _jets.kill() in the player death function at the bottom in case they're boosting when they die (it leaves the emitter hanging around otherwise)

Big thanks to adamrobo for this tut, it's given me the flixel bug now!  Smiley
Logged
Jazmeister
Newbie
*
Posts: 8


View Profile
« Reply #9 on: Sun, Sep 13, 2009 »

Can't find player.as. Anyone know why? Using FlashDevelop 3.03, flex 3.4.0.9271, and Flixel 1.25. So far I've followed the Flixel zip-into-the-right-folder tutorial and the configuring Flashdevelop thing from the FD wiki, I got vanilla mode to run fine. So... player.as?

Edit: I worked this out. It's under com, adamatomic, mode, player.as. Oh dear.
« Last Edit: Sun, Sep 13, 2009 by Jazmeister » Logged
thurg boo
Newbie
*
Posts: 2


View Profile
« Reply #10 on: Sun, Dec 20, 2009 »

Every time I try to compile these additions to the code I get a number of errors, starting with this one:

Code:
Loading configuration file /home/noah/code/flash/flex_sdk_3.4/frameworks/flex-config.xml
/home/noah/code/flash/Mode/com/adamatomic/Mode/Player.as(39): col: 89 Error: Incorrect number of arguments.  Expected no more than 3.

_jets = FlxG.state.add(new FlxEmitter(0,0,0,0,null,0.01,-10,10,20,50,0,0,0,0,ImgJet,15)) as FlxEmitter;

I think I've searched the code pretty well for syntax errors, but I'm a huge newbie so I could always be wrong. Does anyone have any ideas? Has anyone encountered this?
Logged
Rybar
Full Member
***
Posts: 219



View Profile
« Reply #11 on: Sun, Dec 20, 2009 »

The problem is that the code from that post is from an older version of flixel.  In flixel 1.40 and newer the constructors for all of flixel's classes have been greatly simplified.  Have you got Mode to compile without any problems? If so, take a look at how the FlxEmitter is set up in bot.as (The bad guy object in Mode).  That should give you a good idea of how to set up the emitter for the jetpack mod.  I may tackle porting the jetpack mod tutorial over to the wiki and updating the code to 1.4x in the next couple of days, meanwhile I'll run through this and post updated code.

 *EDIT: Here's the revised code for flixel 1.47.

variables:

Code:
private var _boosters:Boolean;
private var _canBoost:Boolean;
private var _fuel:int;
private var _jets:FlxEmitter;

Emitter setup:

Code:
//jetpack setup
_fuel = 5000;
_jets = new FlxEmitter(0,0,0.01);
_jets.gravity = 0;
_jets.setXVelocity( -10, 10)
_jets.setYVelocity(-100,0)
_jets.createSprites(ImgJet,15);
FlxG.state.add(_jets);
_jets.kill();

and the game logic -put in the update override:

Code:
                        _jets.y = this.y + 2;
if(facing == RIGHT) _jets.x = this.x + 1;
else _jets.x = this.x + 5;
if (!velocity.y) {
_canBoost = false;
}
if (velocity.y && FlxG.keys.justReleased("X")) {
_canBoost = true;
}
if (velocity.y > 0) {
_canBoost = true;
}
if(FlxG.keys.justPressed("X") && !_boosters && _canBoost) {
_boosters = true;
_jets.restart();

}
if(!FlxG.keys.X && _boosters)
{
_boosters = false;
_jets.kill();
}
if (_boosters && _fuel <= 0)
{
_boosters = false;
_jets.kill();
}
if(_boosters && _fuel>0)
{
velocity.y = -70;
_fuel += -10;
}
if(!_boosters && _fuel<400)
{
_fuel += 20;
}

From there you should be able to figure out how tweak it, I gave the player a lot more fuel (5000) and used most of Hot Trouts additional tweaks. Cheesy
« Last Edit: Sun, Dec 20, 2009 by Rybar » Logged
xmorpher
Newbie
*
Posts: 39


View Profile
« Reply #12 on: Mon, Dec 21, 2009 »

just a suggestion: don't UPDATE the tutorial... leave it as version 1.25 and create a new one for 1.4 please
Logged
Rybar
Full Member
***
Posts: 219



View Profile
« Reply #13 on: Mon, Dec 21, 2009 »

Well it doesn't exist on the wiki at all right now; if I do anything, it will be for the latest version only, as I really don't see the point of creating new or migrating support material for older versions. Of course this post will always be here for the 1.25 version.
Logged
thurg boo
Newbie
*
Posts: 2


View Profile
« Reply #14 on: Tue, Dec 22, 2009 »

Thanks a ton Rybar  Smiley
Logged
Pages: [1]
  Print  
 
Jump to: