home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 145 / MOBICLIC145.ISO / pc / DATA / DSS145 / DSS145_12 / DSS145_12.swf / scripts / dss145_12 / Perso.as < prev    next >
Text File  |  2012-07-19  |  11KB  |  347 lines

  1. package dss145_12
  2. {
  3.    import flash.display.MovieClip;
  4.    
  5.    public class Perso
  6.    {
  7.       
  8.       public static const REST_RIGHT:String = "E1";
  9.       
  10.       public static const REST_LEFT:String = "E2";
  11.       
  12.       public static const WALK_RIGHT:String = "E3";
  13.       
  14.       public static const WALK_LEFT:String = "E4";
  15.       
  16.       public static const UPSTAIRS_STOP:String = "upstairs_stop";
  17.       
  18.       public static const GO_UP:String = "E5";
  19.       
  20.       public static const GO_DOWN:String = "E5";
  21.       
  22.       public static const CRAWL_RIGHT:String = "E7";
  23.       
  24.       public static const CRAWL_LEFT:String = "E8";
  25.       
  26.       public static const JUMP_INPLACE_RIGHT:String = "E9";
  27.       
  28.       public static const JUMP_INPLACE_LEFT:String = "E10";
  29.       
  30.       public static const DUCK_RIGHT:String = "E11";
  31.       
  32.       public static const DUCK_LEFT:String = "E12";
  33.       
  34.       public static const JUMP_RIGHT:String = "E13";
  35.       
  36.       public static const JUMP_LEFT:String = "E14";
  37.       
  38.       public static const FALL_RIGHT:String = "E15";
  39.       
  40.       public static const FALL_LEFT:String = "E16";
  41.       
  42.       public static const FALL_END_RIGHT:String = "fall_end_right";
  43.       
  44.       public static const FALL_END_LEFT:String = "fall_end_left";
  45.       
  46.       public static const JUMP_END:String = "jump_end";
  47.        
  48.       
  49.       public var invincible:Boolean = false;
  50.       
  51.       public var clip:MovieClip;
  52.       
  53.       public var distanceSol:Number = 67;
  54.       
  55.       public var distanceSolFall:Number = 40;
  56.       
  57.       public var xOriginal:Number = 0;
  58.       
  59.       public var yOriginal:Number = 0;
  60.       
  61.       public var x:Number = 0;
  62.       
  63.       public var y:Number = 0;
  64.       
  65.       public var speed:Number = 4;
  66.       
  67.       public var speedX:Number = 0;
  68.       
  69.       public var speedY:Number = 0;
  70.       
  71.       public var DECOR:Decor;
  72.       
  73.       public var state:String = "E1";
  74.       
  75.       public var directionLast:String = "right";
  76.       
  77.       public var direction:String = "none";
  78.       
  79.       private var zoneHit:HitZone;
  80.       
  81.       private var colorHit:uint;
  82.       
  83.       private var actif:Boolean = true;
  84.       
  85.       public var isJumping:Boolean = false;
  86.       
  87.       public var isFalling:Boolean = false;
  88.       
  89.       public var isArrivedToEnd:Boolean = false;
  90.       
  91.       public function Perso(param1:Decor, param2:MovieClip)
  92.       {
  93.          super();
  94.          this.clip = param2;
  95.          this.DECOR = param1;
  96.          this.x = this.xOriginal = this.clip.x;
  97.          this.y = this.yOriginal = this.clip.y;
  98.       }
  99.       
  100.       public function reset() : void
  101.       {
  102.          this.x = this.xOriginal;
  103.          this.y = this.yOriginal;
  104.          this.state = Perso.REST_RIGHT;
  105.          this.clip.STATE.gotoAndStop("E1");
  106.          this.directionLast = "right";
  107.          this.isJumping = false;
  108.          this.isFalling = false;
  109.          this.actif = true;
  110.       }
  111.       
  112.       public function resetContinue() : void
  113.       {
  114.          this.y = this.DECOR.getNearestFloor(this.y + this.distanceSol) - this.distanceSol;
  115.          this.state = Perso.REST_RIGHT;
  116.          this.clip.STATE.gotoAndStop("E1");
  117.          this.directionLast = "right";
  118.          this.isJumping = false;
  119.          this.isFalling = false;
  120.          this.actif = true;
  121.       }
  122.       
  123.       public function move(param1:Object) : void
  124.       {
  125.          if(this.actif)
  126.          {
  127.             this.speedX = this.speedY = 0;
  128.             if(param1.left)
  129.             {
  130.                this.speedX -= this.speed;
  131.             }
  132.             if(param1.right)
  133.             {
  134.                this.speedX += this.speed;
  135.             }
  136.             if(param1.up)
  137.             {
  138.                this.speedY -= this.speed;
  139.             }
  140.             if(param1.down)
  141.             {
  142.                this.speedY += this.speed;
  143.             }
  144.             this.colorHit = this.DECOR.getColorOnDecor(this.x + this.speedX,this.y + this.speedY);
  145.             if(this.colorHit == 0)
  146.             {
  147.                this.speedX = this.speedY = 0;
  148.                this.state = this.directionLast == "right" ? Perso.REST_RIGHT : Perso.REST_LEFT;
  149.             }
  150.             else if(this.colorHit == ColorZones.OUTPUT)
  151.             {
  152.                this.speedX = this.speedY = 0;
  153.                this.state = this.directionLast == "right" ? Perso.REST_RIGHT : Perso.REST_LEFT;
  154.                this.isArrivedToEnd = true;
  155.             }
  156.             else if(this.colorHit == ColorZones.FREE_HORIZONTAL)
  157.             {
  158.                this.speedY = 0;
  159.                this.y = this.DECOR.getNearestFloor(this.y + this.distanceSol) - this.distanceSol;
  160.                if(this.speedX != 0)
  161.                {
  162.                   if(param1.down)
  163.                   {
  164.                      this.state = this.speedX > 0 ? Perso.CRAWL_RIGHT : Perso.CRAWL_LEFT;
  165.                   }
  166.                   else if(param1.up)
  167.                   {
  168.                      this.speedX *= 1.5;
  169.                      this.state = this.directionLast == "right" ? Perso.JUMP_RIGHT : Perso.JUMP_LEFT;
  170.                   }
  171.                   else
  172.                   {
  173.                      this.state = this.speedX > 0 ? Perso.WALK_RIGHT : Perso.WALK_LEFT;
  174.                   }
  175.                }
  176.                else if(param1.up)
  177.                {
  178.                   this.state = this.directionLast == "right" ? Perso.JUMP_INPLACE_RIGHT : Perso.JUMP_INPLACE_LEFT;
  179.                }
  180.                else if(param1.down)
  181.                {
  182.                   this.state = this.directionLast == "right" ? Perso.DUCK_RIGHT : Perso.DUCK_LEFT;
  183.                }
  184.                else
  185.                {
  186.                   this.state = this.directionLast == "right" ? Perso.REST_RIGHT : Perso.REST_LEFT;
  187.                }
  188.             }
  189.             else if(this.colorHit == ColorZones.LOW_CEILING)
  190.             {
  191.                if(this.speedX != 0)
  192.                {
  193.                   if(param1.down == false && this.state != Perso.CRAWL_LEFT && this.state != Perso.CRAWL_RIGHT)
  194.                   {
  195.                      this.speedX = 0;
  196.                   }
  197.                   else
  198.                   {
  199.                      this.state = this.speedX > 0 ? Perso.CRAWL_RIGHT : Perso.CRAWL_LEFT;
  200.                   }
  201.                }
  202.                else if(param1.down == true || this.state == Perso.CRAWL_LEFT || this.state == Perso.CRAWL_RIGHT)
  203.                {
  204.                   this.state = this.directionLast == "right" ? Perso.CRAWL_RIGHT : Perso.CRAWL_LEFT;
  205.                }
  206.                this.speedY = 0;
  207.             }
  208.             else if(this.colorHit == ColorZones.UPSTAIRS_EXTREMITY_TOP)
  209.             {
  210.                if(param1.up)
  211.                {
  212.                   this.state = Perso.GO_UP;
  213.                }
  214.                else if(param1.down)
  215.                {
  216.                   if(this.state == Perso.CRAWL_LEFT || this.state == Perso.CRAWL_RIGHT)
  217.                   {
  218.                      this.speedY += 40;
  219.                   }
  220.                   this.state = Perso.GO_DOWN;
  221.                }
  222.                else if(param1.left)
  223.                {
  224.                   if(param1.down)
  225.                   {
  226.                      this.state = Perso.CRAWL_LEFT;
  227.                   }
  228.                   else
  229.                   {
  230.                      this.state = Perso.WALK_LEFT;
  231.                   }
  232.                }
  233.                else if(param1.right)
  234.                {
  235.                   if(param1.down)
  236.                   {
  237.                      this.state = Perso.CRAWL_RIGHT;
  238.                   }
  239.                   else
  240.                   {
  241.                      this.state = Perso.WALK_RIGHT;
  242.                   }
  243.                }
  244.                else
  245.                {
  246.                   this.state = this.directionLast == "right" ? Perso.REST_RIGHT : Perso.REST_LEFT;
  247.                }
  248.             }
  249.             else if(this.colorHit == ColorZones.UPSTAIRS_EXTREMITY_BOTTOM)
  250.             {
  251.                if(param1.up)
  252.                {
  253.                   this.state = Perso.GO_UP;
  254.                }
  255.                else if(param1.down)
  256.                {
  257.                   if(this.state == Perso.CRAWL_LEFT || this.state == Perso.CRAWL_RIGHT || this.y >= this.DECOR.getNearestFloor(this.y + this.distanceSol) - this.distanceSol && (this.state == Perso.DUCK_LEFT || this.state == Perso.DUCK_RIGHT))
  258.                   {
  259.                      this.y = this.DECOR.getNearestFloor(this.y + this.distanceSol) - this.distanceSol;
  260.                      this.state = this.directionLast == "right" ? Perso.DUCK_RIGHT : Perso.DUCK_LEFT;
  261.                   }
  262.                   else
  263.                   {
  264.                      this.state = Perso.GO_DOWN;
  265.                   }
  266.                }
  267.                else if(param1.left)
  268.                {
  269.                   if(param1.down)
  270.                   {
  271.                      this.state = Perso.CRAWL_LEFT;
  272.                   }
  273.                   else
  274.                   {
  275.                      this.state = Perso.WALK_LEFT;
  276.                   }
  277.                }
  278.                else if(param1.right)
  279.                {
  280.                   if(param1.down)
  281.                   {
  282.                      this.state = Perso.CRAWL_RIGHT;
  283.                   }
  284.                   else
  285.                   {
  286.                      this.state = Perso.WALK_RIGHT;
  287.                   }
  288.                }
  289.                else
  290.                {
  291.                   this.state = this.directionLast == "right" ? Perso.REST_RIGHT : Perso.REST_LEFT;
  292.                }
  293.             }
  294.             else if(this.colorHit == ColorZones.UPSTAIRS)
  295.             {
  296.                this.speedX = 0;
  297.                if(param1.up)
  298.                {
  299.                   this.state = Perso.GO_UP;
  300.                }
  301.                else if(param1.down)
  302.                {
  303.                   this.state = Perso.GO_DOWN;
  304.                }
  305.                else
  306.                {
  307.                   this.state = Perso.UPSTAIRS_STOP;
  308.                }
  309.             }
  310.             else if(this.colorHit == ColorZones.HOLE)
  311.             {
  312.                this.speedY = 0;
  313.                if(this.isJumping == false)
  314.                {
  315.                   this.actif = false;
  316.                   this.isFalling = true;
  317.                }
  318.             }
  319.          }
  320.          if(this.isFalling)
  321.          {
  322.             if(this.DECOR.getColorOnDecor(this.x,this.y + this.distanceSolFall) == 0)
  323.             {
  324.                this.speedX = this.speedY = 0;
  325.                this.state = this.directionLast == "right" ? Perso.FALL_END_RIGHT : Perso.FALL_END_LEFT;
  326.             }
  327.             else
  328.             {
  329.                this.speedX = 0;
  330.                this.speedY = 2;
  331.                this.state = this.directionLast == "right" ? Perso.FALL_RIGHT : Perso.FALL_LEFT;
  332.             }
  333.          }
  334.          this.x += this.speedX;
  335.          this.y += this.speedY;
  336.          if(this.speedX != 0)
  337.          {
  338.             this.directionLast = this.speedX > 0 ? "right" : "left";
  339.          }
  340.       }
  341.       
  342.       public function redraw() : void
  343.       {
  344.       }
  345.    }
  346. }
  347.