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;
case 1:
snd_select.Play();
if (G.inventory.CheckCargo().length > 0) {
snd_select.Play();
guiControl.trade.screen = "sell";
guiControl.trade.activateDelay = 5;
} 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() {
OS.AddScript("gui/titleScreen.js");
OS.AddScript("gui/inventoryGUI.js");
OS.AddScript("gui/mapGUI.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));
}
}
guiControl.titleImage = new Image();
guiControl.titleImage.src = "images/title.png";
guiControl.background = new Image();
guiControl.background.src = "images/guiBackground.png";
guiControl.cursor = new Image();

View File

@ -1,6 +1,7 @@
var Game = {};
G = Game;
G.gameStarted = false;
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.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", {
// 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.
@ -18,9 +16,7 @@ rm_Ocean.clockImg = new Image();
rm_Ocean.clockImg.src = "images/clock_sheet.png";
function loadRooms() {
// OS.AddScript("rooms/titleScreen.js");
OS.AddScript("rooms/oceanRoom.js");
// OS.SetRoom(rm_TitleScreen);
OS.SetRoom(rm_Ocean);
}

View File

@ -19,7 +19,7 @@ var pr_ship = OS.P.Add("Ship", {
currentSpeed: 0,
pointInFront : {x: 0, y: 0 },
moveStepSize: 3,
moveStepAmount: 5 * Oversimplified.R[Oversimplified.R.currentRoom].stepSpeed,
moveStepAmount: 5 * OS.R[OS.R.currentRoom].stepSpeed,
moveStepProgress: 0,
doTakeStep: false,
@ -30,59 +30,68 @@ var pr_ship = OS.P.Add("Ship", {
});
pr_ship.BeforeDo = function () {
this.GetMapPosition();
if (G.gameStarted) {
this.GetMapPosition();
}
}
pr_ship.Do = function () {
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 (ct_left().down) {
this.direction += 45;
} else if (ct_right().down) {
this.direction -= 45;
}
this.direction = Math.clampAngle(this.direction);
if (ct_up().down) {
this.currentSpeed++;
} else if (ct_down().down) {
this.currentSpeed--;
}
this.AdjustSpeedBasedOnEnergy();
if (G.gameStarted) {
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 (ct_left().down) {
this.direction += 45;
} else if (ct_right().down) {
this.direction -= 45;
}
this.direction = Math.clampAngle(this.direction);
if (ct_up().down) {
this.currentSpeed++;
} else if (ct_down().down) {
this.currentSpeed--;
}
this.AdjustSpeedBasedOnEnergy();
this.CheckInteraction();
this.CheckInteraction();
}
}
this.currentSpeed = Math.clamp(this.currentSpeed, 0, 4);
this.moveStepProgress += this.currentSpeed * this.moveStepAmount;
if (this.moveStepProgress >= 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);
}
}
}

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.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++) {

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.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({