I am working on a simple sidescrolling "game" and am experiencing the following problems:
1) If the player lands while holding the jump button (space), he immediately jumps again. I've tried solving this on my own but I only introduced more problems :P
2) Sometimes the player sinks patially into the ground upon landing. I cant figure out why this happens exactly. Could it be a side effect of problem #1?
Here is my code (I have attached the fla as well):
ActionScript Code:
velocity = 0;
gravity = 0.7;
player = function () {
};
player.prototype = new MovieClip();
Object.registerClass("block", player);
player.prototype.onEnterFrame = function() {
walking = ground.hitTest(this._x, this._y, true);
if ((Key.isDown(Key.SPACE) && walking) || !walking) {
this._y -= velocity;
velocity -= gravity;
}
if (walking) {
velocity = 10;
}
if (Key.isDown(Key.RIGHT)) {
this._x += 5;
}
if (Key.isDown(Key.LEFT)) {
this._x -= 5;
}
};
_root.attachMovie("block", "player1", 1);
Also, this is one of my first attempts at object oriented programming. So if I'm doing something wrong in that area, please let me know.
Thanks for any and all help.