grifdail

Max'

Mar 29th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Missile = function(x,y, angle)
  2. {
  3.  this.x = x;
  4.  this.y = y;
  5.  this.angle = angle;
  6.  this.speed = 6;
  7.  this.xTower = x;
  8.  this.yTower = y;
  9.  
  10.  this.update = function()
  11.  {
  12.   this.x += Math.cos(this.angle) * this.speed;
  13.   this.y -= Math.sin(this.angle) * this.speed;
  14.  }
  15.  
  16.  this.draw = function()
  17.  {
  18.  
  19.   context.fillStyle = "rgb(255,255,0)";
  20.   context.beginPath(this.x, this.y);
  21.   context.arc(this.x + 20, this.y +20, 10,0, Math.PI * 2,1);
  22.   context.fill();
  23.  
  24.  }
  25.  this.limit = function()
  26.   {
  27.    //Calcul de la distance entre la tour et le tir.
  28.    console.log(this.distanceTir);
  29.    this.distanceTir = Math.sqrt(sqr(this.y -  this.yTower) + sqr(this.x -  this.xTower));
  30.    //S'il sort de la range, il sort du tableau
  31.     if (this.distanceTir > 100)  {
  32.     missiles.splice(missiles.indexOf(this), 1); // le .indexOf sert a récuper la position du misille que l'on étudie pour le supprimer car on ne l'as pas conservé
  33.     break
  34.       }
  35.    
  36.     }
  37.   }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment