var WinScene = tine._scene({ initialize: function() { this.addLayer('background'); this.addLayer('screen'); this.addLayer('ui'); var w = game.canvas.width; var h = game.canvas.height; var wh = game.canvas.width/2; var hh = game.canvas.height/2; this.addObject(game.create.bitmap('img_stars'), 'background'); var sky = game.create.shape({regX:-wh, regY:-hh, alpha:0.7}); sky.graphics .rf(["#1D3A58", "#000"], [0, 1], wh, hh, 0, wh, hh, Math.max(w, h)) .r(0, 0, w, h) this.addObject(sky, 'background'); this.addObject(game.create.bitmap('img_dirt'), 'screen'); this.addObject(game.create.bitmap('img_frame'), 'screen'); this.addObject(game.create.bitmap('img_lens'), 'screen'); var self = this; this.nextLevelButton = new Button('Next Level', function() { self.goNext() }); this.nextLevelButton.x = w-125; this.nextLevelButton.y = h-210; this.addObject(this.nextLevelButton, 'ui'); var button = new Button('Restart', function() { self.goRestart() }); button.x = w-125; button.y = h-140; this.addObject(button, 'ui'); var button = new Button('Menu', function() { self.goMenu() }); button.x = w-125; button.y = h-70; this.addObject(button, 'ui'); logo = game.create.text('Victory!', { font: '72px aero', textAlign: 'center', color: '#E0E0E0', x: wh, y: 70, }); this.addObject(logo, 'ui'); logo = game.create.text('One more planet democratized!', { font: '36px aero', textAlign: 'center', color: '#BDBDBD', x: wh, y: 140, }); this.addObject(logo, 'ui'); this.txtInitialResources = game.create.text('Initial resources: 0', {font:'18px nasa', textAlign:'justify', color:'#E0E0E0', x:45, y:375}); this.txtTotalResources = game.create.text('Total resources collected: 0', {font:'18px nasa', textAlign:'justify', color:'#E0E0E0', x:45, y:425}); this.txtSpentResources = game.create.text('Total resources spent: 0', {font:'18px nasa', textAlign:'justify', color:'#E0E0E0', x:45, y:475}); this.txtProfitResources = game.create.text('Final profit: 0', {font:'18px nasa', textAlign:'justify', color:'#E0E0E0', x:45, y:525}); this.addObject(this.txtInitialResources, 'ui'); this.addObject(this.txtTotalResources, 'ui'); this.addObject(this.txtSpentResources, 'ui'); this.addObject(this.txtProfitResources, 'ui'); this.initialResources = 0; this.totalResources = 0; this.spentResources = 0; this.profitResources = 0; }, beforeEnter: function() { this.initialResources = 0; this.totalResources = 0; this.spentResources = 0; this.profitResources = 0; this.txtInitialResources.text = 'Initial resources: 0'; this.txtTotalResources.text = 'Total resources collected: 0'; this.txtSpentResources.text = 'Total resources spent: 0'; this.txtProfitResources.text = 'Final profit: 0'; if (game.registry.next_level !== null) { this.nextLevelButton.alpha = 1; } else { this.nextLevelButton.alpha = 0; } }, enter: function() { var r = game.registry; createjs.Tween.get(this) .wait() .to({initialResources: r.initial_resources}, 500); createjs.Tween.get(this) .wait(500 ).to({totalResources: r.total_resources}, 500); var s = (r.initial_resources + r.total_resources) - r.profit createjs.Tween.get(this) .wait(1000 ).to({spentResources: s}, 500); createjs.Tween.get(this) .wait(1500 ).to({profitResources: r.profit}, 500); }, update: function() { // Update UI -------------------------------------------------------------- var text = 'Initial resources: '+parseInt(this.initialResources); if (this.txtInitialResources.text !== text) { this.txtInitialResources.text = text; } var text = 'Total resources collected: '+parseInt(this.totalResources); if (this.txtTotalResources.text !== text) { this.txtTotalResources.text = text; } var text = 'Total resources spent: '+parseInt(this.spentResources); if (this.txtSpentResources.text !== text) { this.txtSpentResources.text = text; } var text = 'Final profit: '+parseInt(this.profitResources); if (this.txtProfitResources.text !== text) { this.txtProfitResources.text = text; } }, exit: function() { this.alpha = 1; }, goMenu: function() { game.director.replace('menu', new tine.transitions.FadeOut(null, 300)); }, goNext: function() { game.registry.current_level = game.registry.next_level; game.director.replace('level', new tine.transitions.FadeOut(null, 300)); }, goRestart: function() { game.director.replace('level', new tine.transitions.FadeOut(null, 300)); }, })