Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Player.prototype = {
- canShoot : true,
- draw: function (ctx) {
- ctx.save();
- ctx.translate(this.position.x, this.position.y);
- ctx.rotate(this.direction + Math.PI / 2);
- ctx.beginPath();
- ctx.moveTo(0, -this.height / 2);
- ctx.lineTo(this.width / 2, this.height / 2);
- ctx.lineTo(0, this.height / 2 - this.height * 0.3);
- ctx.lineTo(-this.width / 2, this.height / 2);
- ctx.lineTo(0, -this.height / 2);
- ctx.stroke();
- ctx.restore();
- },
- moveForward: function(dt) {
- this.position.x += this.speed.x* Math.cos(this.direction) * dt;
- this.position.y += this.speed.y * Math.sin(this.direction) * dt;
- this.position.iadd(this.velocity.muls(dt))
- },
- throttle: function (dt) {
- this.accelerateForce(this.speed, dt);
- },
- breaks: function (dt) {
- this.breakForce(this.speed, dt);
- this.breakForce(this.velocity, dt);
- },
- rotateLeft: function () {
- this.direction -= this.dAngle;
- },
- rotateRight: function () {
- this.direction += this.dAngle;
- },
- update: function (dt, width, height, projectiles) {
- if (Key.isDown(Key.UP)){
- this.throttle(dt);
- }
- if (Key.isDown(Key.LEFT)) this.rotateLeft();
- if (Key.isDown(Key.DOWN)) this.breaks(dt);
- if (Key.isDown(Key.RIGHT)) this.rotateRight();
- if (Key.isDown(Key.SPACE)){
- console.log(this.canShoot);
- if(this.canShoot) {
- projectiles.push(new Projectile(320, 10,
- new Vector(this.position.x, this.position.y),
- new Vector(this.velocity.x, this.velocity.y),
- new Vector(this.speed.x, this.speed.y),
- this.direction));
- setTimeout(function(){ this.canShoot=true;}, 100);
- setTimeout(function(){ alert("Hello"); }, 3000);
- this.canShoot = false;
- //setTimeout(function(){ this.canShoot=true;}, 100);
- }
- }
- Forces.update(this.velocity, dt);
- this.moveForward(dt);
- this.stayInArea(width, height);
- },
- stayInArea: function (width, height) {
- if (this.position.y < -this.height) this.position.y = height;
- if (this.position.y > height) this.position.y = -this.height;
- if (this.position.x > width) this.position.x = -this.width;
- if (this.position.x < -this.width) this.position.x = width;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement