-
Help with Platform Game actionscript
I'm a newbie with actionscipt so sorry if the problem is really simple. I'm working on a platform game (Like super mario) and I have a hero, "man" and a platform. You can move left and right with the arrow keys and jump with the up arrow. My problem is that when I jump, my hero keeps on falling past the platform beacuse the hitTest doesn't seem to be working.
Code in frame, it is filled with functions that the mc calls:
Code:
stop();
function initGame() {
speed = 5;
bounce = 5;
JumpMax = 10;
JumpSpeed = 0;
flight = 0;
}
//-------------------------------------------------------|
//Movement-----------------------------------------------|
//-------------------------------------------------------|
function moveMan() {
if (Key.isDown(Key.RIGHT)) {
man._x = man._x+speed;
man.gotoAndStop("moveright");
} else if (Key.isDown(Key.LEFT)) {
man._x = man._x-speed;
man.gotoAndStop("moveleft");
} else if (Key.isDown(Key.UP)) {
if (flight == 0) {
flight = 1;
JumpSpeed = JumpMax;
}
} else {
man.gotoAndStop("normal");
}
if (flight == 1) {
man._y = man._y-JumpSpeed;
if (JumpSpeed>(0-20)) {
JumpSpeed = JumpSpeed-1;
}
}
//-------------------------------------------------------|
//Boundries----------------------------------------------|
//-------------------------------------------------------|
if (man.hitTest(north)) {
man._y = man._y+bounce;
speed = 0;
JumpSpeed = 0;
} else if (man.hitTest(south)) {
man._y = man._y-bounce;
speed = 0;
JumpSpeed = 0;
} else if (man.hitTest(west)) {
man._x = man._x+bounce;
speed = 0;
JumpSpeed = 0;
} else if (man.hitTest(east)) {
man._x = man._x-bounce;
speed = 0;
JumpSpeed = 0;
}
}
speed is the speed for moving left and right, JumpSpeed is for jumping. flight is either 0 or 1, it tells whether the character is jumping at the moment or not.
This is in the platform MC:
Code:
onClipEvent (enterFrame) {
if (flight == 1) {
if (me.hitTest(man._x, man._y, true)) {
flight = 0;
JumpSpeed = 0;
man._y = me._y;
}
}
}
Do you see any problems?
Thanks,
Eastwinn
PS: I'm running on Flash MX Pro 2004
-
Senior Member
Hi
maybe this on platform...
code: onClipEvent (enterFrame) {
if (flight == 1) {
if (this.hitTest(man._x, man._y, true)) {
flight = 0;
JumpSpeed = 0;
man._y = me._y;
}
}
}
Or post a basic of your fla i will take a look for you
-
oh, I see what I did wrong. In another laugage I use called visual basic, to refrence the object the code is refering to, you use "me" instead of "this". Thank you so much! Now I can get to the fun part of the game, making the levels...
[EDIT]: For some reason, it still won't work. The character jumps perfetly, it is just when he gets to the platform, he keeps falling. I'll post the fla later.
Last edited by Eastwinn; 12-19-2005 at 12:01 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|