home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Nave / AitchuTheAbduction.swf / scripts / frame_8 / DoAction.as
Encoding:
Text File  |  2005-11-10  |  6.3 KB  |  257 lines

  1. Vaisseau = function()
  2. {
  3.    this._xscale = 80;
  4.    this._yscale = this._xscale;
  5.    this._x = 275;
  6.    this._y = 200;
  7.    this.vitesse = 20;
  8.    this.AnimPlayHaut = false;
  9.    this.AnimPlayBas = false;
  10.    this.vie = 1000;
  11.    this.power = 100;
  12.    this.maxTirdebase = 10;
  13.    this.tempsDernierTirdebase = 0;
  14.    this.delaiEntreDeuxTirdebase = 100;
  15.    this.nbrBombe = 10;
  16.    this.tempsDerniereBombe = 0;
  17.    this.delaiEntreDeuxBombe = 500;
  18.    this.mort = false;
  19.    this.touche = -1;
  20. };
  21. Vaisseau.prototype = new MovieClip();
  22. Object.registerClass("VaisseauClip",Vaisseau);
  23. Vaisseau.prototype.blesse = function()
  24. {
  25.    if(this.touche != -1)
  26.    {
  27.       if(_global.fotemps < this.touche + 10)
  28.       {
  29.          this._x += 5 * Math.cos(random(360) * 2 * 3.141592653589793 / 360);
  30.          this._y -= 5 * Math.cos(random(360) * 2 * 3.141592653589793 / 360);
  31.          this._alpha = random(100);
  32.       }
  33.       else
  34.       {
  35.          this.touche = -1;
  36.          this._alpha = 100;
  37.       }
  38.    }
  39. };
  40. Vaisseau.prototype.onEnterFrame = function()
  41. {
  42.    if(this.vie > 0)
  43.    {
  44.       this.move();
  45.       this.afficheTrainee();
  46.       this.protect();
  47.       this.tirnormal();
  48.       this.blesse();
  49.       this.lachebombe();
  50.       this.testTirEnnemi();
  51.    }
  52.    else if(this.mort == false)
  53.    {
  54.       this.gotoAndPlay("Mort");
  55.       this.mort = true;
  56.    }
  57.    if(_global.level == 1)
  58.    {
  59.       this.afficheTraineeEau();
  60.    }
  61.    if(_global.level == 3)
  62.    {
  63.       this.afficheTraineeFumee();
  64.    }
  65. };
  66. Vaisseau.prototype.testTirEnnemi = function()
  67. {
  68.    var len = _global.tabTirEnnemi.length;
  69.    var j = 0;
  70.    while(j < len)
  71.    {
  72.       var i = _global.tabTirEnnemi[j];
  73.       var clip = this._parent.tirEnnemiClip["tirEnnemi" + i];
  74.       if(clip._currentframe < 3)
  75.       {
  76.          if(this.hitTest(clip))
  77.          {
  78.             if(!this.bouclier)
  79.             {
  80.                this._parent.score -= 100;
  81.                this.vie -= clip.degats;
  82.                this.touche = _global.fotemps;
  83.             }
  84.             clip.angle = 3.141592653589793;
  85.             clip.play();
  86.          }
  87.       }
  88.       j++;
  89.    }
  90. };
  91. Vaisseau.prototype.move = function()
  92. {
  93.    if(Key.isDown(37))
  94.    {
  95.       if(this._x > 40)
  96.       {
  97.          this._x -= this.vitesse;
  98.       }
  99.    }
  100.    if(Key.isDown(39))
  101.    {
  102.       if(this._x < 550)
  103.       {
  104.          this._x += this.vitesse;
  105.       }
  106.    }
  107.    if(Key.isDown(38))
  108.    {
  109.       if(this._y > 20)
  110.       {
  111.          this._y -= this.vitesse;
  112.       }
  113.       if(this.AnimPlayHaut == false)
  114.       {
  115.          this.gotoAndPlay("NormalHaut");
  116.       }
  117.       this.AnimPlayHaut = true;
  118.    }
  119.    else if(this.AnimPlayHaut == true)
  120.    {
  121.       this.gotoAndPlay("HautNormal");
  122.       this.AnimPlayHaut = false;
  123.    }
  124.    if(Key.isDown(40))
  125.    {
  126.       if(this._y < 330)
  127.       {
  128.          this._y += this.vitesse;
  129.       }
  130.       if(this.AnimPlayBas == false)
  131.       {
  132.          this.gotoAndPlay("NormalBas");
  133.       }
  134.       this.AnimPlayBas = true;
  135.    }
  136.    else if(this.AnimPlayBas == true)
  137.    {
  138.       this.gotoAndPlay("HautNormal");
  139.       this.AnimPlayBas = false;
  140.    }
  141. };
  142. Vaisseau.prototype.afficheTrainee = function()
  143. {
  144.    if(!this._parent.trainee)
  145.    {
  146.       this._parent.attachMovie("TraineeClip","trainee",_global.traineeDepth);
  147.    }
  148.    this._parent.trainee._x = this._x;
  149.    this._parent.trainee._y = this._y;
  150. };
  151. Vaisseau.prototype.afficheTraineeEau = function()
  152. {
  153.    if(this._y > 300)
  154.    {
  155.       if(!this._parent.traineeEau)
  156.       {
  157.          this._parent.attachMovie("TraineeEauClip","traineeEau",_global.traineeEauDepth);
  158.          this._parent.traineeEau._y = 380;
  159.          this._parent.traineeEau._alpha = 60;
  160.       }
  161.       this._parent.traineeEau._x = this._x;
  162.       this._parent.traineeEau._height = this._y - 300;
  163.       this._parent.traineeEau._width = 150;
  164.       this._y -= random((this._y - 300) / 5);
  165.    }
  166.    else
  167.    {
  168.       this._parent.traineeEau.removeMovieClip();
  169.    }
  170. };
  171. Vaisseau.prototype.afficheTraineeFumee = function()
  172. {
  173.    if(this._y > 300)
  174.    {
  175.       if(!this._parent.traineeFumee)
  176.       {
  177.          this._parent.attachMovie("TraineeFumeeClip","traineeFumee",_global.traineeEauDepth);
  178.          this._parent.traineeFumee._y = 380;
  179.          this._parent.traineeFumee._alpha = 60;
  180.       }
  181.       this._parent.traineeFumee._x = this._x;
  182.       this._parent.traineeFumee._height = this._y - 300;
  183.       this._parent.traineeFumee._width = 150;
  184.       this._y -= random((this._y - 300) / 5);
  185.    }
  186.    else
  187.    {
  188.       this._parent.traineeFumee.removeMovieClip();
  189.    }
  190. };
  191. Vaisseau.prototype.protect = function()
  192. {
  193.    if(Key.isDown(66) && this.power > 0)
  194.    {
  195.       if(!this.bouclier)
  196.       {
  197.          this.attachMovie("BouclierClip","bouclier",_global.bouclierDepth);
  198.          this.bouclier._x = -20;
  199.          this.bouclier._y = -10;
  200.       }
  201.       this.power--;
  202.    }
  203.    else
  204.    {
  205.       this.bouclier.removeMovieClip();
  206.    }
  207. };
  208. Vaisseau.prototype.tirnormal = function()
  209. {
  210.    if(Key.isDown(32))
  211.    {
  212.       if(getTimer() > this.tempsDuDernierTirdebase + this.delaiEntreDeuxTirdebase)
  213.       {
  214.          this.tempsDuDernierTirdebase = getTimer();
  215.          var i = 0;
  216.          while(this._parent.tirVaisseauClip["tirVaisseau" + i])
  217.          {
  218.             i++;
  219.             if(i == _global.maxTirVaisseau)
  220.             {
  221.                return 0;
  222.             }
  223.          }
  224.          this._parent.tirVaisseauClip.attachMovie("TirdebaseRClip","tirVaisseau" + i,_global.tirVaisseauDepth + i);
  225.          var clip = this._parent.tirVaisseauClip["tirVaisseau" + i];
  226.          clip.angle = 0;
  227.          clip._x = this._x + 5;
  228.          clip._y = this._y;
  229.       }
  230.    }
  231. };
  232. Vaisseau.prototype.lachebombe = function()
  233. {
  234.    if(Key.isDown(86))
  235.    {
  236.       if(getTimer() > this.tempsDerniereBombe + this.delaiEntreDeuxBombe && this.nbrBombe > 0)
  237.       {
  238.          this.tempsDerniereBombe = getTimer();
  239.          var i = 0;
  240.          while(this._parent.tirVaisseauClip["tirVaisseau" + i])
  241.          {
  242.             i++;
  243.             if(i == _global.maxTirVaisseau)
  244.             {
  245.                return 0;
  246.             }
  247.          }
  248.          this._parent.tirVaisseauClip.attachMovie("BombeClip","tirVaisseau" + i,_global.tirVaisseauDepth + i);
  249.          var clip = this._parent.tirVaisseauClip["tirVaisseau" + i];
  250.          clip._x = this._x - 5;
  251.          clip._y = this._y;
  252.          clip.num = i;
  253.          this.nbrBombe--;
  254.       }
  255.    }
  256. };
  257.