Trade-Winds/minified/rooms/oceanRoom.js

1 line
4.1 KiB
JavaScript

function oceanRoom(){G.player=rm_Ocean.AddObject(OS.P.Ship),G.oceanParticle=rm_Ocean.AddObject(OS.P["Ocean Particle"]),rm_Ocean.GenerateMap(),OS.SetRoom(rm_Ocean)}rm_Ocean.waveTimer=Math.round(Math.randomRange(30,150)),rm_Ocean.clockTimerCount=1,rm_Ocean.DoFirst=function(){mus_title.Play(),G.player.x=this.squareSize*(this.squaresX/2)-this.squareSize/2-G.player.xBound,G.player.y=this.squareSize*(this.squaresY/2),G.oceanParticle.x=G.player.x+randomSmidge(),G.oceanParticle.y=G.player.y+randomSmidge(),OS.SetCamera({x:G.player.x-OS.camera.width/2,y:G.player.y-OS.camera.height/2,objectToFollow:G.player}),this.mapLeftTrigger=OS.camera.hBorder,this.mapLeftTriggerTarget=this.width-(OS.camera.width-OS.camera.hBorder),this.mapRightTrigger=this.width-OS.camera.hBorder,this.mapRightTriggerTarget=OS.camera.width-OS.camera.hBorder,this.mapUpTrigger=OS.camera.vBorder,this.mapUpTriggerTarget=this.height-(OS.camera.height-OS.camera.vBorder),this.mapDownTrigger=this.height-OS.camera.vBorder,this.mapDownTriggerTarget=OS.camera.height-OS.camera.vBorder},rm_Ocean.Do=function(){if(G.gameStarted&&(guiControl&&guiControl.inventory&&guiControl.map&&guiControl.trade&&(guiControl.inventory.show||guiControl.map.show||guiControl.trade.show||(G.oceanParticle.CheckPosition&&G.oceanParticle.CheckPosition(G.player.x,G.player.y,G.player.direction),ct_cancel().down&&(snd_select.Play(),guiControl.inventory.activateDelay=5,guiControl.inventory.show=!0),ct_m.down&&(snd_select.Play(),guiControl.map.activateDelay=5,guiControl.map.show=!0))),this.RunClock()),guiControl&&guiControl.trade&&!guiControl.trade.show&&(this.waveTimer--,this.waveTimer<=0)){var e=this.AddObject(OS.P["Wave Particle"]);e.x=G.player.x+4*randomSmidge(),e.y=G.player.y+4*randomSmidge(),this.waveTimer=Math.round(Math.randomRange(30,150))}},rm_Ocean.DrawAbove=function(){G.gameStarted?(this.DrawNightDarkness(),OS.context.drawImage(rm_Ocean.speedGaugeImg,32*G.player.currentSpeed,0,32,32,16,OS.camera.height-32-16,32,32),this.DrawEnergyBar(),this.DrawClock(),drawInventoryGUI(),drawMapGUI(),drawTradeGUI()):drawTitleScreen()},rm_Ocean.DoLast=function(){},rm_Ocean.RunClock=function(){if(guiControl.trade&&!guiControl.trade.show){if(rm_Ocean.clockTimerCount++,rm_Ocean.clockTimerCount>rm_Ocean.clockTimerCutoff){rm_Ocean.clockTimerCount=0,G.economy.UpdateEconomy();for(var e=0;e<G.map.length;e++)G.map[e].island.NewDay();G.SaveGame()}0!=rm_Ocean.clockTimerCount&&rm_Ocean.clockTimerCount!=Math.round(.33*rm_Ocean.clockTimerCutoff)&&rm_Ocean.clockTimerCount!=Math.round(.66*rm_Ocean.clockTimerCutoff)||G.player.CheckIllnessIncrease()}},rm_Ocean.DrawNightDarkness=function(){var e=Math.sin(this.clockTimerCount/(this.clockTimerCutoff*Math.PI)*10*1.5-2)-.4;if(0>e&&(e=0),e>0){var a=OS.context.globalAlpha,r=Oversimplified.context.fillStyle;OS.context.globalAlpha=e,Oversimplified.context.fillStyle="#112189",Oversimplified.context.fillRect(0,0,Oversimplified.camera.width,Oversimplified.camera.height),Oversimplified.context.fillStyle=r,Oversimplified.context.globalAlpha=a}},rm_Ocean.DrawEnergyBar=function(){var e=G.stats.energy/G.stats.maxEnergy,a=pixel(2),r=32,t=pixel(Math.round(r*e)),i=OS.context.fillStyle;OS.context.fillStyle="#0055FF",OS.context.fillRect(64,OS.camera.height-a-16,t,a),OS.context.fillStyle=i},rm_Ocean.DrawClock=function(){var e=OS.camera.width-pixel(9)-pixel(2),a=OS.camera.height-pixel(9)-pixel(2),r=this.clockTimerCount/this.clockTimerCutoff,t=Math.floor(16*r)*pixel(9);OS.context.drawImage(this.clockImg,t,0,pixel(9),pixel(9),e,a,pixel(9),pixel(9))},rm_Ocean.GenerateMap=function(){for(var e=[25],a=[22];e.length<this.numberOfIslands;){for(var r=Math.round(Math.randomRange(2,this.squaresX-2)),t=!1,i=0;i<e.length;i++)if(e[i]-this.squaresX/this.numberOfIslands/2<r&&r<e[i]+this.squaresX/this.numberOfIslands/2){t=!0;break}t||e.push(r)}for(;a.length<this.numberOfIslands;){for(var r=Math.round(Math.randomRange(2,this.squaresY-2)),t=!1,i=0;i<a.length;i++)if(a[i]-this.squaresY/this.numberOfIslands/2<r&&r<a[i]+this.squaresY/this.numberOfIslands/2){t=!0;break}t||a.push(r)}for(var i=0;i<this.numberOfIslands;i++)G.map[i]={island:rm_Ocean.AddObject(OS.P.Island,{x:this.squareSize*e[i],y:this.squareSize*a[i]}),drawX:e[i],drawY:a[i],drawWidth:1,drawHeight:1}};