akahan
07-19-2005, 06:20 PM
Okay, so im spoofing a Mario game and i have my guy running around stuff, but i cant get him to jump, when i hit the jump button, the guy goes into the air and does not come down. So i put gravity on, but when i do, the guy falls through my ground. Here is the code for the MCon (keyPress "<Right>"){
_root.ball._x+=5;
this.play();
this._xscale=100;
}
on (keyPress "<Left>"){
if(_root.ball._x>=7){
this.play();
_root.ball._x-=5;
this._xscale=-100;
}
}
onClipEvent (load) {
// gravity is what I called g in the tutorial. The
// higher g the harder the ball will fall.
// gravity = 0 can be set, as an experiment, but
// it will in fact create a "zero gravity" effect
// gravity < 0 will create an inverted gravity effect
gravity = 2 ;
// We set the speed of the ball when it is released.
speedx = 0 ;
speedy = 0 ;
}
onClipEvent (enterFrame) {
this._y-=_root.gravity
if (_root.jumping == "yes") {
_root.gravity -=.5
}
// We calculate the increase of speed
// speedx doesn't change
if(_root.fall==true){
speedy = speedy + gravity ;
// We move the ball.
// speed/5 just makes the motion slower
this._x += speedx/5 ;
this._y += speedy/5 ;
}}
onClipEvent (load) {
Jump = false;
Jumpable = true;
JumpCount = 0;
Gravity = 0;
}
onClipEvent (enterFrame) {
_y += Gravity;
//If you havent hit the bottom of the block//
if (_root.ball.hitTest(_x, _y, true)) {
Jumping = false;
Jump = false;
Gravity = 0;
} else {
if (Gravity<16) {
Gravity += 1;
} else {
Gravity = 16;
}
}
if (Key.isDown(Key.RIGHT)) {
if (not (_root.grounds.hitTest(_x+(_width/2), _y-(_height/2), true))) {
_x += 4;
}
}
if (Key.isDown(Key.LEFT)) {
if (not (_root.grounds.hitTest(_x-(_width/2), _y-(_height/2), true))) {
_x -= 4;
}
}
if (Key.isDown(Key.SPACE)) {
if (Jump == false && Jumping == false) {
Jump = true;
Jumping = true;
}
if (Jump) {
Jumping = true;
}
} else {
Jump = false;
}
if (Jumping == true) {
_y -= 8;
}
}
here is the frame code
_root.move=true;
_root.fall=true;
gravity=0
jumping="no"
function grounds() {
Gravity = 2;
Falling = "no";
ball._y -= (ball._y-Position);
}
function grounds() {
if (Motion > 0) {
ball._x -= Motion
Motion *= -1
} else if (Motion < 0) {
ball._x -= Motion
Motion *= -1
}
}
And here is the grounds code
onClipEvent(enterFrame){
if (this.hitTest(_root.ball)){
_root.fall=false;
_root.Jumping="no"
}}
//This statement looks to see if character is touching the objects
Any help is appreciated.
Also, how do i make it so i have to have my guy jump over certain things he cant just walk over them? I have done a hittest but cant figure out anything after that. Thanks for the help
_root.ball._x+=5;
this.play();
this._xscale=100;
}
on (keyPress "<Left>"){
if(_root.ball._x>=7){
this.play();
_root.ball._x-=5;
this._xscale=-100;
}
}
onClipEvent (load) {
// gravity is what I called g in the tutorial. The
// higher g the harder the ball will fall.
// gravity = 0 can be set, as an experiment, but
// it will in fact create a "zero gravity" effect
// gravity < 0 will create an inverted gravity effect
gravity = 2 ;
// We set the speed of the ball when it is released.
speedx = 0 ;
speedy = 0 ;
}
onClipEvent (enterFrame) {
this._y-=_root.gravity
if (_root.jumping == "yes") {
_root.gravity -=.5
}
// We calculate the increase of speed
// speedx doesn't change
if(_root.fall==true){
speedy = speedy + gravity ;
// We move the ball.
// speed/5 just makes the motion slower
this._x += speedx/5 ;
this._y += speedy/5 ;
}}
onClipEvent (load) {
Jump = false;
Jumpable = true;
JumpCount = 0;
Gravity = 0;
}
onClipEvent (enterFrame) {
_y += Gravity;
//If you havent hit the bottom of the block//
if (_root.ball.hitTest(_x, _y, true)) {
Jumping = false;
Jump = false;
Gravity = 0;
} else {
if (Gravity<16) {
Gravity += 1;
} else {
Gravity = 16;
}
}
if (Key.isDown(Key.RIGHT)) {
if (not (_root.grounds.hitTest(_x+(_width/2), _y-(_height/2), true))) {
_x += 4;
}
}
if (Key.isDown(Key.LEFT)) {
if (not (_root.grounds.hitTest(_x-(_width/2), _y-(_height/2), true))) {
_x -= 4;
}
}
if (Key.isDown(Key.SPACE)) {
if (Jump == false && Jumping == false) {
Jump = true;
Jumping = true;
}
if (Jump) {
Jumping = true;
}
} else {
Jump = false;
}
if (Jumping == true) {
_y -= 8;
}
}
here is the frame code
_root.move=true;
_root.fall=true;
gravity=0
jumping="no"
function grounds() {
Gravity = 2;
Falling = "no";
ball._y -= (ball._y-Position);
}
function grounds() {
if (Motion > 0) {
ball._x -= Motion
Motion *= -1
} else if (Motion < 0) {
ball._x -= Motion
Motion *= -1
}
}
And here is the grounds code
onClipEvent(enterFrame){
if (this.hitTest(_root.ball)){
_root.fall=false;
_root.Jumping="no"
}}
//This statement looks to see if character is touching the objects
Any help is appreciated.
Also, how do i make it so i have to have my guy jump over certain things he cant just walk over them? I have done a hittest but cant figure out anything after that. Thanks for the help