Added a title screen!

This commit is contained in:
Robbie Antenesse 2016-04-16 23:35:04 -06:00
parent 02285f1d8e
commit f20065727f
11 changed files with 180 additions and 97 deletions

90
gui/titleScreen.js Normal file
View File

@ -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);
}
}
}
}

View File

@ -95,8 +95,8 @@ function drawTradeGUI() {
} }
break; break;
case 1: case 1:
snd_select.Play();
if (G.inventory.CheckCargo().length > 0) { if (G.inventory.CheckCargo().length > 0) {
snd_select.Play();
guiControl.trade.screen = "sell"; guiControl.trade.screen = "sell";
guiControl.trade.activateDelay = 5; guiControl.trade.activateDelay = 5;
} else { } else {

BIN
images/sources/title.pyxel Normal file

Binary file not shown.

BIN
images/title.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,4 +1,5 @@
function loadGUIs() { function loadGUIs() {
OS.AddScript("gui/titleScreen.js");
OS.AddScript("gui/inventoryGUI.js"); OS.AddScript("gui/inventoryGUI.js");
OS.AddScript("gui/mapGUI.js"); OS.AddScript("gui/mapGUI.js");
OS.AddScript("gui/tradeGUI.js"); OS.AddScript("gui/tradeGUI.js");
@ -35,6 +36,8 @@ var guiControl = {
OS.context.drawImage(guiControl.arrows, (direction == "left") ? 0 : pixel(4), 0, pixel(4), pixel(7), xPosition, yPosition, pixel(4), pixel(7)); OS.context.drawImage(guiControl.arrows, (direction == "left") ? 0 : pixel(4), 0, pixel(4), pixel(7), xPosition, yPosition, pixel(4), pixel(7));
} }
} }
guiControl.titleImage = new Image();
guiControl.titleImage.src = "images/title.png";
guiControl.background = new Image(); guiControl.background = new Image();
guiControl.background.src = "images/guiBackground.png"; guiControl.background.src = "images/guiBackground.png";
guiControl.cursor = new Image(); guiControl.cursor = new Image();

View File

@ -1,6 +1,7 @@
var Game = {}; var Game = {};
G = Game; G = Game;
G.gameStarted = false;
G.player = {}; // Just a reference until G.player is created at rm_Ocean's load time. G.player = {}; // Just a reference until G.player is created at rm_Ocean's load time.
G.oceanParticle = {}; // One ocean particle will exist at any time and move around the boat. G.oceanParticle = {}; // One ocean particle will exist at any time and move around the boat.
G.map = []; // List of island objects, generated/loaded and saved at game start, loaded on room start. G.map = []; // List of island objects, generated/loaded and saved at game start, loaded on room start.

View File

@ -1,5 +1,3 @@
// var rm_TitleScreen = OS.R.Add("Default");
// var rm_Ocean = OS.R.Add("Ocean", {
var rm_Ocean = OS.R.Add("Default", { var rm_Ocean = OS.R.Add("Default", {
// Putting my room "constants" here. // Putting my room "constants" here.
width: pixel(64) * 50, //50x45 map of 64x64 squares. This will allow a single pixel on the map to represent a 64x square and fit comfortably on screen. width: pixel(64) * 50, //50x45 map of 64x64 squares. This will allow a single pixel on the map to represent a 64x square and fit comfortably on screen.
@ -18,9 +16,7 @@ rm_Ocean.clockImg = new Image();
rm_Ocean.clockImg.src = "images/clock_sheet.png"; rm_Ocean.clockImg.src = "images/clock_sheet.png";
function loadRooms() { function loadRooms() {
// OS.AddScript("rooms/titleScreen.js");
OS.AddScript("rooms/oceanRoom.js"); OS.AddScript("rooms/oceanRoom.js");
// OS.SetRoom(rm_TitleScreen);
OS.SetRoom(rm_Ocean); OS.SetRoom(rm_Ocean);
} }

View File

@ -19,7 +19,7 @@ var pr_ship = OS.P.Add("Ship", {
currentSpeed: 0, currentSpeed: 0,
pointInFront : {x: 0, y: 0 }, pointInFront : {x: 0, y: 0 },
moveStepSize: 3, moveStepSize: 3,
moveStepAmount: 5 * Oversimplified.R[Oversimplified.R.currentRoom].stepSpeed, moveStepAmount: 5 * OS.R[OS.R.currentRoom].stepSpeed,
moveStepProgress: 0, moveStepProgress: 0,
doTakeStep: false, doTakeStep: false,
@ -30,10 +30,13 @@ var pr_ship = OS.P.Add("Ship", {
}); });
pr_ship.BeforeDo = function () { pr_ship.BeforeDo = function () {
if (G.gameStarted) {
this.GetMapPosition(); this.GetMapPosition();
}
} }
pr_ship.Do = function () { pr_ship.Do = function () {
if (G.gameStarted) {
if (guiControl && guiControl.inventory && guiControl.map && guiControl.trade) { // Force it to wait until loaded. if (guiControl && guiControl.inventory && guiControl.map && guiControl.trade) { // Force it to wait until loaded.
if (!guiControl.inventory.show && !guiControl.map.show && !guiControl.trade.show) { if (!guiControl.inventory.show && !guiControl.map.show && !guiControl.trade.show) {
if (ct_left().down) { if (ct_left().down) {
@ -59,6 +62,7 @@ pr_ship.Do = function () {
this.moveStepProgress += this.currentSpeed * this.moveStepAmount; this.moveStepProgress += this.currentSpeed * this.moveStepAmount;
if (this.moveStepProgress >= this.moveStepSize) { if (this.moveStepProgress >= this.moveStepSize) {
this.moveStepProgress -= this.moveStepSize; this.moveStepProgress -= this.moveStepSize;
console.log("take step");
this.doTakeStep = true; this.doTakeStep = true;
} else { } else {
this.doTakeStep = false; this.doTakeStep = false;
@ -67,14 +71,18 @@ pr_ship.Do = function () {
this.SeamlessScroll(); this.SeamlessScroll();
// console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y); // console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y);
}
} }
pr_ship.AfterDo = function () { pr_ship.AfterDo = function () {
if (G.gameStarted) {
this.CheckMovement(); this.CheckMovement();
this.UpdateEnergy(); this.UpdateEnergy();
}
} }
pr_ship.DrawAbove = function () { pr_ship.DrawAbove = function () {
if (G.gameStarted) {
this.drawSickIndicator--; this.drawSickIndicator--;
if (this.drawSickIndicator < 0) { if (this.drawSickIndicator < 0) {
this.drawSickIndicator = 0; this.drawSickIndicator = 0;
@ -84,6 +92,7 @@ pr_ship.DrawAbove = function () {
var sickIndicatorY = this.y - sickIndicatorHeight - Oversimplified.camera.y - (guiControl.iconScaled / 2); var sickIndicatorY = this.y - sickIndicatorHeight - Oversimplified.camera.y - (guiControl.iconScaled / 2);
guiControl.drawIcon(4, 1, this.x - Oversimplified.camera.x - (guiControl.iconScaled / 2), sickIndicatorY); guiControl.drawIcon(4, 1, this.x - Oversimplified.camera.x - (guiControl.iconScaled / 2), sickIndicatorY);
} }
}
} }
pr_ship.GetMapPosition = function () { pr_ship.GetMapPosition = function () {

View File

@ -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.clockTimerCount = 1; // Set it to 1 so it doesn't check for player illness immediately!
rm_Ocean.DoFirst = function () { 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.x = (this.squareSize * (this.squaresX / 2)) - (this.squareSize / 2) - G.player.xBound;
G.player.y = (this.squareSize * (this.squaresY / 2)); G.player.y = (this.squareSize * (this.squaresY / 2));
@ -42,6 +42,7 @@ rm_Ocean.DoFirst = function () {
// G.economy.UpdateEconomy(); // G.economy.UpdateEconomy();
} }
rm_Ocean.Do = function () { rm_Ocean.Do = function () {
if (G.gameStarted) {
if (guiControl && guiControl.inventory && guiControl.trade) { // Force it to wait until loaded. if (guiControl && guiControl.inventory && guiControl.trade) { // Force it to wait until loaded.
if (!guiControl.inventory.show && !guiControl.map.show && !guiControl.trade.show) { if (!guiControl.inventory.show && !guiControl.map.show && !guiControl.trade.show) {
// Move G.oceanParticle around based on player's movement. // Move G.oceanParticle around based on player's movement.
@ -65,9 +66,11 @@ rm_Ocean.Do = function () {
} }
this.RunClock(); this.RunClock();
}
} }
rm_Ocean.DrawAbove = function () { rm_Ocean.DrawAbove = function () {
if (G.gameStarted) {
this.DrawNightDarkness(); this.DrawNightDarkness();
// Draw the speed indicator in Bottom Left corner. // Draw the speed indicator in Bottom Left corner.
@ -77,11 +80,12 @@ rm_Ocean.DrawAbove = function () {
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(); drawInventoryGUI();
drawMapGUI(); drawMapGUI();
drawTradeGUI(); drawTradeGUI();
} else {
drawTitleScreen();
}
} }
rm_Ocean.DoLast = function () { rm_Ocean.DoLast = function () {
@ -95,6 +99,7 @@ rm_Ocean.RunClock = function () {
if (rm_Ocean.clockTimerCount > rm_Ocean.clockTimerCutoff) { if (rm_Ocean.clockTimerCount > rm_Ocean.clockTimerCutoff) {
rm_Ocean.clockTimerCount = 0; rm_Ocean.clockTimerCount = 0;
// Play New_Day sound. // Play New_Day sound.
// Save the game.
G.economy.UpdateEconomy(); G.economy.UpdateEconomy();
for (var i = 0; i < G.map.length; i++) { for (var i = 0; i < G.map.length; i++) {

View File

@ -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 = {};
}

View File

@ -1,5 +1,5 @@
OS.S.defaultStep = 1 / 120; 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; OS.S.pixelScale = 4;
// Oversimplified.DEBUG.showMessages = false; // Oversimplified.DEBUG.showMessages = false;
OS.SetCamera({ OS.SetCamera({