Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Platformer Game

Posted on 2003-03-20
5
Medium Priority
?
194 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
  • 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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

579 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