PDA

View Full Version : [AS2] Problems with platform game (jumping and collision issues)


Amaster
09-14-2004, 09:20 PM
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):

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.

James_H1023
09-14-2004, 09:54 PM
i don't understand why don't you want it jump straight away does it bug or something?

i look at zip and see

Amaster
09-14-2004, 09:56 PM
Well, I would prefer if the player were forced to release and then press the spacebar again in order to perform a second jump, as opposed to simply holding down the key. Also I suspect it may be causing the second problem I listed.

James_H1023
09-14-2004, 09:59 PM
right ok me looking at your fla

James_H1023
09-14-2004, 10:11 PM
ok i have an idea, to stop the space bar thing repeating maybe put a variable in the space bar so when the space bar goes down it is 1 and when the space bar comes up it goes 0.

and the space bar code only runs when the var = 0;

duno how to check if space bar is up maybe a listener

Amaster
09-14-2004, 10:21 PM
I tried creating a listener object originally, and it did function properly (I traced it to make sure I set it up right), but I wasnt able to implement it in a useful manner. I just ended up with more weird bugs. Maybe I did it wrong.

Thanks for looking at the file though.

James_H1023
09-14-2004, 10:26 PM
yea i can only think that a listener listening for when it is up would do, can't think of another way although there probs is.

np