ForumsProgramming ForumDoes anyone have a good wall code and platform code for a platform

7 3488
Midmenj
offline
Midmenj
216 posts
Nomad

Any would be good.

  • 7 Replies
BeastMode10
offline
BeastMode10
374 posts
Nomad

Google it?

I doubt that someone would give out their source code for free, unless you know them or pay them, or something.

You can probably find tutorials for basic games on the internet, but don't expect to receive an actual, submittable game.

PrideRage
offline
PrideRage
148 posts
Nomad

I know there a little thing which would be useful, it's hitTest.
I don't know how to use it :P but it checks collision afaik.
Just google for that.

PixelSmash
offline
PixelSmash
566 posts
Nomad

Well, a quick search gave me this link... looks like something you could use, I think

driejen
offline
driejen
486 posts
Nomad

//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=[&quotlatform1",&quotlatform2",&quotlatform3"] //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
}

driejen
offline
driejen
486 posts
Nomad

//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
driejen
offline
driejen
486 posts
Nomad

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 >.<
Midmenj
offline
Midmenj
216 posts
Nomad

haha thanks man

Showing 1-7 of 7