function Curtain(game, camera) { this.system = null; this.canvas = null; this.duration = 5000; this.timer = 0; this.opacity = 0; this.onComplete = null; this.state = "idle"; this.init = function(systemObject, canvas) { this.system = systemObject; this.canvas = canvas; }; this.close = function(duration, onComplete) { this.duration = duration; this.onComplete = onComplete; this.opacity = 1; this.timer = 0; this.state = "closing"; } this.open = function(duration, onComplete) { this.duration = duration; this.onComplete = onComplete; this.opacity = 0; this.timer = 0; this.state = "opening"; } this.updateDelta = function(delta) { if(this.state == "idle") { return; } this.timer += delta * (1000 / 60); if(this.timer - (this.duration / 8) >= this.duration) { this.state = "idle"; this.onComplete(); return; } this.opacity = (this.timer / (this.duration - (this.duration / 8))); }; this.draw = function(context) { if(this.state == "idle") { return; } if(this.state == "closing") { context.fillStyle = "#000000"; context.globalAlpha = Math.min(1, Math.max(0, this.opacity)); context.beginPath(); context.rect(0, 0, this.canvas.width, this.canvas.height); context.fill(); } if(this.state == "opening") { context.fillStyle = "#000000"; context.globalAlpha = Math.min(1, Math.max(0, 1 - this.opacity)); context.beginPath(); context.rect(0, 0, this.canvas.width, this.canvas.height); context.fill(); } context.globalAlpha = 1; }; };