?
Solved

Platformer Game

Posted on 2003-03-20
5
Medium Priority
?
192 Views
Last Modified: 2010-04-03
I need help so when you reach the end of a platform, the player will fall off. Currently I have the jump code with the ground as a hittest. Also I would like this code to a background scroller. (I already have the background scrolling code, and the instance name for it is a) Thanks.
0
Comment
Question by:Ninfox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 6

Expert Comment

by:henryww
ID: 8176969
.... need more info.
can u post some code and tell us exactly what's the problem.
0
 

Author Comment

by:Ninfox
ID: 8178001
Ok heres the character movement/jump code, (I know its pretty basic)

onClipEvent (enterFrame) {
    if (Key.isDown(Key.RIGHT)) {
        this._x += 5;
    } else if (Key.isDown(Key.LEFT)) {
        this._x -= 5;
    }
}
onClipEvent (load) {
    vel_y = 0;
    jumping = false;
}
onClipEvent (enterFrame) {
    if (Key.isDown(Key.Up) && !jumping) {
        vel_y = 20;
        jumping = true;
    }
    if (jumping == true) {
        vel_y -= 1;
        if (vel_y<=-10) {
            vel_y = -10;
        }
        this._y -= vel_y;
    }
    if (_root.b.ground.hitTest(this._x, this._y+45, true)) {
        vel_y = 0;
        jumping = false;
    }
}

b.ground is the ground and the whole B is the background scroll code (onClipEvent (enterFrame) {
    if (_root.c._x>200) {
        this._x -= 10;
        _root.c._x -= 10;
    }
    if (_root.c._x<100) {
        this._x += 10;
        _root.c._x += 10;
    }
}
)

Anyway, I want to know if there is any way I can edit the code so when there is no hittest of the ground the char. will fall off. Thanks again.
0
 
LVL 6

Accepted Solution

by:
henryww earned 300 total points
ID: 8187642
oh i see ...
so it is kind of like jumping from one block to another and if there is no "ground" the char will fall ...


// see u have already got this to check for the ground ..
if (_root.b.ground.hitTest(this._x, this._y+45, true)) {
   vel_y = 0;
   jumping = false;
}

just use the hitTest again to check if the char stands on anything ... but u will have to make multiple MCs for the ground and check them one by one (loop in a function)

i am not sure how is ur "ground" movieclip going to look like, ... but try this simple way

onClipEvent (enterFrame) {
   if (Key.isDown(Key.RIGHT)) {
       this._x += 5;
   } else if (Key.isDown(Key.LEFT)) {
       this._x -= 5;
   }
// if it is not jumping and the hitTest fail ... so it should fall ...
   if (! ( jumping  ||  _root.b.ground.hitTest(this._x, this._y+45, true))){
      this._y -=2
   }
}
0
 

Author Comment

by:Ninfox
ID: 8188456
Hey thanks Heres the final code, you only have one mistake!(if the Y was negative the player goes up, weird) I wish I had more points but I dont sorry. Thanks again man.

onClipEvent (enterFrame) {
  if (Key.isDown(Key.RIGHT)) {
      this._x += 5;
  } else if (Key.isDown(Key.LEFT)) {
      this._x -= 5;
  }
// if it is not jumping and the hitTest fail ... so it should fall ...
  if (! ( jumping  ||  _root.b.ground.hitTest(this._x, this._y+45, true))){
     this._y +=2
  }
}
onClipEvent (enterFrame) {
     if (Key.isDown(Key.Up) && !jumping) {
          vel_y = 20;
          jumping = true;
     }
     if (jumping == true) {
          vel_y -= 1;
          if (vel_y<=-10) {
               vel_y = -10;
          }
          this._y -= vel_y;
     }
     if (_root.b.ground.hitTest(this._x, this._y+45, true)) {
          vel_y = 0;
          jumping = false;
     }
}
0
 
LVL 6

Expert Comment

by:henryww
ID: 8189211
yeah that's right ... i forgot ... it should be y+=2 ... to go down :)

cheers
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question