OK, I’ve been trying to make a simple side scrolling kinda game today, and right now, I’m trying to make him (the character) jump.
The idea is, when you press the Control button, he hops. Then stops. Remember that last part, its important. He’s supposed to STOP. lol. But the little turd just keeps hopping…sooo, here I am, looking for YOUR help!
Here’s my code, I bolded the jumping code and the variables pertaining to it, now who can help me with this? I’m guessing this is a logic error, I tend to do that sometimes when I’m not wearing my helmet lol
onClipEvent(load) {
gravity = 2.6;
left = 0;
top = 0;
bottom = 150;
right = 550;
**speedy = 5;**
speedx = 5;
**jumping = false;**
}
onClipEvent(enterFrame) {
// Keyboard movement
if(Key.isDown(Key.LEFT)) {
if(this._xscale = -100) {
this._xscale = this._xscale;
} else {
this._xscale = 100;
}
this._x -= speedx;
}
if(Key.isDown(Key.RIGHT)) {
if(this._xscale = 100) {
this._xscale = this._xscale;
} else {
this._xscale = -100;
}
this._x += speedx;
}
**// Jumping
if(Key.isDown(Key.CONTROL) && (jumping = false)) {
jumping = true;
}
if(jumping = true) {
this._y -= speedy;
speedy--;
}
// Wall collisions
if(this._y > bottom) {
this._y = bottom;
jumping = false;
speedy = 5;
}**
if(this._x - _width/2 < left) {
this._x = left + _width/2;
}
if(this._x + _width/2 > right) {
this._x = right - _width/2;
}
// Door events
if(hitTest(_root.door1)) {
_root.stats = "<space>";
this._alpha = 100;
if(Key.isDown(Key.SPACE)) {
_root.stats = "Door Opened!";
this._alpha = 75;
}
} else {
_root.stats = "Welcome to my game! For help, hit your [ESC] key!";
this._alpha = 100;
}
}
</space>