Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Sep 2nd, 2010 | Syntax: ActionScript | Size: 1.14 KB | Hits: 19 | Expires: Never
Copy text to clipboard
  1. onClipEvent (load) {
  2.         speed = 8;
  3.         gravity = 0;
  4.         r = _height/1.2;
  5.         jumping = false;
  6.         var scale:Number = _xscale;
  7.         jumpheight = 15;
  8.         running = false;
  9.         var touchingGround = false;
  10.  
  11. }
  12. onClipEvent (enterFrame) {
  13.         if (Key.isDown(Key.RIGHT)) {
  14.                 _xscale = +scale;
  15.                         if(touchingGround == true) {
  16.                                 this.character.gotoAndStop(2);
  17.                         }
  18.                 _x += speed;
  19.         } else if (Key.isDown(Key.LEFT)) {
  20.                 _xscale = -scale;
  21.                         if(touchingGround == true) {
  22.                                 this.character.gotoAndStop(2);
  23.                         }
  24.                 _x -= speed;
  25.         } else {
  26.                 if (touchingGround == true) {
  27.                         this.character.gotoAndStop(1);
  28.                 }
  29.         }
  30.         if (Key.isDown(Key.UP) && !jumping) {
  31.                 gravity = -jumpheight;
  32.                 jumping = true;
  33.                 this.character.gotoAndStop(3);
  34.         }
  35.         if (!_root.ground.hitTest(_x, _y, true)) {
  36.                 gravity++;
  37.                 _y += gravity;
  38.                 touchingGround = false;
  39.         } else {
  40.                 jumping = false;
  41.                 touchingGround = true;
  42.                 gravity = 0;
  43.         }
  44.         while (_root.ground.hitTest(_x, _y-1+r, true)) {
  45.                 gravity = 0;
  46.                 jumping = false;
  47.                 _y--;
  48.                 touchingGround = true;
  49.         }
  50.         if(touchingGround == false){
  51.                 this.character.gotoAndStop(3);
  52.         }
  53.         if(gravity > 1 || gravity < 0){
  54.                 this.character.gotoAndStop(3);
  55.         }
  56. }