Code Snippets

  

ActionScript Source Code


Welcome to Dream.In.Code
Become an Expert!

Join 137,219 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,240 people online right now. Registration is fast and FREE... Join Now!





Make a person move and add gravity to it.

how to add gravity when a person you made jumps so that he falls back down (like Mario). this also includes how to make the person move using the arrow keys.

Submitted By: seandude
Actions:
Rating:
Views: 115

Language: ActionScript

Last Modified: October 8, 2008
Instructions: first you have to make the guy in your game and when you convert him to simple then you want the registration on the bottom middle so that he doesn't float away. this also includes the person moving with the arrow keys.

Snippet


  1. onClipEvent(load) {
  2.         falling=false;
  3.         hitting=false;
  4.         gravity=7;
  5.         speed=6;
  6.         jump=0;
  7.         jumping=false;
  8. }
  9. onClipEvent(enterFrame) {
  10.         if(!_root.ground.hitTest(this._x, this._y, true) && !jumping) {
  11.                 _y+=gravity;
  12.                 gravity=7;
  13.                 falling=true;
  14.         }
  15.         if(Key.isDown(Key.SPACE) && jumping==false) {
  16.                 jumping=true;
  17.                 luigi.play();
  18.         }
  19.         if(jumping) {
  20.                 this.gotoAndStop("jump")
  21.                 this._y-=jump;
  22.                 jump-=.5;
  23.                 if(jump<0) {
  24.                         falling=true;
  25.                 }
  26.                 if(jump<-15) {
  27.                         jump=-15;
  28.                 }
  29.         }
  30.         if(_root.ground.hitTest(this._x, this._y, true) && falling) {
  31.                 jump=12;
  32.                 jumping=false;
  33.                 falling=false;
  34.         }
  35.         if(Key.isDown(Key.LEFT)) {
  36.                 _x-=speed;
  37.         }
  38.         if(Key.isDown(Key.RIGHT)) {
  39.                 _x+=speed;
  40.         }
  41.        
  42. }

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month