Groups | Blog | Home
all groups > flash actionscript > december 2006 >

flash actionscript : platformer


sk8morestudyless
12/17/2006 7:31:30 PM
i need help with this platformer im making

its a game like mario but with a stick man
i have platforms that go above the stage so when the "player" goes above a
sertain _y value the ground and platforms scroll downwards

but!!

i cant get it to scroll downwards below a sertain y value
it scrolls just fine but it goes way farther than i want it to

any help

heres the code



onClipEvent(load){
speed=20
}


onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_x+=speed
gotoAndStop(2);
_xscale=+100
}
else if (Key.isDown(Key.LEFT)) {
_x-=speed
gotoAndStop(2);
_xscale=-100
}
else{
gotoAndStop(1)
}
}
onClipEvent(enterFrame){
_y+=10
if(_y<=59){
_root.ground._y+=10
}

if(_root.wallr.hitTest(_x,_y,true)){
_root.ground._x-=20
_root.bg._x-=5
_x-=20
}
if(_root.walll.hitTest(_x,_y,true)){
_root.ground._x+=20
_root.bg._x+=0
_x+=20
}
if(_root.ground.endwr.hitTest(_x,_y,true)){
_x-=20
gotoAndStop(1)
jumping=true
}
if(_root.ground.endwl.hitTest(_x,_y,true)){
_x+=20
gotoAndStop(1)
jumping=true
}
if(this.hitTest(_root.ground.goal)&&Key.isDown(Key.SHIFT)){
_root.gotoAndStop(2)
}

if(_root.ground.hitTest(_x,_y,true)){
_y-=10
jumping=false
touchg=true
jh=0
}

if(Key.isDown(Key.SPACE)&&!jumping){
jh=40
jumping=true
}
if(jumping==true){
jh-=2
if(jh<=-15){
jh=-15
}
_y-=jh
gotoAndPlay(3)
}



}
Bob Robertson
12/17/2006 11:07:20 PM
Well, general principles:
comment [i]everything[/i]. (<code>//<comment, or /*<comment>*/<code> .
declare and initialize variables before using them. (var foo=bar) . I learned
this the hard way.
it generally makes your code more readable if you break up your function and
variable names (fn_name(), or fnName())
also, indenting your code makes it much more readable, and is even done
automatically for you in the later versions
There should be a list of ActionScript 'Best Practices' floating around the
Adobe site somewhere...

As to your problem, I don't see any code which actually deals with scrolling
downward to debug. The logic should be similar, though:
if(character is below certain height [above certain _y value]){
scroll bg upward (decrease its _y value);
scroll ground upward (decrease its _y value);
if(test_for_landing()){
landing_action();
}
}

Just to make things conceptually easier, you might want to separate the
jumping action into two separate events: the jump, which propels the character
upward, and the fall, which accelerates the character downward. This, in turn,
leads you into the idea of states, which are a topic for another day, but very
worthy of your attention.
AddThis Social Bookmark Button