|
|
|
|
|
|
|
|
this.invincibleTimeout = null; |
|
|
this.invincibleTimeout = null; |
|
|
this.started = false; |
|
|
this.started = false; |
|
|
this.rotation = 0; |
|
|
this.rotation = 0; |
|
|
|
|
|
this.box = new Box(); |
|
|
|
|
|
this.shape.push(this.box); |
|
|
|
|
|
|
|
|
this.erectLevel = 0; |
|
|
this.erectLevel = 0; |
|
|
this.rise(); |
|
|
this.rise(); |
|
|
|
|
|
|
|
|
this.pos.set({ x: 0, y: game.canvas.height / 2 }); |
|
|
this.pos.set({ x: 0, y: game.canvas.height / 2 }); |
|
|
} |
|
|
} |
|
|
Player.prototype.rise = function() { |
|
|
|
|
|
this.erectLevel += 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Player.prototype.setBox = function() { |
|
|
var w = 30 + ((this.erectLevel - 1) * 15); |
|
|
var w = 30 + ((this.erectLevel - 1) * 15); |
|
|
var h = 15 + ((this.erectLevel - 1) * 6); |
|
|
var h = 15 + ((this.erectLevel - 1) * 6); |
|
|
this.shape.push(new Box(w, h, { x: -(w/2), y: -(h/2) })); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.box.width = w; |
|
|
|
|
|
this.box.height = h; |
|
|
|
|
|
this.box.pos.x = -(w / 2); |
|
|
|
|
|
this.box.pos.y = -(h / 2); |
|
|
|
|
|
} |
|
|
|
|
|
Player.prototype.rise = function() { |
|
|
|
|
|
this.erectLevel += 1; |
|
|
this.setInvincible(200); |
|
|
this.setInvincible(200); |
|
|
|
|
|
this.setBox(); |
|
|
} |
|
|
} |
|
|
Player.prototype.lower = function() { |
|
|
Player.prototype.lower = function() { |
|
|
if (this.invincible) |
|
|
if (this.invincible) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
this.shape.pop(); |
|
|
|
|
|
|
|
|
|
|
|
this.erectLevel -= 1; |
|
|
this.erectLevel -= 1; |
|
|
if (this.erectLevel === 0) |
|
|
if (this.erectLevel === 0) |
|
|
this.lose(); |
|
|
this.lose(); |
|
|
else |
|
|
else |
|
|
this.setInvincible(500); |
|
|
this.setInvincible(500); |
|
|
|
|
|
|
|
|
|
|
|
this.setBox(); |
|
|
} |
|
|
} |
|
|
Player.prototype.setInvincible = function(time) { |
|
|
Player.prototype.setInvincible = function(time) { |
|
|
clearTimeout(this.invincibleTimeout); |
|
|
clearTimeout(this.invincibleTimeout); |
|
|
|
|
|
|
|
|
this.game.camera.x = this.pos.x - (this.game.canvas.width / 7); |
|
|
this.game.camera.x = this.pos.x - (this.game.canvas.width / 7); |
|
|
|
|
|
|
|
|
// Rotate |
|
|
// Rotate |
|
|
this.rotation = this.vel.rotation(); |
|
|
|
|
|
|
|
|
this.rotation = this.vel.angle(); |
|
|
} |
|
|
} |
|
|
Player.prototype.lose = function() { |
|
|
Player.prototype.lose = function() { |
|
|
alert("You died!"); |
|
|
alert("You died!"); |
|
|
|
|
|
|
|
|
else |
|
|
else |
|
|
ctx.fillStyle = "#f5f5dc"; |
|
|
ctx.fillStyle = "#f5f5dc"; |
|
|
ctx.rotate(this.rotation); |
|
|
ctx.rotate(this.rotation); |
|
|
|
|
|
|
|
|
this.shape.draw(ctx); |
|
|
this.shape.draw(ctx); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
makeEnt(this, game, 100); |
|
|
makeEnt(this, game, 100); |
|
|
this.pos.set({ x: x, y: y }); |
|
|
this.pos.set({ x: x, y: y }); |
|
|
|
|
|
|
|
|
var w = 40; |
|
|
|
|
|
|
|
|
var w = 70; |
|
|
var h = game.canvas.height; |
|
|
var h = game.canvas.height; |
|
|
var gap = 200; |
|
|
var gap = 200; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.shape.push(new Box(30, 30)); |
|
|
this.shape.push(new Box(30, 30)); |
|
|
} |
|
|
} |
|
|
PowerUp.prototype.draw = function(ctx) { |
|
|
PowerUp.prototype.draw = function(ctx) { |
|
|
|
|
|
ctx.fillStyle = "#33ee33"; |
|
|
|
|
|
ctx.strokeStyle = "#227722"; |
|
|
ctx.beginPath(); |
|
|
ctx.beginPath(); |
|
|
ctx.arc(15, 15, 15, 0, 2 * Math.PI); |
|
|
ctx.arc(15, 15, 15, 0, 2 * Math.PI); |
|
|
ctx.stroke(); |
|
|
ctx.stroke(); |
|
|
|
|
|
ctx.fill(); |
|
|
} |
|
|
} |
|
|
PowerUp.prototype.update = function() { |
|
|
PowerUp.prototype.update = function() { |
|
|
if (this.game.camera.x > this.pos.x + this.shape.width()) |
|
|
if (this.game.camera.x > this.pos.x + this.shape.width()) |