home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / Jumper.swf / scripts / game / Jumper.as < prev    next >
Encoding:
Text File  |  2008-09-05  |  2.5 KB  |  98 lines

  1. package game
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.TimerEvent;
  5.    
  6.    public class Jumper extends GameObject
  7.    {
  8.       
  9.       public static var rightJumpImageClass:Class = Jumper_rightJumpImageClass;
  10.       
  11.       public static var leftJumpImageClass:Class = Jumper_leftJumpImageClass;
  12.       
  13.       public static var jumpImageClass:Class = Jumper_jumpImageClass;
  14.       
  15.       public static var imageClass:Class = Jumper_imageClass;
  16.        
  17.       
  18.       private var theGame:Game;
  19.       
  20.       public var overGoingPhase:int = 0;
  21.       
  22.       public function Jumper(theGame:Game, x:int, y:int, w:int, h:int)
  23.       {
  24.          super(x,y,w,h);
  25.          this.theGame = theGame;
  26.          ay = 0.18;
  27.          Game.timer.addEventListener("timer",move);
  28.       }
  29.       
  30.       override public function move(event:TimerEvent) : void
  31.       {
  32.          vx += ax;
  33.          vy += ay;
  34.          x += vx;
  35.          y += vy;
  36.          theGame.checkHit();
  37.          if(x < 0)
  38.          {
  39.             x = 0;
  40.          }
  41.          if(x + w > 640)
  42.          {
  43.             x = 640 - w;
  44.          }
  45.          if(overGoingPhase == 0)
  46.          {
  47.             if(y + h / 2 < 230 && vy < 0)
  48.             {
  49.                if(x + w / 2 < 330)
  50.                {
  51.                   overGoingPhase = 1;
  52.                }
  53.                if(x + w / 2 > 330)
  54.                {
  55.                   overGoingPhase = 2;
  56.                }
  57.             }
  58.          }
  59.          if(overGoingPhase != 0 && overGoingPhase != 3)
  60.          {
  61.             if(y + h / 2 > 240 && y + h / 2 < 250 && vy > 0)
  62.             {
  63.                if(overGoingPhase == 1 && x + w / 2 > 330 || overGoingPhase == 2 && x + w / 2 < 330)
  64.                {
  65.                   overGoingPhase = 4;
  66.                   theGame.wentOver();
  67.                }
  68.             }
  69.          }
  70.          dispatchEvent(new Event("objectChanged"));
  71.       }
  72.       
  73.       public function jump() : void
  74.       {
  75.          if(Game.powerup == 1)
  76.          {
  77.             vy = -9;
  78.          }
  79.          else
  80.          {
  81.             vy = -7.5;
  82.          }
  83.          if(vx < 0)
  84.          {
  85.             dispatchEvent(new GraphicsChangedEvent("graphicsChanged",leftJumpImageClass,32));
  86.          }
  87.          else if(vx > 0)
  88.          {
  89.             dispatchEvent(new GraphicsChangedEvent("graphicsChanged",rightJumpImageClass,32));
  90.          }
  91.          else
  92.          {
  93.             dispatchEvent(new GraphicsChangedEvent("graphicsChanged",jumpImageClass,32));
  94.          }
  95.       }
  96.    }
  97. }
  98.