Advertisement
Guest User

Untitled

a guest
May 5th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Player.prototype = {
  2.    
  3.     canShoot : true,
  4.    
  5.     draw: function (ctx) {
  6.         ctx.save();
  7.         ctx.translate(this.position.x, this.position.y);
  8.         ctx.rotate(this.direction + Math.PI / 2);
  9.         ctx.beginPath();
  10.         ctx.moveTo(0, -this.height / 2);
  11.         ctx.lineTo(this.width / 2, this.height / 2);
  12.         ctx.lineTo(0, this.height / 2 - this.height * 0.3);
  13.         ctx.lineTo(-this.width / 2, this.height / 2);
  14.         ctx.lineTo(0, -this.height / 2);
  15.  
  16.         ctx.stroke();
  17.         ctx.restore();
  18.     },
  19.  
  20.     moveForward: function(dt) {
  21.         this.position.x += this.speed.x* Math.cos(this.direction) * dt;
  22.         this.position.y += this.speed.y * Math.sin(this.direction) * dt;
  23.         this.position.iadd(this.velocity.muls(dt))
  24.  
  25.     },
  26.  
  27.     throttle: function (dt) {
  28.         this.accelerateForce(this.speed, dt);
  29.     },
  30.     breaks: function (dt) {
  31.         this.breakForce(this.speed, dt);
  32.         this.breakForce(this.velocity, dt);
  33.  
  34.     },
  35.  
  36.     rotateLeft: function () {
  37.         this.direction -= this.dAngle;
  38.     },
  39.  
  40.     rotateRight: function () {
  41.         this.direction += this.dAngle;
  42.     },
  43.    
  44.     update: function (dt, width, height, projectiles) {
  45.  
  46.        
  47.         if (Key.isDown(Key.UP)){
  48.              this.throttle(dt);
  49.         }
  50.         if (Key.isDown(Key.LEFT)) this.rotateLeft();
  51.         if (Key.isDown(Key.DOWN)) this.breaks(dt);
  52.         if (Key.isDown(Key.RIGHT)) this.rotateRight();
  53.         if (Key.isDown(Key.SPACE)){
  54.             console.log(this.canShoot);
  55.             if(this.canShoot) {
  56.                 projectiles.push(new Projectile(320, 10,
  57.                     new Vector(this.position.x, this.position.y),
  58.                     new Vector(this.velocity.x, this.velocity.y),
  59.                     new Vector(this.speed.x, this.speed.y),
  60.                     this.direction));
  61.                 setTimeout(function(){ this.canShoot=true;}, 100);
  62.                 setTimeout(function(){ alert("Hello"); }, 3000);
  63.                 this.canShoot = false;
  64.                 //setTimeout(function(){ this.canShoot=true;}, 100);
  65.                
  66.             }
  67.         }
  68.         Forces.update(this.velocity, dt);
  69.         this.moveForward(dt);
  70.         this.stayInArea(width, height);
  71.     },
  72.  
  73.     stayInArea: function (width, height) {
  74.         if (this.position.y < -this.height) this.position.y = height;
  75.         if (this.position.y > height) this.position.y = -this.height;
  76.         if (this.position.x > width) this.position.x = -this.width;
  77.         if (this.position.x < -this.width) this.position.x = width;
  78.     }
  79.  
  80.  
  81. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement