PDA

View Full Version : help with game plz


boburmum1
05-31-2008, 05:11 PM
i'm making a game in AS2 but when my char hits the menu he stops which he is supposed to. but when i press the up key or the left or right or down keys. it doesnt move anymore. here is my code.
onClipEvent(load){
speed=5;
}
onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)){
_x-=speed;
}
if(Key.isDown(Key.RIGHT)){
_x+=speed
}
if(Key.isDown(Key.UP)){
_y-=speed
}
if(Key.isDown(Key.DOWN)){
_y+=speed;
}
if(this.hitTest(_root.menu)){
speed=0;
}
}
if someone could help i would be really greatful. i've tried else if statements but it doesn't work for me.

rrh
05-31-2008, 09:42 PM
That's because you are changing speed to zero. You need to clearly define, under what conditions should you be able to move again? Maybe you want to check each direction separately, (using mc.hitTest(_x,_y,true)) and disable only the side that is touching the menu. Maybe you want a timer (using setInterval ) so it pauses for a moment before letting you continue again.

boburmum1
06-01-2008, 12:49 PM
i know how to do set interval

it's something likemyInterval = setInterval (disable,3000)

function disable() {
clearInterval(myInterval);
} but what would i put in between it?

boburmum1
06-03-2008, 05:31 PM
can anyone help!!!!!!PLZ!!!!!!!!

jason2d
06-03-2008, 05:55 PM
Where on the fla is the menu? for example if it was a right aligned menu, on the hit test instead of speed=0; put _y=-1. This means everytime you move into the menu, it will push you back one pixel but still allow you to move other directions. If you try to go into the menu again, same thing will happen.

VictorTheGamer
06-03-2008, 07:43 PM
Try this

I hope it helps

like the person below me said, you should have _y=-1

onClipEvent(load){
speed=5;
}
onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)){
_x-=speed;
}
if(Key.isDown(Key.RIGHT)){
_x+=speed
}
if(Key.isDown(Key.UP)){
_y-=speed
}
if(Key.isDown(Key.DOWN)){
_y+=speed;
}
if(this.hitTest(_root.menu)){
_y=-1;
}
}

boburmum1
06-03-2008, 08:30 PM
i tried that but _y-=1 sends it to the top of the page which i dont want. but now i am trying different things so it ends up back ion the same place as it does when you hit it.
EDIT: i changed it to _y=270; it bounces back a few pixels when it hits the menu. u know i gave up on the other game i was making before but noiw thx to u guys i am noiw nearly half way to finishing my game. thankyou so much

UknownXL
06-04-2008, 05:49 PM
Try this....

onClipEvent(load){
speed=5;
}
onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)){
_x-=speed;
}
if(Key.isDown(Key.RIGHT)){
_x+=speed
}
if(Key.isDown(Key.UP)){
_y-=speed
}
if(Key.isDown(Key.DOWN)){
_y+=speed;
}
if(this.hitTest(_root.menu)){
speed=0;
}else if(!this.hitTest(_root.menu)){
speed=5;
}
}

// that should work perfectly.