From f20065727fd728122a08b37b79cce474b200e5a2 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Sat, 16 Apr 2016 23:35:04 -0600 Subject: [PATCH] Added a title screen! --- gui/titleScreen.js | 90 +++++++++++++++++++++++++++++++++++ gui/tradeGUI.js | 2 +- images/sources/title.pyxel | Bin 0 -> 1276 bytes images/title.png | Bin 0 -> 1116 bytes loadGUIs.js | 3 ++ loadGameManager.js | 1 + loadRooms.js | 4 -- prefabs/shipPrefab.js | 93 ++++++++++++++++++++----------------- rooms/oceanRoom.js | 61 +++++++++++++----------- rooms/titleScreen.js | 21 --------- start.js | 2 +- 11 files changed, 180 insertions(+), 97 deletions(-) create mode 100644 gui/titleScreen.js create mode 100644 images/sources/title.pyxel create mode 100644 images/title.png delete mode 100644 rooms/titleScreen.js diff --git a/gui/titleScreen.js b/gui/titleScreen.js new file mode 100644 index 0000000..03be6fa --- /dev/null +++ b/gui/titleScreen.js @@ -0,0 +1,90 @@ +function titleScreen () { + guiControl.title = { + show: true, + cursorPosition: 0, + activateDelay: 0, + + padding: pixel(2), + leftBorder: pixel(12), + + rowTop: function (rowNumber) { + return pixel(32) + pixel(2) + pixel((guiControl.iconSize + 2) * rowNumber); + } + } +} + +function drawTitleScreen() { + if (guiControl.title && guiControl.title.show) { + guiControl.title.activateDelay -= (guiControl.title.activateDelay > 0) ? 1 : 0; + + if (ct_down().down) { + snd_cursordown.Play(); + guiControl.title.cursorPosition++; + } + if (ct_up().down) { + snd_cursorup.Play(); + guiControl.title.cursorPosition--; + } + + // console.log(guiControl.title.screen); + // Limit Cursor + if (guiControl.title.cursorPosition < 0) { + guiControl.title.cursorPosition = 2; + } + if (guiControl.title.cursorPosition > 2) { + guiControl.title.cursorPosition = 0; + } + + // Title + OS.context.drawImage(guiControl.titleImage, 0, 0); + + // New Game + guiControl.drawPixelText("New Game", guiControl.title.leftBorder, guiControl.title.rowTop(0), 10, "white", 6); + // Load Game + guiControl.drawPixelText("Continue", guiControl.title.leftBorder, guiControl.title.rowTop(1), 10, (false) ? "white" : "black", 6); + // Options + guiControl.drawPixelText("Options", guiControl.title.leftBorder, guiControl.title.rowTop(2) + pixel(), 8, "black", 6); + + // Draw cursor + OS.context.drawImage(guiControl.cursor, guiControl.title.leftBorder - (guiControl.iconScaled), guiControl.title.rowTop(guiControl.title.cursorPosition)); + + // Button Action + if (guiControl.title.activateDelay <= 0) { + if (ct_confirm().down) { + switch (guiControl.title.cursorPosition) { + case 0: + snd_select.Play(); + mus_title.Stop(); + mus_sail.Play(); + guiControl.title.show = false; + G.gameStarted = true; + break; + case 1: + if (false) { // once loading is in, allow this. + snd_select.Play(); + mus_title.Stop(); + mus_sail.Play(); + // Run Load Data + guiControl.title.show = false; + G.gameStarted = true; + } else { + snd_cannotbuy.Play(); + } + break; + case 2: + if (false) { // once loading is in, allow this. + snd_select.Play(); + guiControl.title.show = false; + guiControl.options.show = true; + break; + } else { + snd_cannotbuy.Play(); + } + } + + guiControl.title.cursorPosition = 0; + // console.log(guiControl.title.screen); + } + } + } +} diff --git a/gui/tradeGUI.js b/gui/tradeGUI.js index 7d0562a..9a57963 100644 --- a/gui/tradeGUI.js +++ b/gui/tradeGUI.js @@ -95,8 +95,8 @@ function drawTradeGUI() { } break; case 1: - snd_select.Play(); if (G.inventory.CheckCargo().length > 0) { + snd_select.Play(); guiControl.trade.screen = "sell"; guiControl.trade.activateDelay = 5; } else { diff --git a/images/sources/title.pyxel b/images/sources/title.pyxel new file mode 100644 index 0000000000000000000000000000000000000000..5e27b4dbad203eb596c9cf34e3116a8b3faee11a GIT binary patch literal 1276 zcmWIWW@Zs#VBp|j(3&#AgFWr#r$$BwhCj><3_J`B3@Q1^E{P?HdRfK!dAXB)^A9WV zw7vf;D)@XQ(vV$C*#h zvF)&jqK; ziTmEWcx3mdhzndEf`zhELe?w{J#r?gHZY6zte8NJ`w3Z2*3NB$;)KOb4O`KBbx?yr(H(3(2q}xIVzf3woEdVl;5~_dW7cu&;p~)-z{#i+UI z0YgC8$DKB9Tlk{Z%j{{D;FFuU{OAS-oy!X}7^l6t_-K0FLms9jv(Bg_Oxu=yS7DXw zzMmY7o43T~b7nlcnzdb0YC{H7!0uQZ#*BwvjgN0`^kB-++MZ>oRIpZR`jKrR0;UX; z1Ogkv7^gnVTHMl+@hXzzQL3ozsp%5~CZaN_H`JHQ)x6J)Woh?tCVjo@gW?;|p4CH1M zkVCPv<#@cfsI8bg=d#Wzp$Rp0OunkQ$QLLZ4#b>5T#}iS3Qioac|H_Be>&+=QbNLmuU`r{nJ)1; ztT}LyO-20d+HA(4qIr6KilW=^$)!AD{lusHEe*qw7QWCqmyzU=arQb$~Z3 RDBUwK1K~;_ZOa1U0RX#d{&WBU literal 0 HcmV?d00001 diff --git a/images/title.png b/images/title.png new file mode 100644 index 0000000000000000000000000000000000000000..72239252e8d47332d28e8e78ca1a1f9435c55419 GIT binary patch literal 1116 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58aUX1d~M7X3CiB`)}Jf_v4-$`ua*x!2aa-_3QU% zPVeesaByKzP+}06IEyW2Z(ZHb8C8;jf(#uT3@$7TN>Ua6%x>?~S+bAE9|gIA14Mva zqwwAL>!O>Y4CT>F=6u_;`g?zq>{|ElN=6`gWZ)rdag%w{-V-}+30!2mv3G@3?Y#`! zRmao6|KJ2E0~-ZmEXlvPUV28x;rDFocgtOty1;)LB#Hz$7~UB@+|4-SpA8dG)Bz*| zc1)!n!&Uvs3<+;5_uOFyiK2iTri|tLb%f@A@Mk`7P!B~4#A#S}{`I{NO1~e7=`*9c zhlRmd{l^wxM@9vZIu;;q05K-4V%)~){`RwrxGXqMKw=1RqxAoqW^+IGgspWKrx&g= z&)L`rb|XRs1H&EhhSld+-&081%DCHpe|2;3i_a2%G$)aJM8_tww3GBOPVLH{$1LC|A#BO26yHSyB;37D|WWbyrzUHB>zR=Ud~sq z{x14@^KQXS=`CBnbEDeO;La#8H(@!mK<); zRV$eHfrnw;KRE$3nKgoMW(&leE>6;0u*R6k7qDC7?%m4U> z%= this.moveStepSize) { + this.moveStepProgress -= this.moveStepSize; + console.log("take step"); + this.doTakeStep = true; + } else { + this.doTakeStep = false; + } + + + this.SeamlessScroll(); + // console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y); } - - this.currentSpeed = Math.clamp(this.currentSpeed, 0, 4); - - this.moveStepProgress += this.currentSpeed * this.moveStepAmount; - if (this.moveStepProgress >= this.moveStepSize) { - this.moveStepProgress -= this.moveStepSize; - this.doTakeStep = true; - } else { - this.doTakeStep = false; - } - - - this.SeamlessScroll(); - // console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y); } pr_ship.AfterDo = function () { - this.CheckMovement(); - this.UpdateEnergy(); + if (G.gameStarted) { + this.CheckMovement(); + this.UpdateEnergy(); + } } pr_ship.DrawAbove = function () { - this.drawSickIndicator--; - if (this.drawSickIndicator < 0) { - this.drawSickIndicator = 0; - } - if (this.drawSickIndicator > 0) { - var sickIndicatorHeight = Math.round((this.drawSickIndicatorTime - this.drawSickIndicator) / 2) / OS.S.pixelScale; - var sickIndicatorY = this.y - sickIndicatorHeight - Oversimplified.camera.y - (guiControl.iconScaled / 2); - guiControl.drawIcon(4, 1, this.x - Oversimplified.camera.x - (guiControl.iconScaled / 2), sickIndicatorY); + if (G.gameStarted) { + this.drawSickIndicator--; + if (this.drawSickIndicator < 0) { + this.drawSickIndicator = 0; + } + if (this.drawSickIndicator > 0) { + var sickIndicatorHeight = Math.round((this.drawSickIndicatorTime - this.drawSickIndicator) / 2) / OS.S.pixelScale; + var sickIndicatorY = this.y - sickIndicatorHeight - Oversimplified.camera.y - (guiControl.iconScaled / 2); + guiControl.drawIcon(4, 1, this.x - Oversimplified.camera.x - (guiControl.iconScaled / 2), sickIndicatorY); + } } } diff --git a/rooms/oceanRoom.js b/rooms/oceanRoom.js index 8773b4f..e051eb6 100644 --- a/rooms/oceanRoom.js +++ b/rooms/oceanRoom.js @@ -14,7 +14,7 @@ rm_Ocean.waveTimer = Math.round(Math.randomRange(30, 150)); rm_Ocean.clockTimerCount = 1; // Set it to 1 so it doesn't check for player illness immediately! rm_Ocean.DoFirst = function () { - mus_sail.Play(); + 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)); @@ -42,46 +42,50 @@ rm_Ocean.DoFirst = function () { // G.economy.UpdateEconomy(); } rm_Ocean.Do = function () { - if (guiControl && guiControl.inventory && guiControl.trade) { // Force it to wait until loaded. - if (!guiControl.inventory.show && !guiControl.map.show && !guiControl.trade.show) { - // Move G.oceanParticle around based on player's movement. - if (G.oceanParticle.CheckPosition) G.oceanParticle.CheckPosition(G.player.x, G.player.y, G.player.direction); + if (G.gameStarted) { + if (guiControl && guiControl.inventory && guiControl.trade) { // Force it to wait until loaded. + if (!guiControl.inventory.show && !guiControl.map.show && !guiControl.trade.show) { + // Move G.oceanParticle around based on player's movement. + if (G.oceanParticle.CheckPosition) G.oceanParticle.CheckPosition(G.player.x, G.player.y, G.player.direction); - this.waveTimer--; - if (this.waveTimer <= 0) { - var wave = this.AddObject(OS.P["Wave Particle"]); - wave.x = G.player.x + (randomSmidge() * 4); - wave.y = G.player.y + (randomSmidge() * 4); + this.waveTimer--; + if (this.waveTimer <= 0) { + var wave = this.AddObject(OS.P["Wave Particle"]); + wave.x = G.player.x + (randomSmidge() * 4); + wave.y = G.player.y + (randomSmidge() * 4); - this.waveTimer = Math.round(Math.randomRange(30, 150)); - } + this.waveTimer = Math.round(Math.randomRange(30, 150)); + } - if (ct_cancel().down) { - snd_select.Play(); - guiControl.inventory.activateDelay = 5; - guiControl.inventory.show = true; + if (ct_cancel().down) { + snd_select.Play(); + guiControl.inventory.activateDelay = 5; + guiControl.inventory.show = true; + } } } - } - this.RunClock(); + this.RunClock(); + } } rm_Ocean.DrawAbove = function () { - this.DrawNightDarkness(); + if (G.gameStarted) { + this.DrawNightDarkness(); - // Draw the speed indicator in Bottom Left corner. - OS.context.drawImage(rm_Ocean.speedGaugeImg, G.player.currentSpeed * 32, 0, 32, 32, 16, OS.camera.height - 32 - 16, 32, 32); + // Draw the speed indicator in Bottom Left corner. + OS.context.drawImage(rm_Ocean.speedGaugeImg, G.player.currentSpeed * 32, 0, 32, 32, 16, OS.camera.height - 32 - 16, 32, 32); - this.DrawEnergyBar(); + this.DrawEnergyBar(); - this.DrawClock(); + this.DrawClock(); - // drawPixelText("Testing 1 2 3!", 0, 0, 0, "white", 4); - // drawPixelText("Testing 1 2 3!", 0, 64, 0, "white", 6); - drawInventoryGUI(); - drawMapGUI(); - drawTradeGUI(); + drawInventoryGUI(); + drawMapGUI(); + drawTradeGUI(); + } else { + drawTitleScreen(); + } } rm_Ocean.DoLast = function () { @@ -95,6 +99,7 @@ rm_Ocean.RunClock = function () { if (rm_Ocean.clockTimerCount > rm_Ocean.clockTimerCutoff) { rm_Ocean.clockTimerCount = 0; // Play New_Day sound. + // Save the game. G.economy.UpdateEconomy(); for (var i = 0; i < G.map.length; i++) { diff --git a/rooms/titleScreen.js b/rooms/titleScreen.js deleted file mode 100644 index b41eda2..0000000 --- a/rooms/titleScreen.js +++ /dev/null @@ -1,21 +0,0 @@ -function titleScreen () { - // When room is loaded, explicitly set room to rm_TitleScreen, just in case "Default" doesn't work/is loaded too slowly - OS.SetRoom(rm_TitleScreen); -} - -rm_TitleScreen.Do = function () { - // Menu options. -} -rm_TitleScreen.DrawBelow = function () { - // Fill background color because I can't figure out how to make OversimplifiedJS change the bg color on room change! - var tmp = Oversimplified.context.fillStyle; - Oversimplified.context.fillStyle = "#D9BEA5"; - Oversimplified.context.fillRect(0, 0, Oversimplified.camera.width, Oversimplified.camera.height); - Oversimplified.context.fillStyle = tmp; - - -} -rm_TitleScreen.DoLast = function () { - // Clear Objects on room exit. This is best practice unless you need persistent objects. - rm_TitleScreen.objects = {}; -} \ No newline at end of file diff --git a/start.js b/start.js index 720040e..4d19d90 100644 --- a/start.js +++ b/start.js @@ -1,5 +1,5 @@ OS.S.defaultStep = 1 / 120; -OS.S.numberOfScriptsToLoad = 15; // Excludes the titleScreen.js room, which is not loaded yet. +OS.S.numberOfScriptsToLoad = 16; OS.S.pixelScale = 4; // Oversimplified.DEBUG.showMessages = false; OS.SetCamera({