Jump Around
I’ve been tinkering with Sprites and the idea of making a silly little game in Flash with AS3, to flex (PUN?) my actionscript chops. This is the meagre progress I’ve made so far, and I thought I’d make it open source for all the world to gasp at my horrendous code. I’m currently at the “HOLY CRAP I MADE A CHARACTER THAT CAN JUMP USING AS3″ stage of development.
How about that linear jump? Needs some gravity love, eh?
SOURCE (71 KB, .zip)
You might have to click on the swf to give it focus and enable keyboard controls to move/jump. Shift+Left/Right to ‘run’ (*his legs don’t move*). No collision detection whatsoever, yet.
Below is the event handler I’m using for jumping, which is called on every frame after the user presses the up key, until the jump is complete:
var jumpDestination:Number = groundLevel - MAX_JUMP_HEIGHT;
// only attempt to stop the jump if you've already left the ground
if( inAir && y+height == groundLevel ){
dy = 0;
groundLevel = 0;
inAir = false;
removeEventListener(Event.ENTER_FRAME, jump);
return false;
}
if( y >= jumpDestination ){
inAir = true;
dy -= 4;
} else if( y <= jumpDestination ){
dy += 4;
}
}
Eh? Eh? I felt good after figuring that one out. Ahaha. Looking at it though, I think I should be stopping the jump based upon some collision detection. As it stands right now, it wouldn’t work if you wanted to jump onto something (since it will only stop the jump if you hit the point you’ve started at. Development is early, what can I say.


