//Code on main timeline, ensure that the registrations are correct; //leftwall(right), rightwall(left), platform(right), player(bottom). //Store each wall and platform names in arrays
var walls=["wall1","wall2","wall3"] //names of all walls on stage var platforms=["latform1","latform2","latform3"] //names of all platforms on stage var xspeed=0 //used to move the player horizontally var yspeed=0 //used to move the player vertically var maxspeed=2 var thrust=4 //how high your character jumps var maxfall=5 //top speed that your character falls var gravity=0.1 //acceleration due to gravity
//maxspeed, thrust, maxfall, and gravity can be tweaked to your preference
player.onEnterFrame=function():Void{ xspeed=(Key.isDown(Key.RIGHT)-Key.isDown(Key.LEFT))*maxspeed player._x+=xspeed if(yspeed<maxfall){ //if player is not falling at maximum fallspeed yspeed+=gravity //accelerate player downwards } for(i=1;i<=walls.length;i++){ //for each entry in walls array if(_root[walls[i-1]].hitTest(player)){ //if the entry hits the player if(player._x>_root[walls[i-1]]._x){ //if player is to the right of the wall player._x+=maxspeed //push the player right }else{ player._x-=maxspeed //else push the player left } } } for(i=1;i<=platforms.length;i++){ //for each entry in platforms array ydiff=player._y-_root[platforms[i-1]]._y //how far the player overlaps the platform if(_root[platforms[i-1]].hitTest(player)&&ydiff<maxfall){ //if platform hits player and the overlap is less that maxfall player._y-=ydiff //move player to cancel out the overlap yspeed=0 //stop the vertical movement if(Key.isDown(Key.UP)){ yspeed=-thrust //jumping action is placed within the collosion detector to make sure player only jumps when stood on a platform } } } player._y+=yspeed }
//Code on main timeline, ensure that the registrations are correct; //leftwall(right), rightwall(left), platform(right), player(bottom). //Store each wall and platform names in arrays
sorry thats wrong, when I first wrote the post I was going to separate walls into left wall and right wall, you just need 'wall' and its registration point does not matter
Sorry for triple post, the registration for platforms should be up, not right
so
//Code on main timeline, ensure that the registrations are correct; //leftwall(right), rightwall(left), platform(right), player(bottom). //Store each wall and platform names in arrays
should be...
//Code on main timeline, ensure that the registrations are correct; //platform(up), player(bottom). //Store each wall and platform names in arrays
can a mod replace it for me and delete unneeded posts please >.<