var TEXTCOLOR = '#44BCC4'; var TEXTCOLORACTIVE = '#C5F51D'; var TEXTCOLORDISABLE = '#585858'; var LevelScene = tine._scene({ initialize: function() { var w = game.canvas.width; var h = game.canvas.height; var wh = game.canvas.width/2; var hh = game.canvas.height/2; this.regX = -wh; this.regY = -hh; // CONFIGURE LAYERS ------------------------------------------------------- this.addLayer('background'); this.addLayer('planetbg'); this.addLayer('objectsbg'); this.addLayer('objects'); this.addLayer('objectsfg'); this.addLayer('planetfg'); this.addLayer('gameinfo'); this.addLayer('ui'); this.getLayer('ui').regX = wh; this.getLayer('ui').regY = hh; // GAME VARIABLES --------------------------------------------------------- this.canplay = false; this.player = { resources: 0, totalResources: 0 } this.humanPlayed = false; this.cursor = new Cursor(this); this.planet = new Planet(this, 150, 100); this.playerStructures = []; this.playerCreatures = []; this.enemyStructures = []; this.enemyCreatures = []; this.structures = []; this.creatures = []; this.distanceCache = []; this.maxEnemies = game.data.max_enemies; this.allowActionA = true; this.allowActionB = true; this.allowActionC = true; this.allowEnemySpawn = true; this.allowAlert = true; this.guardianChance = game.data.guardian_chance; this.tool = null; // TODO: (TEMP) INITIAL CREATURES ----------------------------------------- // for (var i=0; i<0; i++) { // var c = this.addCreature('zergling', Math.random()*360); // c.goTo(Math.random()*360); // } // var c = this.addStructure('supernest', Math.random()*360); // for (var i=0; i<3; i++) { // var c = this.addStructure('nest', Math.random()*360); // } // var c = this.addStructure('smallnest', Math.random()*360); // ADD BACKGROUND --------------------------------------------------------- this.addObject(game.create.bitmap('img_stars', {regX:wh, regY:hh}), 'background'); var sky = game.create.shape({regX:-wh, regY:-hh, alpha:0.7}); sky.graphics .rf(["#1D3A58", "#000"], [0, 1], 0, 0, 0, 0, 0, Math.max(w, h)) .r(-wh, -hh, w, h) this.addObject(sky, 'background'); // ADD PLANET ------------------------------------------------------------- this.addObject(this.planet.background, 'planetbg'); this.addObject(this.planet.foreground, 'planetfg'); // CURSOR ----------------------------------------------------------------- this.addObject(this.cursor.display, 'background'); // EMITTERS --------------------------------------------------------------- var shape = game.create.shape(); shape.graphics.f('red').r(-3, -3, 6, 6); this.creatureKillEmitter = new tine.Emitter(shape, 300); this.creatureKillEmitter.burstAmount = 20; this.creatureKillEmitter.angle = 0; this.creatureKillEmitter.angleVar = 140; this.creatureKillEmitter.dirXVar = 0.3; this.creatureKillEmitter.dirYVar = 0.3; this.creatureKillEmitter.speed = 25; this.creatureKillEmitter.life = 0.5; this.creatureKillEmitter.lifeVar = 0.2; this.creatureKillEmitter.endAlpha = 0; // this.creatureKillEmitter.emissionRate = 20; this.addObject(this.creatureKillEmitter, 'objectsfg'); var shape = game.create.shape(); shape.graphics.f('white').r(-5, -5, 10, 10); this.structureKillEmitter = new tine.Emitter(shape, 500); this.structureKillEmitter.burstAmount = 100; this.structureKillEmitter.angle = 0; this.structureKillEmitter.angleVar = 140; this.structureKillEmitter.dirXVar = 0.8; this.structureKillEmitter.dirYVar = 0.8; this.structureKillEmitter.speed = 50; this.structureKillEmitter.life = 0.5; this.structureKillEmitter.lifeVar = 0.2; // this.structureKillEmitter.emissionRate = 100; this.structureKillEmitter.endAlpha = 0; this.addObject(this.structureKillEmitter, 'objectsfg'); var shape = game.create.shape(); shape.graphics.f('#E03B20').dc(0, 0, 3); this.attackEmitter = new tine.Emitter(shape, 200); this.attackEmitter.burstAmount = 3; this.attackEmitter.angle = 0; this.attackEmitter.angleVar = 140; this.attackEmitter.dirXVar = 0.3; this.attackEmitter.dirYVar = 0.3; this.attackEmitter.speed = 3; this.attackEmitter.life = 0.5; this.attackEmitter.lifeVar = 0.2; this.attackEmitter.endAlpha = 0; this.addObject(this.attackEmitter, 'objectsfg'); var shape = game.create.shape(); shape.graphics.f('#FFF').dc(0, 0, 5); this.landingEmitter = new tine.Emitter(shape, 300); this.landingEmitter.burstAmount = 10; this.landingEmitter.angle = 0; this.landingEmitter.angleVar = 35; this.landingEmitter.dirXVar = 0.2; this.landingEmitter.dirYVar = 0.2; this.landingEmitter.xVar = 5; this.landingEmitter.yVar = 5; this.landingEmitter.speed = 5; this.landingEmitter.life = 1.5; this.landingEmitter.lifeVar = 0.5; this.landingEmitter.endAlpha = 0; this.addObject(this.landingEmitter, 'objectsfg'); // UI --------------------------------------------------------------------- this.addObject(game.create.bitmap('img_dirt', {regX:'center', regY:300}), 'gameinfo'); this.addObject(game.create.bitmap('img_frame', {regX:'center', regY:300}), 'gameinfo'); this.addObject(game.create.bitmap('img_lens', {regX:'center', regY:300}), 'gameinfo'); this.txtResources = game.create.text('Resources: 0', { font:'24px nasa', color:TEXTCOLOR, textAlign:'left', x:20, y:40 }) this.txtPlanetResources = game.create.text('Planet: 0', { font:'24px nasa', color:TEXTCOLOR, textAlign:'left', x: 20, y: 80, }); var cost = game.data.playerStructures['extractor'].cost; this.txtActionA = game.create.text('[Q] Extractor ($'+cost+')', { font:'20px nasa', color:TEXTCOLOR, textAlign:'left', x: 20, y: h-140, }); var cost = game.data.playerStructures['reinforcement_pod'].cost; this.txtActionB = game.create.text('[W] Drop Pod ($'+cost+')', { font:'20px nasa', color:TEXTCOLOR, textAlign:'left', x: 20, y: h-110, }); var cost = game.data.playerStructures['big_reinforcement_pod'].cost; this.txtActionC = game.create.text('[E] Big Drop Pod ($'+cost+')', { font:'20px nasa', color:TEXTCOLOR, textAlign:'left', x: 20, y: h-80, }); this.addObject(this.txtResources, 'ui'); this.addObject(this.txtPlanetResources, 'ui'); this.addObject(this.txtActionA, 'ui'); this.addObject(this.txtActionB, 'ui'); this.addObject(this.txtActionC, 'ui'); var self = this; var pauseButton = new MiniButton('II', function() { self.doPause(); }) pauseButton.x = w-50; pauseButton.y = h-50; this.addObject(pauseButton, 'ui'); var muteButton = new MiniButton('M', function() { game.sound.toogleMute(); }) muteButton.x = w-90; muteButton.y = h-50; this.addObject(muteButton, 'ui'); this.txtAlert = game.create.text('mensagem', { font:'12px nasa', color:TEXTCOLOR, textAlign:'right', x:w-30, y:40 }); this.txtAlert.alpha = 0; this.addObject(this.txtAlert, 'ui'); // game.canvas.addEventListener('blur', function() { // self.doPause(); // }) }, // -------------------------------------------------------------------------- // SCENE FLOW // -------------------------------------------------------------------------- beforeEnter: function() { var spec = game.data[game.registry.current_level]; this.cursor.moveTo(0); this.humanPlayed = false; this.planet.resources = spec.planet_resource; this.planet.radius = spec.planet_radius; this.planet._redraw(); this.initialResource = spec.initial_resource; this.player.resources = spec.initial_resource; this.txtAlert.text = spec.tutorial_text || ''; this.txtAlert.alpha = 1; this.allowActionA = spec.allow_actionA; this.allowActionB = spec.allow_actionB; this.allowActionC = spec.allow_actionC; this.allowEnemySpawn = spec.allow_enemy_spawn; this.allowAlert = spec.allow_alert; this.maxEnemies = spec.max_enemies; this.nextLevel = spec.next_level; this.levelEnded = false; this.guardianChance = spec.guardian_chance||game.data.guardian_chance; if (!this.allowActionA) this.txtActionA.color = TEXTCOLORDISABLE if (!this.allowActionB) this.txtActionB.color = TEXTCOLORDISABLE if (!this.allowActionC) this.txtActionC.color = TEXTCOLORDISABLE for (var i=0; i=0; i--) { this.removeCreature(this.creatures[i]); } for (var i=this.structures.length-1; i>=0; i--) { this.removeStructure(this.structures[i]); } this.canplay = false; this.player = { resources: 0, totalResources: 0 } this.playerStructures = []; this.playerCreatures = []; this.enemyStructures = []; this.enemyCreatures = []; this.structures = []; this.creatures = []; this.maxEnemies = game.data.max_enemies; this.allowActionA = true; this.allowActionB = true; this.allowActionC = true; this.allowEnemySpawn = true; this.allowAlert = true; this.tool = null; }, // -------------------------------------------------------------------------- // ADD/REMOVE OBJECTS // -------------------------------------------------------------------------- addStructure: function(type, position, ignoreConstraints) { var spec = game.data.playerStructures[type] || game.data.enemyStructures[type]; var position = position || this.cursor.position; var circumference = this.planet.circumference; if (!ignoreConstraints) { // Verify needed resources if (this.player.resources < spec.cost) { // TODO: MENSAGEM ERROR AQUI return; } // Verify minimum distance for (var i=0; i 45) { this._addLandingEffect(position, -d/2); this._addLandingEffect(position, 0); this._addLandingEffect(position, d/2); this.shake('superstrong'); } else if (structure.width > 30) { this._addLandingEffect(position, -d/2); this._addLandingEffect(position, d/2); this.shake('strong'); } else if (structure.width > 20) { this._addLandingEffect(position, 0); this.shake('medium'); } else { this.shake(); } this._addLandingEffect(position, +d); }, addDestroyEffect: function(position) { game.sound.playSfx('explosion'); var a = tine.radians(position); var x = Math.sin(a) * (this.planet.radius+10); var y = -Math.cos(a) * (this.planet.radius+10); this.structureKillEmitter.angle = position-90; this.structureKillEmitter.burst(x, y) }, alert: function(msg) { if (!this.allowAlert) return; this.txtAlert.text = msg; this.txtAlert.alpha = 0; createjs.Tween.get(this.txtAlert, {override:true}) .to({alpha: 1}, 500) .wait(2000) .to({alpha: 0}, 200) .to({alpha: 1}, 500) .to({alpha: 0}, 1000) }, shake: function(force) { var r = 2; if (force === 'superstrong') r = 20; if (force === 'strong') r = 10; if (force === 'medium') r = 5; var ox = this.x; var oy = this.y; createjs.Tween.get(this, {override:true}) .to({x:Math.random()*r-r/2, y:Math.random()*r-r/2}, 50) .to({x:Math.random()*r-r/2, y:Math.random()*r-r/2}, 50) .to({x:Math.random()*r-r/2, y:Math.random()*r-r/2}, 50) .to({x:Math.random()*r-r/2, y:Math.random()*r-r/2}, 50) .to({x:Math.random()*r-r/2, y:Math.random()*r-r/2}, 50) .to({x:Math.random()*r-r/2, y:Math.random()*r-r/2}, 50) .to({x:Math.random()*r-r/2, y:Math.random()*r-r/2}, 50) .to({x:Math.random()*r-r/2, y:Math.random()*r-r/2}, 50) .to({x:Math.random()*r-r/2, y:Math.random()*r-r/2}, 50) .to({x:Math.random()*r-r/2, y:Math.random()*r-r/2}, 50) .to({x:Math.random()*r-r/2, y:Math.random()*r-r/2}, 50) .to({x:Math.random()*r-r/2, y:Math.random()*r-r/2}, 50) .to({x:ox, y:oy}, 50) }, doPause: function() { // if (game.director.scene === this) if (this.paused || !this.started) return; game.director.push('pause', new tine.transitions.MoveIn(creatine.TOP, null, 200)); } })