Update code styles and spacing

This commit is contained in:
Robbie Antenesse 2019-02-13 12:11:30 -07:00
parent 27e95d4011
commit 7b8729d4e0
19 changed files with 2074 additions and 1995 deletions

View File

@ -1,217 +1,221 @@
function inventoryGUI() { function inventoryGUI() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran inventoryGUI()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran inventoryGUI()");
} }
guiControl.inventory = { guiControl.inventory = {
screen: "main", screen: "main",
cursorPosition: 0, cursorPosition: 0,
show: false, show: false,
activateDelay: 0 activateDelay: 0,
} }
guiControl.inventory.Draw = function () { guiControl.inventory.Draw = function () {
if (guiControl.inventory && guiControl.inventory.show) { if (guiControl.inventory && guiControl.inventory.show) {
guiControl.inventory.activateDelay -= (guiControl.inventory.activateDelay > 0) ? 1 : 0; guiControl.inventory.activateDelay -= (guiControl.inventory.activateDelay > 0) ? 1 : 0;
guiControl.drawGUIBackground(); guiControl.drawGUIBackground();
if (ct_down().down) { if (ct_down().down) {
snd_cursordown.Play(); snd_cursordown.Play();
guiControl.inventory.cursorPosition++; guiControl.inventory.cursorPosition++;
} }
if (ct_up().down) { if (ct_up().down) {
snd_cursordown.Play(); snd_cursordown.Play();
guiControl.inventory.cursorPosition--; guiControl.inventory.cursorPosition--;
} }
if (guiControl.inventory.screen == "main") { if (guiControl.inventory.screen == "main") {
// Limit Cursor // Limit Cursor
if (guiControl.inventory.cursorPosition < 0) { if (guiControl.inventory.cursorPosition < 0) {
guiControl.inventory.cursorPosition = 3; guiControl.inventory.cursorPosition = 3;
} }
if (guiControl.inventory.cursorPosition > 3) { if (guiControl.inventory.cursorPosition > 3) {
guiControl.inventory.cursorPosition = 0; guiControl.inventory.cursorPosition = 0;
} }
// Title // Title
guiControl.drawPixelText("Storage", guiControl.leftBorder - pixel(2), guiControl.topOfBackground, 8, "black", 6); guiControl.drawPixelText("Storage", guiControl.leftBorder - pixel(2), guiControl.topOfBackground, 8, "black", 6);
guiControl.drawPageArrow("left", pixel(4), guiControl.topOfBackground); guiControl.drawPageArrow("left", pixel(4), guiControl.topOfBackground);
guiControl.drawPageArrow("right", OS.camera.width - pixel(4) - pixel(4), guiControl.topOfBackground); guiControl.drawPageArrow("right", OS.camera.width - pixel(4) - pixel(4), guiControl.topOfBackground);
// Money icon // Money icon
guiControl.drawIcon(7, 2, guiControl.leftBorder, guiControl.rowTop(0)); guiControl.drawIcon(7, 2, guiControl.leftBorder, guiControl.rowTop(0));
guiControl.drawPixelText(G.inventory.moneyDisplay(), guiControl.leftBorder + pixel(guiControl.iconSize + 4), guiControl.rowTop(0) + pixel(), 8, "black", 6); guiControl.drawPixelText(G.inventory.moneyDisplay(), guiControl.leftBorder + pixel(guiControl.iconSize + 4), guiControl.rowTop(0) + pixel(), 8, "black", 6);
// Cargo icon // Cargo icon
guiControl.drawIcon(1, 0, guiControl.leftBorder, guiControl.rowTop(1)); guiControl.drawIcon(1, 0, guiControl.leftBorder, guiControl.rowTop(1));
guiControl.drawPixelText(G.inventory.CargoTotal().toString(), guiControl.leftBorder + pixel(guiControl.iconSize + 4), guiControl.rowTop(1) + pixel(), 8, "black", 6); guiControl.drawPixelText(G.inventory.CargoTotal().toString(), guiControl.leftBorder + pixel(guiControl.iconSize + 4), guiControl.rowTop(1) + pixel(), 8, "black", 6);
// Stats icon // Stats icon
// guiControl.drawIcon(9, 2, guiControl.leftBorder, guiControl.rowTop(2)); // guiControl.drawIcon(9, 2, guiControl.leftBorder, guiControl.rowTop(2));
guiControl.drawPixelText("Status", guiControl.leftBorder, guiControl.rowTop(2) + pixel(), 8, "black", 6); guiControl.drawPixelText("Status", guiControl.leftBorder, guiControl.rowTop(2) + pixel(), 8, "black", 6);
// Close Text // Close Text
guiControl.drawPixelText("Close", guiControl.leftBorder, guiControl.rowTop(3) + pixel(), 8, "black", 6); guiControl.drawPixelText("Close", guiControl.leftBorder, guiControl.rowTop(3) + pixel(), 8, "black", 6);
// Draw cursor // Draw cursor
guiControl.drawCursor(guiControl.leftBorder - (guiControl.iconScaled), guiControl.rowTop(guiControl.inventory.cursorPosition)); guiControl.drawCursor(guiControl.leftBorder - (guiControl.iconScaled), guiControl.rowTop(guiControl.inventory.cursorPosition));
// Button Action // Button Action
if (guiControl.inventory.activateDelay <= 0) { if (guiControl.inventory.activateDelay <= 0) {
if (ct_confirm().down) { if (ct_confirm().down) {
switch (guiControl.inventory.cursorPosition) { switch (guiControl.inventory.cursorPosition) {
case 0: case 0: {
snd_select.Play(); snd_select.Play();
guiControl.inventory.screen = "money"; guiControl.inventory.screen = "money";
break; break;
case 1: }
snd_select.Play(); case 1: {
guiControl.inventory.screen = "cargo"; snd_select.Play();
guiControl.inventory.screen = "cargo";
break; break;
case 2: }
snd_select.Play(); case 2: {
guiControl.inventory.screen = "status"; snd_select.Play();
guiControl.inventory.screen = "status";
break; break;
default: }
snd_cursorup.Play(); default: {
guiControl.inventory.show = false; snd_cursorup.Play();
guiControl.inventory.show = false;
break; break;
} }
}
guiControl.inventory.cursorPosition = 0; guiControl.inventory.cursorPosition = 0;
guiControl.inventory.activateDelay = 5; guiControl.inventory.activateDelay = 5;
} }
if (ct_cancel().down) { if (ct_cancel().down) {
snd_cursorup.Play(); snd_cursorup.Play();
guiControl.inventory.show = false; guiControl.inventory.show = false;
} }
if (ct_left().down) { if (ct_left().down) {
snd_cursordown.Play(); snd_cursordown.Play();
guiControl.inventory.show = false; guiControl.inventory.show = false;
guiControl.map.activateDelay = 5; guiControl.map.activateDelay = 5;
guiControl.map.show = true; guiControl.map.show = true;
} }
if (ct_right().down) { if (ct_right().down) {
snd_cursordown.Play(); snd_cursordown.Play();
guiControl.inventory.show = false; guiControl.inventory.show = false;
guiControl.map.activateDelay = 5; guiControl.map.activateDelay = 5;
guiControl.map.show = true; guiControl.map.show = true;
} }
} }
} }
else if (guiControl.inventory.screen == "money") { else if (guiControl.inventory.screen == "money") {
// Limit Cursor // Limit Cursor
if (guiControl.inventory.cursorPosition < 0) { if (guiControl.inventory.cursorPosition < 0) {
guiControl.inventory.cursorPosition = 0; guiControl.inventory.cursorPosition = 0;
} }
if (guiControl.inventory.cursorPosition > 0) { if (guiControl.inventory.cursorPosition > 0) {
guiControl.inventory.cursorPosition = 0; guiControl.inventory.cursorPosition = 0;
} }
// Title // Title
guiControl.drawPixelText("Money", guiControl.leftBorder + pixel(3), guiControl.topOfBackground, 8, "black", 6); guiControl.drawPixelText("Money", guiControl.leftBorder + pixel(3), guiControl.topOfBackground, 8, "black", 6);
guiControl.drawPixelText("Actual Amt", guiControl.leftBorder - pixel(5), guiControl.rowTop(0) + pixel(), 10, "black", 4); guiControl.drawPixelText("Actual Amt", guiControl.leftBorder - pixel(5), guiControl.rowTop(0) + pixel(), 10, "black", 4);
// Money icon // Money icon
guiControl.drawIcon(7, 2, guiControl.leftBorder - pixel(5), guiControl.rowTop(1) - pixel(3)); guiControl.drawIcon(7, 2, guiControl.leftBorder - pixel(5), guiControl.rowTop(1) - pixel(3));
guiControl.drawPixelText(G.inventory.money.toString(), guiControl.leftBorder - pixel(5) + pixel(guiControl.iconSize + 2), guiControl.rowTop(1) + pixel(2) - pixel(3), 10, "black", 4); guiControl.drawPixelText(G.inventory.money.toString(), guiControl.leftBorder - pixel(5) + pixel(guiControl.iconSize + 2), guiControl.rowTop(1) + pixel(2) - pixel(3), 10, "black", 4);
// Back Text // Back Text
guiControl.drawPixelText("Back", guiControl.leftBorder, guiControl.rowTop(4) - pixel(3), 8, "black", 6); guiControl.drawPixelText("Back", guiControl.leftBorder, guiControl.rowTop(4) - pixel(3), 8, "black", 6);
// Draw cursor // Draw cursor
guiControl.drawCursor(guiControl.leftBorder - (guiControl.iconScaled), guiControl.rowTop(4) - pixel(4)); guiControl.drawCursor(guiControl.leftBorder - (guiControl.iconScaled), guiControl.rowTop(4) - pixel(4));
// Button Action // Button Action
if (guiControl.inventory.activateDelay <= 0) { if (guiControl.inventory.activateDelay <= 0) {
if (ct_confirm().down || ct_cancel().down) { if (ct_confirm().down || ct_cancel().down) {
snd_cursorup.Play(); snd_cursorup.Play();
guiControl.inventory.screen = "main"; guiControl.inventory.screen = "main";
guiControl.inventory.activateDelay = 5; guiControl.inventory.activateDelay = 5;
guiControl.inventory.cursorPosition = 0; guiControl.inventory.cursorPosition = 0;
} }
} }
} }
else if (guiControl.inventory.screen == "cargo") { else if (guiControl.inventory.screen == "cargo") {
// Limit Cursor // Limit Cursor
if (guiControl.inventory.cursorPosition < 0) { if (guiControl.inventory.cursorPosition < 0) {
guiControl.inventory.cursorPosition = 0; guiControl.inventory.cursorPosition = 0;
} }
if (guiControl.inventory.cursorPosition > 0) { if (guiControl.inventory.cursorPosition > 0) {
guiControl.inventory.cursorPosition = 0; guiControl.inventory.cursorPosition = 0;
} }
// Title // Title
guiControl.drawPixelText("Cargo", guiControl.leftBorder + pixel(3), guiControl.topOfBackground, 8, "black", 6); guiControl.drawPixelText("Cargo", guiControl.leftBorder + pixel(3), guiControl.topOfBackground, 8, "black", 6);
// Cargo icons // Cargo icons
var cargo = G.inventory.CheckCargo(); // Contains the item ids that have more than 1 item var cargo = G.inventory.CheckCargo(); // Contains the item ids that have more than 1 item
for (var i = 0; i < cargo.length; i++) { for (var i = 0; i < cargo.length; i++) {
guiControl.drawItem(cargo[i], guiControl.leftBorder, guiControl.rowTop(i)); guiControl.drawItem(cargo[i], guiControl.leftBorder, guiControl.rowTop(i));
guiControl.drawPixelText(G.inventory.cargo[cargo[i]], guiControl.leftBorder + pixel(guiControl.iconSize + 4), guiControl.rowTop(i) + pixel(), 8, "black", 6); guiControl.drawPixelText(G.inventory.cargo[cargo[i]], guiControl.leftBorder + pixel(guiControl.iconSize + 4), guiControl.rowTop(i) + pixel(), 8, "black", 6);
} }
// Back Text // Back Text
guiControl.drawPixelText("Back", guiControl.leftBorder, guiControl.rowTop(4) - pixel(3), 8, "black", 6); guiControl.drawPixelText("Back", guiControl.leftBorder, guiControl.rowTop(4) - pixel(3), 8, "black", 6);
// Draw cursor // Draw cursor
guiControl.drawCursor(guiControl.leftBorder - (guiControl.iconScaled), guiControl.rowTop(4) - pixel(4)); guiControl.drawCursor(guiControl.leftBorder - (guiControl.iconScaled), guiControl.rowTop(4) - pixel(4));
// Button Action // Button Action
if (guiControl.inventory.activateDelay <= 0) { if (guiControl.inventory.activateDelay <= 0) {
if (ct_confirm().down || ct_cancel().down) { if (ct_confirm().down || ct_cancel().down) {
snd_cursorup.Play(); snd_cursorup.Play();
guiControl.inventory.screen = "main"; guiControl.inventory.screen = "main";
guiControl.inventory.activateDelay = 5; guiControl.inventory.activateDelay = 5;
guiControl.inventory.cursorPosition = 1; guiControl.inventory.cursorPosition = 1;
} }
} }
} }
else if (guiControl.inventory.screen == "status") { else if (guiControl.inventory.screen == "status") {
// Limit Cursor // Limit Cursor
if (guiControl.inventory.cursorPosition < 0) { if (guiControl.inventory.cursorPosition < 0) {
guiControl.inventory.cursorPosition = 0; guiControl.inventory.cursorPosition = 0;
} }
if (guiControl.inventory.cursorPosition > 0) { if (guiControl.inventory.cursorPosition > 0) {
guiControl.inventory.cursorPosition = 0; guiControl.inventory.cursorPosition = 0;
} }
// guiControl.drawPageArrow("left", pixel(4), guiControl.topOfBackground); // guiControl.drawPageArrow("left", pixel(4), guiControl.topOfBackground);
// guiControl.drawPageArrow("right", OS.camera.width - pixel(4) - pixel(4), guiControl.topOfBackground); // guiControl.drawPageArrow("right", OS.camera.width - pixel(4) - pixel(4), guiControl.topOfBackground);
// Title // Title
guiControl.drawPixelText("Status", guiControl.leftBorder + pixel(), guiControl.topOfBackground, 8, "black", 6); guiControl.drawPixelText("Status", guiControl.leftBorder + pixel(), guiControl.topOfBackground, 8, "black", 6);
// Illness icon // Illness icon
guiControl.drawIcon(4, 1, guiControl.leftBorder - pixel(6), guiControl.rowTop(0)); guiControl.drawIcon(4, 1, guiControl.leftBorder - pixel(6), guiControl.rowTop(0));
guiControl.drawPixelText(G.stats.illness.toString(), guiControl.leftBorder - pixel(6) + (guiControl.iconScaled + pixel(2)), guiControl.rowTop(0) + pixel(2), 2, "black", 4); guiControl.drawPixelText(G.stats.illness.toString(), guiControl.leftBorder - pixel(6) + (guiControl.iconScaled + pixel(2)), guiControl.rowTop(0) + pixel(2), 2, "black", 4);
guiControl.drawPixelText("This will show more data when stati can change.", guiControl.leftBorder - pixel(5), guiControl.rowTop(1), 10, "black", 4); guiControl.drawPixelText("This will show more data when stati can change.", guiControl.leftBorder - pixel(5), guiControl.rowTop(1), 10, "black", 4);
/*// Energy icon /*// Energy icon
guiControl.drawIcon(9, 2, guiControl.leftBorder - pixel(5), guiControl.rowTop(0) - pixel(3)); guiControl.drawIcon(9, 2, guiControl.leftBorder - pixel(5), guiControl.rowTop(0) - pixel(3));
guiControl.drawPixelText(G.stats.energy.toString(), guiControl.leftBorder - pixel(5) + pixel(guiControl.iconSize + 2), guiControl.rowTop(1) + pixel(2) - pixel(3), 2, "black", 4); guiControl.drawPixelText(G.stats.energy.toString(), guiControl.leftBorder - pixel(5) + pixel(guiControl.iconSize + 2), guiControl.rowTop(1) + pixel(2) - pixel(3), 2, "black", 4);
// Illness icon // Illness icon
guiControl.drawIcon(4, 1, guiControl.leftBorder - pixel(5) + pixel(24), guiControl.rowTop(1) - pixel(3)); guiControl.drawIcon(4, 1, guiControl.leftBorder - pixel(5) + pixel(24), guiControl.rowTop(1) - pixel(3));
guiControl.drawPixelText(G.stats.illness.toString(), guiControl.leftBorder - pixel(5) + pixel(24) + pixel(guiControl.iconSize + 2), guiControl.rowTop(1) + pixel(2) - pixel(3), 2, "black", 4); guiControl.drawPixelText(G.stats.illness.toString(), guiControl.leftBorder - pixel(5) + pixel(24) + pixel(guiControl.iconSize + 2), guiControl.rowTop(1) + pixel(2) - pixel(3), 2, "black", 4);
// Yes/No options // Yes/No options
guiControl.drawPixelText("No", guiControl.leftBorder, guiControl.rowTop(2) - pixel(3), 3, "black", 6); guiControl.drawPixelText("No", guiControl.leftBorder, guiControl.rowTop(2) - pixel(3), 3, "black", 6);
guiControl.drawPixelText("Yes", guiControl.leftBorder, guiControl.rowTop(3) - pixel(3), 3, (G.inventory.supplies > 0 && G.stats.illness > 0) ? "black" : "white", 6); guiControl.drawPixelText("Yes", guiControl.leftBorder, guiControl.rowTop(3) - pixel(3), 3, (G.inventory.supplies > 0 && G.stats.illness > 0) ? "black" : "white", 6);
*/ */
// Back Text // Back Text
guiControl.drawPixelText("Back", guiControl.leftBorder, guiControl.rowTop(4) - pixel(3), 8, "black", 6); guiControl.drawPixelText("Back", guiControl.leftBorder, guiControl.rowTop(4) - pixel(3), 8, "black", 6);
// Draw cursor // Draw cursor
guiControl.drawCursor(guiControl.leftBorder - (guiControl.iconScaled), guiControl.rowTop(4) - pixel(3)); guiControl.drawCursor(guiControl.leftBorder - (guiControl.iconScaled), guiControl.rowTop(4) - pixel(3));
// Button Action // Button Action
if (guiControl.inventory.activateDelay <= 0) { if (guiControl.inventory.activateDelay <= 0) {
if (ct_confirm().down || ct_cancel().down) { if (ct_confirm().down || ct_cancel().down) {
snd_cursorup.Play(); snd_cursorup.Play();
guiControl.inventory.screen = "main"; guiControl.inventory.screen = "main";
guiControl.inventory.activateDelay = 5; guiControl.inventory.activateDelay = 5;
guiControl.inventory.cursorPosition = 2; // The position where "Supplies" is on main screen. guiControl.inventory.cursorPosition = 2; // The position where "Supplies" is on main screen.
} }
} }
} }
} }
} }

View File

@ -1,62 +1,62 @@
function mapGUI() { function mapGUI() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran mapGUI()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran mapGUI()");
} }
guiControl.map = { guiControl.map = {
show: false, show: false,
activateDelay: 0 activateDelay: 0,
} }
guiControl.map.Draw = function () { guiControl.map.Draw = function () {
if (guiControl.map && guiControl.map.show) { if (guiControl.map && guiControl.map.show) {
guiControl.map.activateDelay -= (guiControl.map.activateDelay > 0) ? 1 : 0; guiControl.map.activateDelay -= (guiControl.map.activateDelay > 0) ? 1 : 0;
guiControl.drawGUIBackground(); guiControl.drawGUIBackground();
// Title // Title
guiControl.drawPixelText("Map", guiControl.leftBorder + pixel(10), guiControl.topOfBackground, 8, "black", 6); guiControl.drawPixelText("Map", guiControl.leftBorder + pixel(10), guiControl.topOfBackground, 8, "black", 6);
guiControl.drawPageArrow("left", pixel(4), guiControl.topOfBackground); guiControl.drawPageArrow("left", pixel(4), guiControl.topOfBackground);
guiControl.drawPageArrow("right", OS.camera.width - pixel(4) - pixel(4), guiControl.topOfBackground); guiControl.drawPageArrow("right", OS.camera.width - pixel(4) - pixel(4), guiControl.topOfBackground);
var saveFillStyle = OS.context.fillStyle; var saveFillStyle = OS.context.fillStyle;
var mapLeft = guiControl.leftBorder - pixel(5); var mapLeft = guiControl.leftBorder - pixel(5);
var mapTop = guiControl.upperBorder; var mapTop = guiControl.upperBorder;
OS.context.fillStyle = "#0000CC"; OS.context.fillStyle = "#0000CC";
OS.context.fillRect(mapLeft, mapTop, pixel(50), pixel(45)); OS.context.fillRect(mapLeft, mapTop, pixel(50), pixel(45));
OS.context.fillStyle = "#00FF00"; OS.context.fillStyle = "#00FF00";
for (var m = 0; m < G.map.length; m++) { for (var m = 0; m < G.map.length; m++) {
var pixelLeft = mapLeft + pixel(G.map[m].drawX); var pixelLeft = mapLeft + pixel(G.map[m].drawX);
var pixelTop = mapTop + pixel(G.map[m].drawY); var pixelTop = mapTop + pixel(G.map[m].drawY);
OS.context.fillRect(pixelLeft, pixelTop, pixel(), pixel()); OS.context.fillRect(pixelLeft, pixelTop, pixel(), pixel());
} }
OS.context.fillStyle = "#FF0000"; OS.context.fillStyle = "#FF0000";
OS.context.fillRect(mapLeft + G.player.mapX, mapTop + G.player.mapY, pixel(), pixel()); OS.context.fillRect(mapLeft + G.player.mapX, mapTop + G.player.mapY, pixel(), pixel());
OS.context.fillStyle = saveFillStyle; OS.context.fillStyle = saveFillStyle;
// Button Action // Button Action
if (guiControl.map.activateDelay <= 0) { if (guiControl.map.activateDelay <= 0) {
if (ct_confirm().down || ct_cancel().down || ct_m.down) { if (ct_confirm().down || ct_cancel().down || ct_m.down) {
snd_cursorup.Play(); snd_cursorup.Play();
guiControl.map.show = false; guiControl.map.show = false;
} }
if (ct_left().down) { if (ct_left().down) {
snd_cursordown.Play(); snd_cursordown.Play();
guiControl.map.show = false; guiControl.map.show = false;
guiControl.inventory.activateDelay = 5; guiControl.inventory.activateDelay = 5;
guiControl.inventory.show = true; guiControl.inventory.show = true;
} }
if (ct_right().down) { if (ct_right().down) {
snd_cursordown.Play(); snd_cursordown.Play();
guiControl.map.show = false; guiControl.map.show = false;
guiControl.inventory.activateDelay = 5; guiControl.inventory.activateDelay = 5;
guiControl.inventory.show = true; guiControl.inventory.show = true;
} }
} }
} }
} }

View File

@ -3,111 +3,114 @@ function titleScreen () {
} }
guiControl.title = { guiControl.title = {
screen: "main", screen: "main",
show: true, show: true,
cursorPosition: 0, cursorPosition: 0,
activateDelay: 0, activateDelay: 0,
padding: pixel(2), padding: pixel(2),
leftBorder: pixel(12), leftBorder: pixel(12),
rowTop: function (rowNumber) { rowTop: function (rowNumber) {
return pixel(32) + pixel(2) + pixel((guiControl.iconSize + 2) * rowNumber); return pixel(32) + pixel(2) + pixel((guiControl.iconSize + 2) * rowNumber);
} },
} }
guiControl.title.Draw = function () { guiControl.title.Draw = function () {
if (guiControl.title && guiControl.title.show) { if (guiControl.title && guiControl.title.show) {
guiControl.title.activateDelay -= (guiControl.title.activateDelay > 0) ? 1 : 0; guiControl.title.activateDelay -= (guiControl.title.activateDelay > 0) ? 1 : 0;
if (guiControl.title.screen == "main") { if (guiControl.title.screen == "main") {
if (ct_down().down) { if (ct_down().down) {
snd_cursordown.Play(); snd_cursordown.Play();
guiControl.title.cursorPosition++; guiControl.title.cursorPosition++;
}
if (ct_up().down) {
snd_cursordown.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
guiControl.drawTitleImage();
// 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, (G.savedGameExists) ? "white" : "black", 6);
// Options
guiControl.drawPixelText("Options", guiControl.title.leftBorder, guiControl.title.rowTop(2) + pixel(), 8, (guiControl.optionsScreen) ? "white" : "black", 6);
// Draw cursor
guiControl.drawCursor(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;
G.SaveGame();
break;
} }
if (ct_up().down) { case 1: {
snd_cursordown.Play(); if (G.savedGameExists) { // once loading is in, allow this.
guiControl.title.cursorPosition--; G.LoadGame();
snd_select.Play();
mus_title.Stop();
mus_sail.Play();
guiControl.title.show = false;
G.gameStarted = true;
} else {
snd_cannotbuy.Play();
}
break;
} }
case 2: {
// console.log(guiControl.title.screen); if (false) { // once loading is in, allow this.
// Limit Cursor snd_select.Play();
if (guiControl.title.cursorPosition < 0) { guiControl.title.show = false;
guiControl.title.cursorPosition = 2; guiControl.options.show = true;
} break;
if (guiControl.title.cursorPosition > 2) { } else {
guiControl.title.cursorPosition = 0; snd_cannotbuy.Play();
}
} }
}
// Title guiControl.title.cursorPosition = 0;
guiControl.drawTitleImage(); // console.log(guiControl.title.screen);
// 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, (G.savedGameExists) ? "white" : "black", 6);
// Options
guiControl.drawPixelText("Options", guiControl.title.leftBorder, guiControl.title.rowTop(2) + pixel(), 8, (guiControl.optionsScreen) ? "white" : "black", 6);
// Draw cursor
guiControl.drawCursor(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;
G.SaveGame();
break;
case 1:
if (G.savedGameExists) { // once loading is in, allow this.
G.LoadGame();
snd_select.Play();
mus_title.Stop();
mus_sail.Play();
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);
}
if (ct_cancel().down) {
guiControl.title.screen = "credits";
}
}
} }
else if (guiControl.title.screen == "credits") {
guiControl.drawPixelText("Credits", guiControl.title.leftBorder - pixel(), pixel(2), 0, "white", 6);
guiControl.drawPixelText("Music, Icons", pixel(), pixel(11), 0, "white", 4);
guiControl.drawPixelText("Paws Menu", pixel(2), pixel(17), 0, "yellow", 6);
guiControl.drawPixelText("paws.bandcamp.com", pixel(2), pixel(25), 0, "yellow", 4);
guiControl.drawPixelText("Evrthng Else", pixel(), pixel(39), 0, "white", 4);
guiControl.drawPixelText("Alamantus", pixel(2), pixel(45), 0, "yellow", 6);
guiControl.drawPixelText("alamantus.com", pixel(2), pixel(53), 0, "yellow", 4);
if (ct_confirm().down || ct_cancel().down || ct_esc.down) { if (ct_cancel().down) {
guiControl.title.screen = "main"; guiControl.title.screen = "credits";
}
} }
}
} }
else if (guiControl.title.screen == "credits") {
guiControl.drawPixelText("Credits", guiControl.title.leftBorder - pixel(), pixel(2), 0, "white", 6);
guiControl.drawPixelText("Music, Icons", pixel(), pixel(11), 0, "white", 4);
guiControl.drawPixelText("Paws Menu", pixel(2), pixel(17), 0, "yellow", 6);
guiControl.drawPixelText("paws.bandcamp.com", pixel(2), pixel(25), 0, "yellow", 4);
guiControl.drawPixelText("Evrthng Else", pixel(), pixel(39), 0, "white", 4);
guiControl.drawPixelText("Alamantus", pixel(2), pixel(45), 0, "yellow", 6);
guiControl.drawPixelText("alamantus.com", pixel(2), pixel(53), 0, "yellow", 4);
if (ct_confirm().down || ct_cancel().down || ct_esc.down) {
guiControl.title.screen = "main";
}
}
}
} }

View File

@ -1,448 +1,461 @@
function tradeGUI() { function tradeGUI() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran tradeGUI()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran tradeGUI()");
} }
guiControl.trade = { guiControl.trade = {
screen: "main", // "main", "buy", "sell", "gossip" screen: "main", // "main", "buy", "sell", "gossip"
cursorPosition: 0, cursorPosition: 0,
page: 0, // horizontal page on item lists. Base 1 to match number of pages var "pages" within the gui. page: 0, // horizontal page on item lists. Base 1 to match number of pages var "pages" within the gui.
itemsPerPage: 3, itemsPerPage: 3,
show: false, show: false,
activateDelay: 0, activateDelay: 0,
island: null, island: null,
padding: pixel(2), padding: pixel(2),
leftBorder: pixel(12), leftBorder: pixel(12),
rowTop: function (rowNumber) { rowTop: function (rowNumber) {
return (guiControl.trade.padding + pixel(6) + (guiControl.trade.padding * 3)) + pixel((guiControl.iconSize + 3) * rowNumber); return (guiControl.trade.padding + pixel(6) + (guiControl.trade.padding * 3)) + pixel((guiControl.iconSize + 3) * rowNumber);
} },
} }
guiControl.trade.Draw = function () { guiControl.trade.Draw = function () {
if (guiControl.trade && guiControl.trade.show) { if (guiControl.trade && guiControl.trade.show) {
guiControl.trade.activateDelay -= (guiControl.trade.activateDelay > 0) ? 1 : 0; guiControl.trade.activateDelay -= (guiControl.trade.activateDelay > 0) ? 1 : 0;
// console.log("trade screen island: " + guiControl.trade.island.name); // console.log("trade screen island: " + guiControl.trade.island.name);
// Draw background color. // Draw background color.
var tmp = Oversimplified.context.fillStyle; var tmp = Oversimplified.context.fillStyle;
Oversimplified.context.fillStyle = "#D9BEA5"; Oversimplified.context.fillStyle = "#D9BEA5";
Oversimplified.context.fillRect(0, 0, Oversimplified.camera.width, Oversimplified.camera.height); Oversimplified.context.fillRect(0, 0, Oversimplified.camera.width, Oversimplified.camera.height);
Oversimplified.context.fillStyle = tmp; Oversimplified.context.fillStyle = tmp;
if (ct_down().down) { if (ct_down().down) {
snd_cursordown.Play(); snd_cursordown.Play();
guiControl.trade.cursorPosition++; guiControl.trade.cursorPosition++;
} }
if (ct_up().down) { if (ct_up().down) {
snd_cursordown.Play(); snd_cursordown.Play();
guiControl.trade.cursorPosition--; guiControl.trade.cursorPosition--;
} }
if (ct_right().down) { if (ct_right().down) {
snd_cursordown.Play(); snd_cursordown.Play();
guiControl.trade.page++; guiControl.trade.page++;
} }
if (ct_left().down) { if (ct_left().down) {
snd_cursordown.Play(); snd_cursordown.Play();
guiControl.trade.page--; guiControl.trade.page--;
} }
if (guiControl.trade.screen == "main") { if (guiControl.trade.screen == "main") {
// console.log(guiControl.trade.screen); // console.log(guiControl.trade.screen);
// Limit Cursor // Limit Cursor
if (guiControl.trade.cursorPosition < 0) { if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 3; guiControl.trade.cursorPosition = 3;
} }
if (guiControl.trade.cursorPosition > 3) { if (guiControl.trade.cursorPosition > 3) {
guiControl.trade.cursorPosition = 0; guiControl.trade.cursorPosition = 0;
} }
// Limit page // Limit page
if (guiControl.trade.page < 0) { if (guiControl.trade.page < 0) {
guiControl.trade.page = 0; guiControl.trade.page = 0;
} }
if (guiControl.trade.page > 0) { if (guiControl.trade.page > 0) {
guiControl.trade.page = 0; guiControl.trade.page = 0;
} }
// Title // Title
guiControl.drawPixelText("On Island", (guiControl.trade.padding * 2), guiControl.trade.padding, 10, "black", 6); guiControl.drawPixelText("On Island", (guiControl.trade.padding * 2), guiControl.trade.padding, 10, "black", 6);
// Money icon // Money icon
// guiControl.drawIcon(7, 2, guiControl.trade.leftBorder, guiControl.trade.rowTop(0)); // guiControl.drawIcon(7, 2, guiControl.trade.leftBorder, guiControl.trade.rowTop(0));
guiControl.drawPixelText((guiControl.trade.island.CheckInventory().length > 0) ? "Buy" : "Sold Out!", guiControl.trade.leftBorder, guiControl.trade.rowTop(0) + pixel(), 10, (guiControl.trade.island.CheckInventory().length > 0) ? "black" : "white", 6); guiControl.drawPixelText((guiControl.trade.island.CheckInventory().length > 0) ? "Buy" : "Sold Out!", guiControl.trade.leftBorder, guiControl.trade.rowTop(0) + pixel(), 10, (guiControl.trade.island.CheckInventory().length > 0) ? "black" : "white", 6);
// Supplies icon // Supplies icon
// guiControl.drawIcon(9, 2, guiControl.trade.leftBorder, guiControl.trade.rowTop(1)); // guiControl.drawIcon(9, 2, guiControl.trade.leftBorder, guiControl.trade.rowTop(1));
guiControl.drawPixelText((G.inventory.CheckCargo().length > 0) ? "Sell" : "No Cargo!", guiControl.trade.leftBorder, guiControl.trade.rowTop(1) + pixel(), 10, (G.inventory.CheckCargo().length > 0) ? "black" : "white", 6); guiControl.drawPixelText((G.inventory.CheckCargo().length > 0) ? "Sell" : "No Cargo!", guiControl.trade.leftBorder, guiControl.trade.rowTop(1) + pixel(), 10, (G.inventory.CheckCargo().length > 0) ? "black" : "white", 6);
// Cargo icon // Cargo icon
// guiControl.drawIcon(1, 0, guiControl.trade.leftBorder, guiControl.trade.rowTop(2)); // guiControl.drawIcon(1, 0, guiControl.trade.leftBorder, guiControl.trade.rowTop(2));
guiControl.drawPixelText("Tavern", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) + pixel(), 8, "black", 6); guiControl.drawPixelText("Tavern", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) + pixel(), 8, "black", 6);
// Close Text // Close Text
guiControl.drawPixelText("Leave", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) + pixel(), 8, "black", 6); guiControl.drawPixelText("Leave", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) + pixel(), 8, "black", 6);
// Draw cursor // Draw cursor
guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition)); guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition));
// Button Action // Button Action
if (guiControl.trade.activateDelay <= 0) { if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) { if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) { switch (guiControl.trade.cursorPosition) {
case 0: case 0: {
if (guiControl.trade.island.CheckInventory().length > 0) { if (guiControl.trade.island.CheckInventory().length > 0) {
snd_select.Play(); snd_select.Play();
guiControl.trade.screen = "buy"; guiControl.trade.screen = "buy";
guiControl.trade.activateDelay = 5; guiControl.trade.activateDelay = 5;
} }
else { else {
snd_cannotbuy.Play(); snd_cannotbuy.Play();
} }
break; break;
case 1: }
if (G.inventory.CheckCargo().length > 0) { case 1: {
snd_select.Play(); if (G.inventory.CheckCargo().length > 0) {
guiControl.trade.screen = "sell"; snd_select.Play();
guiControl.trade.activateDelay = 5; guiControl.trade.screen = "sell";
} else { guiControl.trade.activateDelay = 5;
snd_cannotbuy.Play(); } else {
} snd_cannotbuy.Play();
}
break; break;
case 2: }
snd_select.Play(); case 2: {
guiControl.trade.screen = "tavern"; snd_select.Play();
guiControl.trade.activateDelay = 5; guiControl.trade.screen = "tavern";
guiControl.trade.activateDelay = 5;
break; break;
default: }
snd_cursorup.Play(); default: {
mus_trade.Stop(); snd_cursorup.Play();
mus_sail.Play(); mus_trade.Stop();
guiControl.trade.show = false; mus_sail.Play();
guiControl.trade.show = false;
break; break;
} }
}
// snd_select.Play(); // snd_select.Play();
guiControl.trade.cursorPosition = 0; guiControl.trade.cursorPosition = 0;
guiControl.trade.page = 0; guiControl.trade.page = 0;
// console.log(guiControl.trade.screen); // console.log(guiControl.trade.screen);
} }
if (ct_cancel().down) { if (ct_cancel().down) {
snd_cursorup.Play(); snd_cursorup.Play();
mus_trade.Stop(); mus_trade.Stop();
mus_sail.Play(); mus_sail.Play();
guiControl.trade.show = false; guiControl.trade.show = false;
} }
} }
} }
else if (guiControl.trade.screen == "buy") { else if (guiControl.trade.screen == "buy") {
// console.log(guiControl.trade.screen); // console.log(guiControl.trade.screen);
// Limit Cursor // Limit Cursor
if (guiControl.trade.cursorPosition < 0) { if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 2; guiControl.trade.cursorPosition = 2;
} }
if (guiControl.trade.cursorPosition > 2) { if (guiControl.trade.cursorPosition > 2) {
guiControl.trade.cursorPosition = 0; guiControl.trade.cursorPosition = 0;
} }
// Title // Title
guiControl.drawPixelText("Buy", guiControl.trade.leftBorder - pixel(2), guiControl.topOfBackground, 10, "black", 6); guiControl.drawPixelText("Buy", guiControl.trade.leftBorder - pixel(2), guiControl.topOfBackground, 10, "black", 6);
// Money icon // Money icon
guiControl.drawIcon(7, 2, guiControl.trade.padding, guiControl.trade.rowTop(0) - pixel(3)); guiControl.drawIcon(7, 2, guiControl.trade.padding, guiControl.trade.rowTop(0) - pixel(3));
guiControl.drawPixelText(G.inventory.moneyDisplay(), guiControl.trade.padding + pixel(guiControl.iconSize + 2), guiControl.trade.rowTop(0) + pixel(2) - pixel(3), 10, "black", 4); guiControl.drawPixelText(G.inventory.moneyDisplay(), guiControl.trade.padding + pixel(guiControl.iconSize + 2), guiControl.trade.rowTop(0) + pixel(2) - pixel(3), 10, "black", 4);
// Cargo icons // Cargo icons
var items = guiControl.trade.island.CheckInventory(); // Contains the item ids that have more than 1 item var items = guiControl.trade.island.CheckInventory(); // Contains the item ids that have more than 1 item
// Limit page // Limit page
if (guiControl.trade.page < 0) { if (guiControl.trade.page < 0) {
guiControl.trade.page = items.length - 1; guiControl.trade.page = items.length - 1;
} }
if (guiControl.trade.page > items.length - 1) { if (guiControl.trade.page > items.length - 1) {
guiControl.trade.page = 0; guiControl.trade.page = 0;
} }
if (items.length > 0) { if (items.length > 0) {
var itemPrice = G.economy.cargoItemWorth[items[guiControl.trade.page]] + guiControl.trade.island.priceDifferences[items[guiControl.trade.page]] - guiControl.trade.island.haggleAmount; var itemPrice = G.economy.cargoItemWorth[items[guiControl.trade.page]] + guiControl.trade.island.priceDifferences[items[guiControl.trade.page]] - guiControl.trade.island.haggleAmount;
if (itemPrice < 1) itemPrice = 1; if (itemPrice < 1) itemPrice = 1;
var itemPriceDisplay = itemPrice.toString() + " c"; var itemPriceDisplay = itemPrice.toString() + " c";
guiControl.drawItem(items[guiControl.trade.page], guiControl.trade.leftBorder, guiControl.trade.rowTop(1) - pixel(5)); guiControl.drawItem(items[guiControl.trade.page], guiControl.trade.leftBorder, guiControl.trade.rowTop(1) - pixel(5));
guiControl.drawPixelText(itemPriceDisplay, guiControl.trade.leftBorder + pixel(guiControl.iconSize + 4), guiControl.trade.rowTop(1) - pixel(5) + pixel(), 8, "black", 6); guiControl.drawPixelText(itemPriceDisplay, guiControl.trade.leftBorder + pixel(guiControl.iconSize + 4), guiControl.trade.rowTop(1) - pixel(5) + pixel(), 8, "black", 6);
if (items.length > 1) { if (items.length > 1) {
guiControl.drawPageArrow("left", guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel(5)); guiControl.drawPageArrow("left", guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel(5));
guiControl.drawPageArrow("right", OS.camera.width - pixel(4) - guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel(5)); guiControl.drawPageArrow("right", OS.camera.width - pixel(4) - guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel(5));
} }
// Amounts // Amounts
guiControl.drawPixelText("Shop" + guiControl.trade.island.inventory[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(2) - pixel(6) + pixel(), 4, (guiControl.trade.island.CanBuyFrom(items[guiControl.trade.page], itemPrice)) ? "black" : "yellow", 4); guiControl.drawPixelText("Shop" + guiControl.trade.island.inventory[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(2) - pixel(6) + pixel(), 4, (guiControl.trade.island.CanBuyFrom(items[guiControl.trade.page], itemPrice)) ? "black" : "yellow", 4);
guiControl.drawPixelText("Own " + G.inventory.cargo[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(3) - pixel(6) + pixel(), 4, (G.inventory.cargo[items[guiControl.trade.page]] < G.stats.hold) ? "black" : "yellow", 4); guiControl.drawPixelText("Own " + G.inventory.cargo[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(3) - pixel(6) + pixel(), 4, (G.inventory.cargo[items[guiControl.trade.page]] < G.stats.hold) ? "black" : "yellow", 4);
} else { } else {
guiControl.drawPixelText("Sold Out!", guiControl.trade.leftBorder, guiControl.trade.rowTop(1) - pixel(5) + pixel(), 10, "black", 6); guiControl.drawPixelText("Sold Out!", guiControl.trade.leftBorder, guiControl.trade.rowTop(1) - pixel(5) + pixel(), 10, "black", 6);
} }
// Draw Amount of Cargo // Draw Amount of Cargo
guiControl.drawIcon(1, 1, OS.camera.width - pixel(20), guiControl.trade.rowTop(4) - pixel(5)); guiControl.drawIcon(1, 1, OS.camera.width - pixel(20), guiControl.trade.rowTop(4) - pixel(5));
guiControl.drawPixelText(G.inventory.CheckCargo().length.toString(), OS.camera.width - pixel(20) + (guiControl.iconScaled + pixel()), guiControl.trade.rowTop(4) - pixel(4), 4, (G.inventory.CheckCargo().length < G.stats.inventory) ? "black" : "yellow", 6); guiControl.drawPixelText(G.inventory.CheckCargo().length.toString(), OS.camera.width - pixel(20) + (guiControl.iconScaled + pixel()), guiControl.trade.rowTop(4) - pixel(4), 4, (G.inventory.CheckCargo().length < G.stats.inventory) ? "black" : "yellow", 6);
// Yes/No Options // Yes/No Options
guiControl.drawPixelText("Haggle", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) - pixel(2), 8, (guiControl.trade.island.timesHaggledToday >= G.stats.popularity) ? "yellow" : ((items.length > 0 && guiControl.trade.island.haggleAmount == 0) ? "black" : "white"), 6); guiControl.drawPixelText("Haggle", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) - pixel(2), 8, (guiControl.trade.island.timesHaggledToday >= G.stats.popularity) ? "yellow" : ((items.length > 0 && guiControl.trade.island.haggleAmount == 0) ? "black" : "white"), 6);
guiControl.drawPixelText((guiControl.trade.island.CanBuyFrom(items[guiControl.trade.page], itemPrice)) ? "Yes" : "Over!", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) - pixel(2), 8, (items.length > 0 && G.inventory.CanBuy(items[guiControl.trade.page], itemPrice)) ? ((guiControl.trade.island.CanBuyFrom(items[guiControl.trade.page], itemPrice)) ? "black" : "yellow") : "white", 6); guiControl.drawPixelText((guiControl.trade.island.CanBuyFrom(items[guiControl.trade.page], itemPrice)) ? "Yes" : "Over!", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) - pixel(2), 8, (items.length > 0 && G.inventory.CanBuy(items[guiControl.trade.page], itemPrice)) ? ((guiControl.trade.island.CanBuyFrom(items[guiControl.trade.page], itemPrice)) ? "black" : "yellow") : "white", 6);
// Back Text // Back Text
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6); guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
// Draw cursor // Draw cursor
guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(3)); guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(3));
// Button Action // Button Action
if (guiControl.trade.activateDelay <= 0) { if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) { if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) { switch (guiControl.trade.cursorPosition) {
case 0: // Haggle case 0: { // Haggle
if (items.length > 0 && (guiControl.trade.island.timesHaggledToday <= G.stats.popularity) && // If there are items and you haven't haggled too much if (items.length > 0 && (guiControl.trade.island.timesHaggledToday <= G.stats.popularity) && // If there are items and you haven't haggled too much
guiControl.trade.island.haggleAmount == 0 && Math.floor(Math.randomRange(0, 100)) < G.stats.popularity) // Or you haven't haggled yet and get a random number less than your popularity, haggle successfully. guiControl.trade.island.haggleAmount == 0 && Math.floor(Math.randomRange(0, 100)) < G.stats.popularity) // Or you haven't haggled yet and get a random number less than your popularity, haggle successfully.
{ {
snd_sell.Play(); snd_sell.Play();
guiControl.trade.island.haggleAmount = G.stats.haggling; guiControl.trade.island.haggleAmount = G.stats.haggling;
} else { } else {
snd_cannotbuy.Play(); snd_cannotbuy.Play();
guiControl.trade.island.timesHaggledToday++; guiControl.trade.island.timesHaggledToday++;
} }
break; break;
case 1: // Buy }
if (items.length > 0 && case 1: { // Buy
G.inventory.CanBuy(items[guiControl.trade.page], itemPrice) && if (items.length > 0 &&
guiControl.trade.island.CanBuyFrom(items[guiControl.trade.page], itemPrice)) //If cursor is over yes and you can buy, buy it. G.inventory.CanBuy(items[guiControl.trade.page], itemPrice) &&
{ guiControl.trade.island.CanBuyFrom(items[guiControl.trade.page], itemPrice)) //If cursor is over yes and you can buy, buy it.
snd_buy.Play(); {
guiControl.trade.island.BuyFrom(items[guiControl.trade.page], itemPrice); snd_buy.Play();
} else { guiControl.trade.island.BuyFrom(items[guiControl.trade.page], itemPrice);
snd_cannotbuy.Play(); } else {
} snd_cannotbuy.Play();
}
break; break;
default: }
snd_cursorup.Play(); default: {
guiControl.trade.screen = "main"; snd_cursorup.Play();
guiControl.trade.activateDelay = 5; guiControl.trade.screen = "main";
guiControl.trade.cursorPosition = 0; // The position where "Buy" is on main screen. guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 0; // The position where "Buy" is on main screen.
break; break;
} }
// console.log(guiControl.trade.screen); }
} // console.log(guiControl.trade.screen);
if (ct_cancel().down) { }
snd_cursorup.Play(); if (ct_cancel().down) {
guiControl.trade.screen = "main"; snd_cursorup.Play();
guiControl.trade.activateDelay = 5; guiControl.trade.screen = "main";
guiControl.trade.cursorPosition = 0; // The position where "Buy" is on main screen. guiControl.trade.activateDelay = 5;
// console.log(guiControl.trade.screen); guiControl.trade.cursorPosition = 0; // The position where "Buy" is on main screen.
} // console.log(guiControl.trade.screen);
} }
} }
else if (guiControl.trade.screen == "sell") { }
// console.log(guiControl.trade.screen); else if (guiControl.trade.screen == "sell") {
// Limit Cursor // console.log(guiControl.trade.screen);
if (guiControl.trade.cursorPosition < 0) { // Limit Cursor
guiControl.trade.cursorPosition = 2; if (guiControl.trade.cursorPosition < 0) {
} guiControl.trade.cursorPosition = 2;
if (guiControl.trade.cursorPosition > 2) { }
guiControl.trade.cursorPosition = 0; if (guiControl.trade.cursorPosition > 2) {
} guiControl.trade.cursorPosition = 0;
}
// Title // Title
guiControl.drawPixelText("Sell", guiControl.trade.leftBorder - pixel(2), guiControl.topOfBackground, 10, "black", 6); guiControl.drawPixelText("Sell", guiControl.trade.leftBorder - pixel(2), guiControl.topOfBackground, 10, "black", 6);
// Money icon // Money icon
guiControl.drawIcon(7, 2, guiControl.trade.padding, guiControl.trade.rowTop(0) - pixel(3)); guiControl.drawIcon(7, 2, guiControl.trade.padding, guiControl.trade.rowTop(0) - pixel(3));
guiControl.drawPixelText(G.inventory.moneyDisplay(), guiControl.trade.padding + pixel(guiControl.iconSize + 2), guiControl.trade.rowTop(0) + pixel(2) - pixel(3), 10, "black", 4); guiControl.drawPixelText(G.inventory.moneyDisplay(), guiControl.trade.padding + pixel(guiControl.iconSize + 2), guiControl.trade.rowTop(0) + pixel(2) - pixel(3), 10, "black", 4);
// Cargo icons // Cargo icons
var items = G.inventory.CheckCargo(); // Contains the item ids that have more than 1 item var items = G.inventory.CheckCargo(); // Contains the item ids that have more than 1 item
// Limit page // Limit page
if (guiControl.trade.page < 0) { if (guiControl.trade.page < 0) {
guiControl.trade.page = items.length - 1; guiControl.trade.page = items.length - 1;
} }
if (guiControl.trade.page > items.length - 1) { if (guiControl.trade.page > items.length - 1) {
guiControl.trade.page = 0; guiControl.trade.page = 0;
} }
if (items.length > 0) { if (items.length > 0) {
var itemPrice = G.economy.cargoItemWorth[items[guiControl.trade.page]] + guiControl.trade.island.priceDifferences[items[guiControl.trade.page]]; var itemPrice = G.economy.cargoItemWorth[items[guiControl.trade.page]] + guiControl.trade.island.priceDifferences[items[guiControl.trade.page]];
var priceCut = 0.5 + ((guiControl.trade.island.haggleAmount == 0) ? 0 : (G.stats.popularity * 0.01 * 0.5)); // If haggled successfully, lessen the price cut by half of your popularity's percent worth. var priceCut = 0.5 + ((guiControl.trade.island.haggleAmount == 0) ? 0 : (G.stats.popularity * 0.01 * 0.5)); // If haggled successfully, lessen the price cut by half of your popularity's percent worth.
itemPrice = Math.round(itemPrice * priceCut); itemPrice = Math.round(itemPrice * priceCut);
if (itemPrice < 1) itemPrice = 1; if (itemPrice < 1) itemPrice = 1;
var itemPriceDisplay = itemPrice.toString() + " c"; var itemPriceDisplay = itemPrice.toString() + " c";
guiControl.drawItem(items[guiControl.trade.page], guiControl.trade.leftBorder, guiControl.trade.rowTop(1) - pixel(5)); guiControl.drawItem(items[guiControl.trade.page], guiControl.trade.leftBorder, guiControl.trade.rowTop(1) - pixel(5));
guiControl.drawPixelText(itemPriceDisplay, guiControl.trade.leftBorder + pixel(guiControl.iconSize + 4), guiControl.trade.rowTop(1) - pixel(5) + pixel(), 8, "black", 6); guiControl.drawPixelText(itemPriceDisplay, guiControl.trade.leftBorder + pixel(guiControl.iconSize + 4), guiControl.trade.rowTop(1) - pixel(5) + pixel(), 8, "black", 6);
if (items.length > 1) { if (items.length > 1) {
guiControl.drawPageArrow("left", guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel(5)); guiControl.drawPageArrow("left", guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel(5));
guiControl.drawPageArrow("right", OS.camera.width - pixel(4) - guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel(5)); guiControl.drawPageArrow("right", OS.camera.width - pixel(4) - guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel(5));
} }
// Amounts // Amounts
guiControl.drawPixelText("Shop" + guiControl.trade.island.inventory[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(2) - pixel(6) + pixel(), 4, (guiControl.trade.island.CanSellTo(items[guiControl.trade.page], itemPrice)) ? "black" : "yellow", 4); guiControl.drawPixelText("Shop" + guiControl.trade.island.inventory[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(2) - pixel(6) + pixel(), 4, (guiControl.trade.island.CanSellTo(items[guiControl.trade.page], itemPrice)) ? "black" : "yellow", 4);
guiControl.drawPixelText("Own " + G.inventory.cargo[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(3) - pixel(6) + pixel(), 4, (G.inventory.cargo[items[guiControl.trade.page]] > 0) ? "black" : "yellow", 4); guiControl.drawPixelText("Own " + G.inventory.cargo[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(3) - pixel(6) + pixel(), 4, (G.inventory.cargo[items[guiControl.trade.page]] > 0) ? "black" : "yellow", 4);
} else { } else {
guiControl.drawPixelText("No Cargo!", guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel(5) + pixel(), 10, "black", 6); guiControl.drawPixelText("No Cargo!", guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel(5) + pixel(), 10, "black", 6);
} }
// Draw Amount of Cargo // Draw Amount of Cargo
guiControl.drawIcon(1, 1, OS.camera.width - pixel(20), guiControl.trade.rowTop(4) - pixel(5)); guiControl.drawIcon(1, 1, OS.camera.width - pixel(20), guiControl.trade.rowTop(4) - pixel(5));
guiControl.drawPixelText(G.inventory.CheckCargo().length.toString(), OS.camera.width - pixel(20) + (guiControl.iconScaled + pixel()), guiControl.trade.rowTop(4) - pixel(4), 4, (G.inventory.CheckCargo().length > 0) ? "black" : "yellow", 6); guiControl.drawPixelText(G.inventory.CheckCargo().length.toString(), OS.camera.width - pixel(20) + (guiControl.iconScaled + pixel()), guiControl.trade.rowTop(4) - pixel(4), 4, (G.inventory.CheckCargo().length > 0) ? "black" : "yellow", 6);
// Yes/No Options // Yes/No Options
guiControl.drawPixelText("Hagl?", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) - pixel(2), 8, (guiControl.trade.island.timesHaggledToday >= G.stats.popularity) ? "yellow" : ((items.length > 0 && guiControl.trade.island.haggleAmount == 0) ? "black" : "white"), 6); guiControl.drawPixelText("Hagl?", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) - pixel(2), 8, (guiControl.trade.island.timesHaggledToday >= G.stats.popularity) ? "yellow" : ((items.length > 0 && guiControl.trade.island.haggleAmount == 0) ? "black" : "white"), 6);
guiControl.drawPixelText((guiControl.trade.island.CanSellTo(items[guiControl.trade.page], itemPrice)) ? "Yes" : "Over!", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) - pixel(2), 8, (items.length > 0 && G.inventory.CanSell(items[guiControl.trade.page])) ? ((guiControl.trade.island.CanSellTo(items[guiControl.trade.page], itemPrice)) ? "black" : "yellow") : "white", 6); guiControl.drawPixelText((guiControl.trade.island.CanSellTo(items[guiControl.trade.page], itemPrice)) ? "Yes" : "Over!", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) - pixel(2), 8, (items.length > 0 && G.inventory.CanSell(items[guiControl.trade.page])) ? ((guiControl.trade.island.CanSellTo(items[guiControl.trade.page], itemPrice)) ? "black" : "yellow") : "white", 6);
// Back Text // Back Text
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6); guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
// Draw cursor // Draw cursor
guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(3)); guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(3));
// Button Action // Button Action
if (guiControl.trade.activateDelay <= 0) { if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) { if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) { switch (guiControl.trade.cursorPosition) {
case 0: // Haggle case 0: { // Haggle
if (items.length > 0 && (guiControl.trade.island.timesHaggledToday <= G.stats.popularity) && if (items.length > 0 && (guiControl.trade.island.timesHaggledToday <= G.stats.popularity) &&
guiControl.trade.island.haggleAmount == 0 && Math.floor(Math.randomRange(0, 100)) < G.stats.popularity) // If you haven't haggled yet and get a random number less than your popularity, haggle successfully. guiControl.trade.island.haggleAmount == 0 && Math.floor(Math.randomRange(0, 100)) < G.stats.popularity) // If you haven't haggled yet and get a random number less than your popularity, haggle successfully.
{ {
snd_sell.Play(); snd_sell.Play();
guiControl.trade.island.haggleAmount = G.stats.haggling; guiControl.trade.island.haggleAmount = G.stats.haggling;
} else { } else {
snd_cannotbuy.Play(); snd_cannotbuy.Play();
guiControl.trade.island.timesHaggledToday++; guiControl.trade.island.timesHaggledToday++;
} }
break; break;
case 1: // Sell }
if (items.length > 0 && case 1: { // Sell
G.inventory.CanSell(items[guiControl.trade.page]) && if (items.length > 0 &&
guiControl.trade.island.CanSellTo(items[guiControl.trade.page], itemPrice)) //If cursor is over yes and you can buy, buy it. G.inventory.CanSell(items[guiControl.trade.page]) &&
{ guiControl.trade.island.CanSellTo(items[guiControl.trade.page], itemPrice)) //If cursor is over yes and you can buy, buy it.
snd_sell.Play(); {
guiControl.trade.island.SellTo(items[guiControl.trade.page], itemPrice); snd_sell.Play();
} else { guiControl.trade.island.SellTo(items[guiControl.trade.page], itemPrice);
snd_cannotbuy.Play(); } else {
} snd_cannotbuy.Play();
}
break; break;
default: }
snd_cursorup.Play(); default: {
guiControl.trade.screen = "main"; snd_cursorup.Play();
guiControl.trade.activateDelay = 5; guiControl.trade.screen = "main";
guiControl.trade.cursorPosition = 1; // The position where "Sell" is on main screen. guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 1; // The position where "Sell" is on main screen.
break; break;
} }
// console.log(guiControl.trade.screen); }
} // console.log(guiControl.trade.screen);
if (ct_cancel().down) { }
snd_cursorup.Play(); if (ct_cancel().down) {
guiControl.trade.screen = "main"; snd_cursorup.Play();
guiControl.trade.activateDelay = 5; guiControl.trade.screen = "main";
guiControl.trade.cursorPosition = 1; // The position where "Sell" is on main screen. guiControl.trade.activateDelay = 5;
// console.log(guiControl.trade.screen); guiControl.trade.cursorPosition = 1; // The position where "Sell" is on main screen.
} // console.log(guiControl.trade.screen);
} }
} }
else if (guiControl.trade.screen == "tavern") { }
// Limit Cursor else if (guiControl.trade.screen == "tavern") {
if (guiControl.trade.cursorPosition < 0) { // Limit Cursor
guiControl.trade.cursorPosition = 2; if (guiControl.trade.cursorPosition < 0) {
} guiControl.trade.cursorPosition = 2;
if (guiControl.trade.cursorPosition > 2) { }
guiControl.trade.cursorPosition = 0; if (guiControl.trade.cursorPosition > 2) {
} guiControl.trade.cursorPosition = 0;
}
// Title // Title
guiControl.drawPixelText("Tavern", guiControl.leftBorder - pixel(6), guiControl.topOfBackground, 8, "black", 6); guiControl.drawPixelText("Tavern", guiControl.leftBorder - pixel(6), guiControl.topOfBackground, 8, "black", 6);
var innPrice = G.economy.innCost + guiControl.trade.island.innPriceDifference; var innPrice = G.economy.innCost + guiControl.trade.island.innPriceDifference;
guiControl.drawPixelText("Heal costs " + innPrice.toString() + " C", guiControl.leftBorder - pixel(5), guiControl.trade.rowTop(0) - pixel(), 10, "black", 4); guiControl.drawPixelText("Heal costs " + innPrice.toString() + " C", guiControl.leftBorder - pixel(5), guiControl.trade.rowTop(0) - pixel(), 10, "black", 4);
// Money icon // Money icon
guiControl.drawIcon(7, 2, guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel()); guiControl.drawIcon(7, 2, guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel());
guiControl.drawPixelText(G.inventory.moneyDisplay(), guiControl.trade.padding + pixel(guiControl.iconSize + 2), guiControl.trade.rowTop(1) + pixel(), 10, "black", 4); guiControl.drawPixelText(G.inventory.moneyDisplay(), guiControl.trade.padding + pixel(guiControl.iconSize + 2), guiControl.trade.rowTop(1) + pixel(), 10, "black", 4);
// Options // Options
guiControl.drawPixelText("Gossip", guiControl.leftBorder, guiControl.trade.rowTop(2) - pixel(), 0, "black", 6); guiControl.drawPixelText("Gossip", guiControl.leftBorder, guiControl.trade.rowTop(2) - pixel(), 0, "black", 6);
guiControl.drawPixelText("Heal", guiControl.leftBorder, guiControl.trade.rowTop(3) - pixel(), 4, (G.inventory.money > innPrice && G.stats.illness > 0) ? "black" : "white", 6); guiControl.drawPixelText("Heal", guiControl.leftBorder, guiControl.trade.rowTop(3) - pixel(), 4, (G.inventory.money > innPrice && G.stats.illness > 0) ? "black" : "white", 6);
// Illness icon // Illness icon
guiControl.drawIcon(4, 1, guiControl.leftBorder + pixel(30), guiControl.trade.rowTop(3) - pixel(2)); guiControl.drawIcon(4, 1, guiControl.leftBorder + pixel(30), guiControl.trade.rowTop(3) - pixel(2));
guiControl.drawPixelText(G.stats.illness.toString(), guiControl.leftBorder + pixel(30) + pixel(guiControl.iconSize + 2), guiControl.trade.rowTop(3), 2, (G.stats.illness == 0) ? "yellow" : "black", 4); guiControl.drawPixelText(G.stats.illness.toString(), guiControl.leftBorder + pixel(30) + pixel(guiControl.iconSize + 2), guiControl.trade.rowTop(3), 2, (G.stats.illness == 0) ? "yellow" : "black", 4);
// Back Text // Back Text
guiControl.drawPixelText("Back", guiControl.leftBorder, guiControl.trade.rowTop(4) - pixel(), 8, "black", 6); guiControl.drawPixelText("Back", guiControl.leftBorder, guiControl.trade.rowTop(4) - pixel(), 8, "black", 6);
// Draw cursor // Draw cursor
guiControl.drawCursor(guiControl.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(2)); guiControl.drawCursor(guiControl.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(2));
// Button Action // Button Action
if (guiControl.trade.activateDelay <= 0) { if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) { if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) { switch (guiControl.trade.cursorPosition) {
case 0: case 0: {
snd_select.Play(); snd_select.Play();
guiControl.trade.screen = "gossip"; guiControl.trade.screen = "gossip";
guiControl.trade.activateDelay = 5; guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 2; // The position where "Supplies" is on main screen. guiControl.trade.cursorPosition = 2; // The position where "Supplies" is on main screen.
break; break;
case 1: }
if (G.stats.illness > 0 && G.inventory.money > innPrice) { //If cursor is over yes, heal illness with supplies. case 1: {
snd_heal.Play(); if (G.stats.illness > 0 && G.inventory.money > innPrice) { //If cursor is over yes, heal illness with supplies.
guiControl.trade.island.StayAtInn(); snd_heal.Play();
} else { guiControl.trade.island.StayAtInn();
snd_cannotbuy.Play(); } else {
} snd_cannotbuy.Play();
}
break; break;
default: }
snd_cursorup.Play(); default: {
guiControl.trade.screen = "main"; snd_cursorup.Play();
guiControl.trade.activateDelay = 5; guiControl.trade.screen = "main";
guiControl.trade.cursorPosition = 2; // The position where "Supplies" is on main screen. guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 2; // The position where "Supplies" is on main screen.
break; break;
} }
}
// Give a cooldown so you don't accidentally do something you don't want. // Give a cooldown so you don't accidentally do something you don't want.
guiControl.trade.activateDelay = 5; guiControl.trade.activateDelay = 5;
} }
if (ct_cancel().down) { if (ct_cancel().down) {
snd_cursorup.Play(); snd_cursorup.Play();
guiControl.trade.screen = "main"; guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5; guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 2; // The position where "Supplies" is on main screen. guiControl.trade.cursorPosition = 2; // The position where "Supplies" is on main screen.
} }
} }
} }
else if (guiControl.trade.screen == "gossip") { else if (guiControl.trade.screen == "gossip") {
// console.log(guiControl.trade.screen); // console.log(guiControl.trade.screen);
// Limit Cursor // Limit Cursor
if (guiControl.trade.cursorPosition < 0) { if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 0; guiControl.trade.cursorPosition = 0;
} }
if (guiControl.trade.cursorPosition > 0) { if (guiControl.trade.cursorPosition > 0) {
guiControl.trade.cursorPosition = 0; guiControl.trade.cursorPosition = 0;
} }
// Title // Title
guiControl.drawPixelText("Gossip", guiControl.trade.padding, guiControl.topOfBackground, 10, "black", 6); guiControl.drawPixelText("Gossip", guiControl.trade.padding, guiControl.topOfBackground, 10, "black", 6);
guiControl.drawPixelText("Use the map with M to find new islands to trade with!", guiControl.trade.padding, guiControl.trade.rowTop(0) - pixel(2), 0, "black", 4); guiControl.drawPixelText("Use the map with M to find new islands to trade with!", guiControl.trade.padding, guiControl.trade.rowTop(0) - pixel(2), 0, "black", 4);
// Back Text // Back Text
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6); guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
// Draw cursor // Draw cursor
guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(4) - pixel(3)); guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(4) - pixel(3));
// Button Action // Button Action
if (guiControl.trade.activateDelay <= 0) { if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down || ct_cancel().down) { if (ct_confirm().down || ct_cancel().down) {
snd_cursorup.Play(); snd_cursorup.Play();
guiControl.trade.screen = "tavern"; guiControl.trade.screen = "tavern";
guiControl.trade.activateDelay = 5; guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 0; guiControl.trade.cursorPosition = 0;
} }
} }
} }
} }
} }

View File

@ -15,38 +15,41 @@
<![endif]--> <![endif]-->
</head> </head>
<body> <body>
<div class="wrapper"> <div class="wrapper">
<header> <header>
<h1 class="header">Trade Winds</h1> <h1 class="header">Trade Winds</h1>
<p class="header">An exploration and trade game built with <a href="https://github.com/Alamantus/OversimplifiedJS" target="_blank">OversimplifiedJS</a></p> <p class="header">An exploration and trade game built with <a href="https://github.com/Alamantus/OversimplifiedJS" target="_blank">OversimplifiedJS</a></p>
<ul> <ul>
<li class="download"><a class="buttons" href="https://github.com/AlamantusGameDev/Trade-Winds/zipball/master">Download ZIP</a></li> <li class="download"><a class="buttons" href="https://github.com/AlamantusGameDev/Trade-Winds/zipball/master">Download ZIP</a></li>
<li class="download"><a class="buttons" href="https://github.com/AlamantusGameDev/Trade-Winds/tarball/master">Download TAR</a></li> <li class="download"><a class="buttons" href="https://github.com/AlamantusGameDev/Trade-Winds/tarball/master">Download TAR</a></li>
<li><a class="buttons github" href="https://github.com/AlamantusGameDev/Trade-Winds">View On GitHub</a></li> <li><a class="buttons github" href="https://github.com/AlamantusGameDev/Trade-Winds">View On GitHub</a></li>
</ul> </ul>
<p class="header">This project is maintained by <a class="header name" href="http://www.alamantus.com">Alamantus GameDev</a></p> <p class="header">This project is maintained by <a class="header name" href="http://www.alamantus.com">Alamantus GameDev</a></p>
</header> </header>
<section> <section>
<h2>Play</h2> <h2>Play</h2>
<p><i>You may need to refresh the page if all of the assets do not load.</i></p> <p><i>You may need to refresh the page if all of the assets do not load.</i></p>
<canvas style="border:solid 1px black;" id="game"> <canvas style="border:solid 1px black;" id="game">
Your browser is really old, dude - no canvas support! Update this thing! Your browser is really old, dude - no canvas support! Update this thing!
</canvas> </canvas>
<div id="audio"></div> <div id="audio"></div>
</section> </section>
<section> <section>
<h2> <h2>
<a id="about" class="anchor" href="#about" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>About</h2> <a id="about" class="anchor" href="#about" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>
About
</h2>
<p>This page contains the in-dev version of the game, and the most recent stable version will be <a href="https://alamantus-gamedev.itch.io/trade-winds">on Itch.io</a>.</p> <p>This page contains the in-dev version of the game, and the most recent stable version will be <a href="https://alamantus-gamedev.itch.io/trade-winds">on Itch.io</a>.</p>
<h2> <h2>
<a id="controls" class="anchor" href="#controls" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Controls</h2> <a id="controls" class="anchor" href="#controls" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Controls
</h2>
<strong>In-Game Controls</strong> <strong>In-Game Controls</strong>
<ul> <ul>
@ -100,12 +103,11 @@
<p>The game saves at the start of each day. If you stop in the middle of the day, you will lose your progress for that day.</p> <p>The game saves at the start of each day. If you stop in the middle of the day, you will lose your progress for that day.</p>
<p>There's no end game yet, but you can sail around and trade as long as you want. Try to make as much money as you can!</p> <p>There's no end game yet, but you can sail around and trade as long as you want. Try to make as much money as you can!</p>
</section> </section>
<footer> <footer>
<p><small>Hosted on <a href="https://pages.github.com">GitHub Pages</a> using the Dinky theme</small></p> <p><small>Hosted on <a href="https://pages.github.com">GitHub Pages</a> using the Dinky theme</small></p>
</footer> </footer>
</div> </div>
<!--[if !IE]><script>fixScale(document);</script><![endif]--> <!--[if !IE]><script>fixScale(document);</script><![endif]-->
</body>
</body>
</html> </html>

View File

@ -1,20 +1,19 @@
fixScale = function(doc) { fixScale = function(doc) {
var addEvent = 'addEventListener', var addEvent = 'addEventListener',
type = 'gesturestart', type = 'gesturestart',
qsa = 'querySelectorAll', qsa = 'querySelectorAll',
scales = [1, 1], scales = [1, 1],
meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : []; meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
function fix() { function fix() {
meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1]; meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
doc.removeEventListener(type, fix, true); doc.removeEventListener(type, fix, true);
} }
if ((meta = meta[meta.length - 1]) && addEvent in doc) {
fix();
scales = [.25, 1.6];
doc[addEvent](type, fix, true);
}
if ((meta = meta[meta.length - 1]) && addEvent in doc) {
fix();
scales = [.25, 1.6];
doc[addEvent](type, fix, true);
}
}; };

View File

@ -15,5 +15,5 @@ var snd_sell = new OS.E.AddSound("Sell", {wav: "audio/sounds/Sell.wav", mp3: "au
var snd_wave = new OS.E.AddSound("Wave Crash", {wav: "audio/sounds/Wave_Crash.wav", mp3: "audio/sounds/Wave_Crash.mp3"}); var snd_wave = new OS.E.AddSound("Wave Crash", {wav: "audio/sounds/Wave_Crash.wav", mp3: "audio/sounds/Wave_Crash.mp3"});
function loadAudio() { function loadAudio() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadAudio()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran loadAudio()");
} }

View File

@ -15,53 +15,53 @@ var ct_m = OS.C.Add("M", OS.Keycode.m);
var ct_esc = OS.C.Add("Cancel", OS.Keycode.escape); var ct_esc = OS.C.Add("Cancel", OS.Keycode.escape);
function loadControls () { function loadControls () {
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadControls()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran loadControls()");
} }
function ct_up () { function ct_up () {
return { return {
held : ct_wasd_up.held || ct_arrow_up.held, held : ct_wasd_up.held || ct_arrow_up.held,
down : ct_wasd_up.down || ct_arrow_up.down, down : ct_wasd_up.down || ct_arrow_up.down,
up : ct_wasd_up.up || ct_arrow_up.up up : ct_wasd_up.up || ct_arrow_up.up,
} }
} }
function ct_left () { function ct_left () {
return { return {
held : ct_wasd_left.held || ct_arrow_left.held, held : ct_wasd_left.held || ct_arrow_left.held,
down : ct_wasd_left.down || ct_arrow_left.down, down : ct_wasd_left.down || ct_arrow_left.down,
up : ct_wasd_left.up || ct_arrow_left.up up : ct_wasd_left.up || ct_arrow_left.up,
} }
} }
function ct_down () { function ct_down () {
return { return {
held : ct_wasd_down.held || ct_arrow_down.held, held : ct_wasd_down.held || ct_arrow_down.held,
down : ct_wasd_down.down || ct_arrow_down.down, down : ct_wasd_down.down || ct_arrow_down.down,
up : ct_wasd_down.up || ct_arrow_down.up up : ct_wasd_down.up || ct_arrow_down.up,
} }
} }
function ct_right () { function ct_right () {
return { return {
held : ct_wasd_right.held || ct_arrow_right.held, held : ct_wasd_right.held || ct_arrow_right.held,
down : ct_wasd_right.down || ct_arrow_right.down, down : ct_wasd_right.down || ct_arrow_right.down,
up : ct_wasd_right.up || ct_arrow_right.up up : ct_wasd_right.up || ct_arrow_right.up,
} }
} }
function ct_confirm () { function ct_confirm () {
return { return {
held : ct_space.held || ct_z.held, held : ct_space.held || ct_z.held,
down : ct_space.down || ct_z.down, down : ct_space.down || ct_z.down,
up : ct_space.up || ct_z.up up : ct_space.up || ct_z.up,
} }
} }
function ct_cancel () { function ct_cancel () {
return { return {
held : ct_shift.held || ct_x.held, held : ct_shift.held || ct_x.held,
down : ct_shift.down || ct_x.down, down : ct_shift.down || ct_x.down,
up : ct_shift.up || ct_x.up up : ct_shift.up || ct_x.up,
} }
} }

View File

@ -1,79 +1,79 @@
function loadGUIs() { function loadGUIs() {
OS.AddScript("gui/titleScreen.js"); 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");
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadGUIs()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran loadGUIs()");
} }
var guiControl = { var guiControl = {
topOfBackground: pixel(2 + 2), topOfBackground: pixel(2 + 2),
upperBorder: pixel(13 + 2), upperBorder: pixel(13 + 2),
lowerBorder: pixel(3 + 2), lowerBorder: pixel(3 + 2),
leftBorder: pixel(10 + 2), leftBorder: pixel(10 + 2),
rightBorder: pixel(5 + 2), rightBorder: pixel(5 + 2),
iconSize: 8, iconSize: 8,
iconScaled: pixel(8), iconScaled: pixel(8),
drawEnergyBar: function () { drawEnergyBar: function () {
var percentage = G.stats.energy / G.stats.maxEnergy; var percentage = G.stats.energy / G.stats.maxEnergy;
var barHeight = pixel(2); var barHeight = pixel(2);
var maxBarWidth = 32; var maxBarWidth = 32;
var barWidth = pixel(Math.round(maxBarWidth * percentage)); var barWidth = pixel(Math.round(maxBarWidth * percentage));
var saveFillStyle = OS.context.fillStyle; var saveFillStyle = OS.context.fillStyle;
OS.context.fillStyle = "#0055FF"; OS.context.fillStyle = "#0055FF";
OS.context.fillRect(64, OS.camera.height - barHeight - pixel(4), barWidth, barHeight); OS.context.fillRect(64, OS.camera.height - barHeight - pixel(4), barWidth, barHeight);
OS.context.fillStyle = saveFillStyle; OS.context.fillStyle = saveFillStyle;
}, },
drawClock: function () { drawClock: function () {
var screenX = OS.camera.width - pixel(9) - pixel(2); var screenX = OS.camera.width - pixel(9) - pixel(2);
var screenY = OS.camera.height - pixel(9) - pixel(2); var screenY = OS.camera.height - pixel(9) - pixel(2);
var percentOfClock = guiControl.clockTimerCount / guiControl.clockTimerCutoff; var percentOfClock = guiControl.clockTimerCount / guiControl.clockTimerCutoff;
var clockFrameX = guiControl.gui_sheet.clock.x + (Math.floor(pixel(4) * percentOfClock) * pixel(9)); var clockFrameX = guiControl.gui_sheet.clock.x + (Math.floor(pixel(4) * percentOfClock) * pixel(9));
OS.context.drawImage(guiControl.gui_sheet, clockFrameX, guiControl.gui_sheet.clock.y, pixel(9), pixel(9), screenX, screenY, pixel(9), pixel(9)); OS.context.drawImage(guiControl.gui_sheet, clockFrameX, guiControl.gui_sheet.clock.y, pixel(9), pixel(9), screenX, screenY, pixel(9), pixel(9));
}, },
drawSpeedGauge: function () { drawSpeedGauge: function () {
var screenX = pixel(4); var screenX = pixel(4);
var screenY = OS.camera.height - guiControl.iconScaled - pixel(4); var screenY = OS.camera.height - guiControl.iconScaled - pixel(4);
var sheetX = guiControl.gui_sheet.gauge.x + (G.player.currentSpeed * guiControl.iconScaled); var sheetX = guiControl.gui_sheet.gauge.x + (G.player.currentSpeed * guiControl.iconScaled);
var sheetY = guiControl.gui_sheet.gauge.y; var sheetY = guiControl.gui_sheet.gauge.y;
OS.context.drawImage(guiControl.gui_sheet, sheetX, sheetY, guiControl.iconScaled, guiControl.iconScaled, screenX, screenY, guiControl.iconScaled, guiControl.iconScaled); OS.context.drawImage(guiControl.gui_sheet, sheetX, sheetY, guiControl.iconScaled, guiControl.iconScaled, screenX, screenY, guiControl.iconScaled, guiControl.iconScaled);
}, },
iconPosition: function (cellPosition) { iconPosition: function (cellPosition) {
return (guiControl.iconScaled * cellPosition); return (guiControl.iconScaled * cellPosition);
}, },
rowTop: function (rowNumber) { rowTop: function (rowNumber) {
return guiControl.upperBorder + pixel((guiControl.iconSize + 2) * rowNumber); return guiControl.upperBorder + pixel((guiControl.iconSize + 2) * rowNumber);
}, },
drawIcon: function (cellX, cellY, xPosition, yPosition) { drawIcon: function (cellX, cellY, xPosition, yPosition) {
var iconSheetX = guiControl.gui_sheet.icons.x + guiControl.iconPosition(cellX); var iconSheetX = guiControl.gui_sheet.icons.x + guiControl.iconPosition(cellX);
var iconSheetY = guiControl.gui_sheet.icons.y + guiControl.iconPosition(cellY); var iconSheetY = guiControl.gui_sheet.icons.y + guiControl.iconPosition(cellY);
OS.context.drawImage(guiControl.gui_sheet, iconSheetX, iconSheetY, guiControl.iconScaled, guiControl.iconScaled, xPosition, yPosition, guiControl.iconScaled, guiControl.iconScaled); OS.context.drawImage(guiControl.gui_sheet, iconSheetX, iconSheetY, guiControl.iconScaled, guiControl.iconScaled, xPosition, yPosition, guiControl.iconScaled, guiControl.iconScaled);
}, },
drawItem: function (itemId, xPosition, yPosition) { drawItem: function (itemId, xPosition, yPosition) {
var cellX = itemId % 4; var cellX = itemId % 4;
var cellY = Math.floor(itemId / 4); var cellY = Math.floor(itemId / 4);
var itemSheetX = guiControl.gui_sheet.items.x + guiControl.iconPosition(cellX); var itemSheetX = guiControl.gui_sheet.items.x + guiControl.iconPosition(cellX);
var itemSheetY = guiControl.gui_sheet.items.y + guiControl.iconPosition(cellY); var itemSheetY = guiControl.gui_sheet.items.y + guiControl.iconPosition(cellY);
OS.context.drawImage(guiControl.gui_sheet, itemSheetX, itemSheetY, guiControl.iconScaled, guiControl.iconScaled, xPosition, yPosition, guiControl.iconScaled, guiControl.iconScaled); OS.context.drawImage(guiControl.gui_sheet, itemSheetX, itemSheetY, guiControl.iconScaled, guiControl.iconScaled, xPosition, yPosition, guiControl.iconScaled, guiControl.iconScaled);
}, },
drawTitleImage: function () { drawTitleImage: function () {
OS.context.drawImage(guiControl.gui_sheet, guiControl.gui_sheet.titleImage.x, guiControl.gui_sheet.titleImage.y, guiControl.gui_sheet.titleImage.width, guiControl.gui_sheet.titleImage.height, 0, 0, guiControl.gui_sheet.titleImage.width, guiControl.gui_sheet.titleImage.height); OS.context.drawImage(guiControl.gui_sheet, guiControl.gui_sheet.titleImage.x, guiControl.gui_sheet.titleImage.y, guiControl.gui_sheet.titleImage.width, guiControl.gui_sheet.titleImage.height, 0, 0, guiControl.gui_sheet.titleImage.width, guiControl.gui_sheet.titleImage.height);
}, },
drawGUIBackground: function () { drawGUIBackground: function () {
OS.context.drawImage(guiControl.gui_sheet, guiControl.gui_sheet.guiBackground.x, guiControl.gui_sheet.guiBackground.y, guiControl.gui_sheet.guiBackground.width, guiControl.gui_sheet.guiBackground.height, pixel(2), pixel(2), guiControl.gui_sheet.guiBackground.width, guiControl.gui_sheet.guiBackground.height); OS.context.drawImage(guiControl.gui_sheet, guiControl.gui_sheet.guiBackground.x, guiControl.gui_sheet.guiBackground.y, guiControl.gui_sheet.guiBackground.width, guiControl.gui_sheet.guiBackground.height, pixel(2), pixel(2), guiControl.gui_sheet.guiBackground.width, guiControl.gui_sheet.guiBackground.height);
}, },
drawCursor: function (xPosition, yPosition) { drawCursor: function (xPosition, yPosition) {
OS.context.drawImage(guiControl.gui_sheet, guiControl.gui_sheet.guiCursor.x, guiControl.gui_sheet.guiCursor.y, guiControl.iconScaled, guiControl.iconScaled, xPosition, yPosition, guiControl.iconScaled, guiControl.iconScaled); OS.context.drawImage(guiControl.gui_sheet, guiControl.gui_sheet.guiCursor.x, guiControl.gui_sheet.guiCursor.y, guiControl.iconScaled, guiControl.iconScaled, xPosition, yPosition, guiControl.iconScaled, guiControl.iconScaled);
}, },
drawPageArrow: function (direction, xPosition, yPosition) { drawPageArrow: function (direction, xPosition, yPosition) {
var arrowSheetX = guiControl.gui_sheet.arrows.x + ((direction == "left") ? 0 : pixel(4)); var arrowSheetX = guiControl.gui_sheet.arrows.x + ((direction == "left") ? 0 : pixel(4));
OS.context.drawImage(guiControl.gui_sheet, arrowSheetX, guiControl.gui_sheet.arrows.y, pixel(4), pixel(7), xPosition, yPosition, pixel(4), pixel(7)); OS.context.drawImage(guiControl.gui_sheet, arrowSheetX, guiControl.gui_sheet.arrows.y, pixel(4), pixel(7), xPosition, yPosition, pixel(4), pixel(7));
} }
} }
guiControl.gui_sheet = new Image(); guiControl.gui_sheet = new Image();
guiControl.gui_sheet.src = "images/gui_sheet.png"; guiControl.gui_sheet.src = "images/gui_sheet.png";
@ -100,247 +100,289 @@ guiControl.drawPixelText = function (text, x, y, wrapWidth, color, size) {
// Remember to set the pixel scale for x and y when you call the function! // Remember to set the pixel scale for x and y when you call the function!
// 4x4 font modified from http://pixeljoint.com/forum/forum_posts.asp?TID=18755&PID=185995#185995 // 4x4 font modified from http://pixeljoint.com/forum/forum_posts.asp?TID=18755&PID=185995#185995
// 5x6 font modified from http://atariage.com/forums/topic/165697-fonts/page-4#entry2081600 // 5x6 font modified from http://atariage.com/forums/topic/165697-fonts/page-4#entry2081600
text = text.toString().toUpperCase(); text = text.toString().toUpperCase();
var letterSizeX = pixel((size == 6) ? size - 1 : size); var letterSizeX = pixel((size == 6) ? size - 1 : size);
var letterSizeY = pixel(size); var letterSizeY = pixel(size);
var maxWrapWidth = Math.floor(OS.camera.width / (letterSizeX + pixel(1))); var maxWrapWidth = Math.floor(OS.camera.width / (letterSizeX + pixel(1)));
wrapWidth = (wrapWidth <= 0 || wrapWidth > maxWrapWidth) ? maxWrapWidth : wrapWidth; wrapWidth = (wrapWidth <= 0 || wrapWidth > maxWrapWidth) ? maxWrapWidth : wrapWidth;
// var alphabet = guiControl.alphabet_sheet[color + size.toString()]; // var alphabet = guiControl.alphabet_sheet[color + size.toString()];
// Make words wrap nicely, but let punctuation wrap. // Make words wrap nicely, but let punctuation wrap.
var wordsInText = text.split(" "); var wordsInText = text.split(" ");
if (wordsInText.length > 1) { if (wordsInText.length > 1) {
var indexToBreak = 0; var indexToBreak = 0;
var replacementText = ""; var replacementText = "";
var punctuation = [".", ",", "-", "?", "!"]; var punctuation = [".", ",", "-", "?", "!"];
for (var w = 0; w < wordsInText.length; w++) { for (var w = 0; w < wordsInText.length; w++) {
// console.log("\"" + wordsInText[w].charAt(wordsInText[w].length - 1) + "\""); // console.log("\"" + wordsInText[w].charAt(wordsInText[w].length - 1) + "\"");
if (punctuation.indexOf(wordsInText[w]) == -1 && punctuation.indexOf(wordsInText[w].charAt(wordsInText[w].length - 1)) != -1) { if (punctuation.indexOf(wordsInText[w]) == -1 && punctuation.indexOf(wordsInText[w].charAt(wordsInText[w].length - 1)) != -1) {
// If the last character of a word is punctuation, separate it out // If the last character of a word is punctuation, separate it out
wordsInText.splice(w + 1, 0, wordsInText[w].charAt(wordsInText[w].length - 1)); wordsInText.splice(w + 1, 0, wordsInText[w].charAt(wordsInText[w].length - 1));
// console.log("punctuation:" + wordsInText[w].charAt(wordsInText[w].length - 1)); // console.log("punctuation:" + wordsInText[w].charAt(wordsInText[w].length - 1));
wordsInText[w] = wordsInText[w].substr(0, wordsInText[w].length - 1); wordsInText[w] = wordsInText[w].substr(0, wordsInText[w].length - 1);
// console.log("Turns to:" + wordsInText[w]); // console.log("Turns to:" + wordsInText[w]);
w--; w--;
} else if (replacementText.substr(indexToBreak).length + wordsInText[w].length + 1 <= wrapWidth) { } else if (replacementText.substr(indexToBreak).length + wordsInText[w].length + 1 <= wrapWidth) {
// console.log("Adding: \"" + wordsInText[w] + " \" to \"" + replacementText.substr(indexToBreak) + "\""); // console.log("Adding: \"" + wordsInText[w] + " \" to \"" + replacementText.substr(indexToBreak) + "\"");
// console.log(replacementText.substr(indexToBreak).length + wordsInText[w].length + " < " + wrapWidth); // console.log(replacementText.substr(indexToBreak).length + wordsInText[w].length + " < " + wrapWidth);
// console.log("\"" + replacementText.substr(indexToBreak) + "\""); // console.log("\"" + replacementText.substr(indexToBreak) + "\"");
replacementText += wordsInText[w]; replacementText += wordsInText[w];
if (punctuation.indexOf(wordsInText[w + 1]) == -1) { // If the next word in the array is not punctuation, if (punctuation.indexOf(wordsInText[w + 1]) == -1) { // If the next word in the array is not punctuation,
replacementText += " "; // Then add a space after. replacementText += " "; // Then add a space after.
} }
// console.log("Turns to: \"" + replacementText.substr(indexToBreak) + "\""); // console.log("Turns to: \"" + replacementText.substr(indexToBreak) + "\"");
} else if (replacementText.substr(indexToBreak).length + wordsInText[w].length <= wrapWidth) { } else if (replacementText.substr(indexToBreak).length + wordsInText[w].length <= wrapWidth) {
// console.log("Adding: \"" + wordsInText[w] + "\" to \"" + replacementText.substr(indexToBreak) + "\""); // console.log("Adding: \"" + wordsInText[w] + "\" to \"" + replacementText.substr(indexToBreak) + "\"");
// console.log(replacementText.substr(indexToBreak).length + wordsInText[w].length + " < " + wrapWidth); // console.log(replacementText.substr(indexToBreak).length + wordsInText[w].length + " < " + wrapWidth);
// console.log("\"" + replacementText.substr(indexToBreak) + "\""); // console.log("\"" + replacementText.substr(indexToBreak) + "\"");
replacementText += wordsInText[w]; replacementText += wordsInText[w];
// console.log("Turns to: \"" + replacementText.substr(indexToBreak) + "\""); // console.log("Turns to: \"" + replacementText.substr(indexToBreak) + "\"");
indexToBreak = replacementText.length; indexToBreak = replacementText.length;
} else { } else {
// console.log("Checking: \"" + replacementText.substr(indexToBreak) + wordsInText[w] + "\""); // console.log("Checking: \"" + replacementText.substr(indexToBreak) + wordsInText[w] + "\"");
// console.log(replacementText.substr(indexToBreak).length + wordsInText[w].length + " > " + wrapWidth); // console.log(replacementText.substr(indexToBreak).length + wordsInText[w].length + " > " + wrapWidth);
// console.log("\"" + replacementText.substr(indexToBreak) + "\""); // console.log("\"" + replacementText.substr(indexToBreak) + "\"");
// indexToBreak = replacementText.length - 1; // indexToBreak = replacementText.length - 1;
var numberOfSpaces = wrapWidth - replacementText.substr(indexToBreak).length; var numberOfSpaces = wrapWidth - replacementText.substr(indexToBreak).length;
for (var s = 0; s < numberOfSpaces; s++) { for (var s = 0; s < numberOfSpaces; s++) {
replacementText += " "; replacementText += " ";
} }
// console.log("Turns to: \"" + replacementText.substr(indexToBreak) + "\""); // console.log("Turns to: \"" + replacementText.substr(indexToBreak) + "\"");
indexToBreak = replacementText.length; indexToBreak = replacementText.length;
w--; w--;
// replacementText += wordsInText[w]; // replacementText += wordsInText[w];
}
// console.log("----");
}
text = replacementText;
}
for (var i = 0; i < text.length; i++) {
var letterCellX, letterCellY;
switch (text.charAt(i)) {
case "A": {
letterCellX = 0;
letterCellY = 0;
break;
} }
// console.log("----"); case "B": {
} letterCellX = 1;
text = replacementText; letterCellY = 0;
} break;
}
case "C": {
letterCellX = 2;
letterCellY = 0;
break;
}
case "D": {
letterCellX = 3;
letterCellY = 0;
break;
}
case "E": {
letterCellX = 4;
letterCellY = 0;
break;
}
case "F": {
letterCellX = 5;
letterCellY = 0;
break;
}
case "G": {
letterCellX = 0;
letterCellY = 1;
break;
}
case "H": {
letterCellX = 1;
letterCellY = 1;
break;
}
case "I": {
letterCellX = 2;
letterCellY = 1;
break;
}
case "J": {
letterCellX = 3;
letterCellY = 1;
break;
}
case "K": {
letterCellX = 4;
letterCellY = 1;
break;
}
case "L": {
letterCellX = 5;
letterCellY = 1;
break;
}
case "M": {
letterCellX = 0;
letterCellY = 2;
break;
}
case "N": {
letterCellX = 1;
letterCellY = 2;
break;
}
case "O": {
letterCellX = 2;
letterCellY = 2;
break;
}
case "P": {
letterCellX = 3;
letterCellY = 2;
break;
}
case "Q": {
letterCellX = 4;
letterCellY = 2;
break;
}
case "R": {
letterCellX = 5;
letterCellY = 2;
break;
}
case "S": {
letterCellX = 0;
letterCellY = 3;
break;
}
case "T": {
letterCellX = 1;
letterCellY = 3;
break;
}
case "U": {
letterCellX = 2;
letterCellY = 3;
break;
}
case "V": {
letterCellX = 3;
letterCellY = 3;
break;
}
case "W": {
letterCellX = 4;
letterCellY = 3;
break;
}
case "X": {
letterCellX = 5;
letterCellY = 3;
break;
}
case "Y": {
letterCellX = 0;
letterCellY = 4;
break;
}
case "Z": {
letterCellX = 1;
letterCellY = 4;
break;
}
case "1": {
letterCellX = 2;
letterCellY = 4;
break;
}
case "2": {
letterCellX = 3;
letterCellY = 4;
break;
}
case "3": {
letterCellX = 4;
letterCellY = 4;
break;
}
case "4": {
letterCellX = 5;
letterCellY = 4;
break;
}
case "5": {
letterCellX = 0;
letterCellY = 5;
break;
}
case "6": {
letterCellX = 1;
letterCellY = 5;
break;
}
case "7": {
letterCellX = 2;
letterCellY = 5;
break;
}
case "8": {
letterCellX = 3;
letterCellY = 5;
break;
}
case "9": {
letterCellX = 4;
letterCellY = 5;
break;
}
case "0": {
letterCellX = 5;
letterCellY = 5;
break;
}
case ".": {
letterCellX = 0;
letterCellY = 6;
break;
}
case ",": {
letterCellX = 1;
letterCellY = 6;
break;
}
case "-": {
letterCellX = 2;
letterCellY = 6;
break;
}
case "?": {
letterCellX = 3;
letterCellY = 6;
break;
}
case "!": {
letterCellX = 4;
letterCellY = 6;
break;
}
default: {// Default to Space
letterCellX = 5;
letterCellY = 6;
break;
}
}
for (var i = 0; i < text.length; i++) { var lineNumber = Math.floor(i/wrapWidth);
var letterCellX, letterCellY; var horizontal = i - (wrapWidth * lineNumber);
switch (text.charAt(i)) { var letterSheetX = guiControl.alphabet_sheet[color + size.toString()].x + (letterSizeX * letterCellX);
case "A": var letterSheetY = guiControl.alphabet_sheet[color + size.toString()].y + (letterSizeY * letterCellY);
letterCellX = 0; var letterX = x + (letterSizeX * horizontal) + pixel(horizontal); //Places a space between characters horizontally
letterCellY = 0; var letterY = y + (letterSizeY * lineNumber) + pixel(lineNumber); //Places a space between characters vertically
break; OS.context.drawImage(guiControl.alphabet_sheet, letterSheetX, letterSheetY, letterSizeX, letterSizeY, letterX, letterY, letterSizeX, letterSizeY);
case "B": }
letterCellX = 1;
letterCellY = 0;
break;
case "C":
letterCellX = 2;
letterCellY = 0;
break;
case "D":
letterCellX = 3;
letterCellY = 0;
break;
case "E":
letterCellX = 4;
letterCellY = 0;
break;
case "F":
letterCellX = 5;
letterCellY = 0;
break;
case "G":
letterCellX = 0;
letterCellY = 1;
break;
case "H":
letterCellX = 1;
letterCellY = 1;
break;
case "I":
letterCellX = 2;
letterCellY = 1;
break;
case "J":
letterCellX = 3;
letterCellY = 1;
break;
case "K":
letterCellX = 4;
letterCellY = 1;
break;
case "L":
letterCellX = 5;
letterCellY = 1;
break;
case "M":
letterCellX = 0;
letterCellY = 2;
break;
case "N":
letterCellX = 1;
letterCellY = 2;
break;
case "O":
letterCellX = 2;
letterCellY = 2;
break;
case "P":
letterCellX = 3;
letterCellY = 2;
break;
case "Q":
letterCellX = 4;
letterCellY = 2;
break;
case "R":
letterCellX = 5;
letterCellY = 2;
break;
case "S":
letterCellX = 0;
letterCellY = 3;
break;
case "T":
letterCellX = 1;
letterCellY = 3;
break;
case "U":
letterCellX = 2;
letterCellY = 3;
break;
case "V":
letterCellX = 3;
letterCellY = 3;
break;
case "W":
letterCellX = 4;
letterCellY = 3;
break;
case "X":
letterCellX = 5;
letterCellY = 3;
break;
case "Y":
letterCellX = 0;
letterCellY = 4;
break;
case "Z":
letterCellX = 1;
letterCellY = 4;
break;
case "1":
letterCellX = 2;
letterCellY = 4;
break;
case "2":
letterCellX = 3;
letterCellY = 4;
break;
case "3":
letterCellX = 4;
letterCellY = 4;
break;
case "4":
letterCellX = 5;
letterCellY = 4;
break;
case "5":
letterCellX = 0;
letterCellY = 5;
break;
case "6":
letterCellX = 1;
letterCellY = 5;
break;
case "7":
letterCellX = 2;
letterCellY = 5;
break;
case "8":
letterCellX = 3;
letterCellY = 5;
break;
case "9":
letterCellX = 4;
letterCellY = 5;
break;
case "0":
letterCellX = 5;
letterCellY = 5;
break;
case ".":
letterCellX = 0;
letterCellY = 6;
break;
case ",":
letterCellX = 1;
letterCellY = 6;
break;
case "-":
letterCellX = 2;
letterCellY = 6;
break;
case "?":
letterCellX = 3;
letterCellY = 6;
break;
case "!":
letterCellX = 4;
letterCellY = 6;
break;
default: // Default to Space
letterCellX = 5;
letterCellY = 6;
break;
}
var lineNumber = Math.floor(i/wrapWidth);
var horizontal = i - (wrapWidth * lineNumber);
var letterSheetX = guiControl.alphabet_sheet[color + size.toString()].x + (letterSizeX * letterCellX);
var letterSheetY = guiControl.alphabet_sheet[color + size.toString()].y + (letterSizeY * letterCellY);
var letterX = x + (letterSizeX * horizontal) + pixel(horizontal); //Places a space between characters horizontally
var letterY = y + (letterSizeY * lineNumber) + pixel(lineNumber); //Places a space between characters vertically
OS.context.drawImage(guiControl.alphabet_sheet, letterSheetX, letterSheetY, letterSizeX, letterSizeY, letterX, letterY, letterSizeX, letterSizeY);
}
} }

View File

@ -3,220 +3,220 @@ G = Game;
G.gameStarted = false; G.gameStarted = false;
G.savedGameExists = (OS.Load("TradeWindsSave")) ? true : false; G.savedGameExists = (OS.Load("TradeWindsSave")) ? true : 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.
G.currentScreen = ""; // For pause screen, stats screen, inventory screen G.currentScreen = ""; // For pause screen, stats screen, inventory screen
G.inventory = { G.inventory = {
money: 100, money: 100,
supplies: 20, // How much stuff you have to maintain your crew's illness with. supplies: 20, // How much stuff you have to maintain your crew's illness with.
cargo: [0, 0, 0, 0, // Keeps track of how much of each item you have. cargo: [0, 0, 0, 0, // Keeps track of how much of each item you have.
0, 0, 0, 0, // Requires a check to make sure you can't buy more different kinds than you can hold. 0, 0, 0, 0, // Requires a check to make sure you can't buy more different kinds than you can hold.
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0], 0, 0, 0, 0],
moneyDisplay: function () { moneyDisplay: function () {
var moneyString = ""; var moneyString = "";
if (G.inventory.money >= 1000000) { if (G.inventory.money >= 1000000) {
moneyString = G.inventory.money.toString().substr(0, 1); moneyString = G.inventory.money.toString().substr(0, 1);
if (parseInt(G.inventory.money.toString().substr(1, 1)) > 0) { if (parseInt(G.inventory.money.toString().substr(1, 1)) > 0) {
moneyString += "." + G.inventory.money.toString().substr(1, 1); moneyString += "." + G.inventory.money.toString().substr(1, 1);
} }
} }
if (G.inventory.money >= 1000000000000) { if (G.inventory.money >= 1000000000000) {
moneyString += "T"; moneyString += "T";
} else if (G.inventory.money >= 1000000000) { } else if (G.inventory.money >= 1000000000) {
moneyString += "B"; moneyString += "B";
} else if (G.inventory.money >= 1000000) { } else if (G.inventory.money >= 1000000) {
moneyString += "M"; moneyString += "M";
} else { } else {
moneyString = G.inventory.money.toString(); moneyString = G.inventory.money.toString();
} }
return moneyString; return moneyString;
}, },
CheckCargo: function () { // Returns an array of indices that have cargo CheckCargo: function () { // Returns an array of indices that have cargo
var indicesWithCargo = []; var indicesWithCargo = [];
for (var i = 0; i < G.inventory.cargo.length; i++) { for (var i = 0; i < G.inventory.cargo.length; i++) {
if (G.inventory.cargo[i] > 0) { if (G.inventory.cargo[i] > 0) {
indicesWithCargo.push(i); indicesWithCargo.push(i);
} }
} }
return indicesWithCargo; return indicesWithCargo;
}, },
CargoTotal: function () { CargoTotal: function () {
var cargo = G.inventory.CheckCargo(); var cargo = G.inventory.CheckCargo();
var cargoTotal = 0; var cargoTotal = 0;
for (var i = 0; i < cargo.length; i++) { for (var i = 0; i < cargo.length; i++) {
cargoTotal += G.inventory.cargo[cargo[i]]; cargoTotal += G.inventory.cargo[cargo[i]];
} }
return cargoTotal; return cargoTotal;
}, },
CanBuy: function (itemIndex, price) { CanBuy: function (itemIndex, price) {
if (G.inventory.cargo[itemIndex] < G.stats.hold && G.inventory.money > price && if (G.inventory.cargo[itemIndex] < G.stats.hold && G.inventory.money > price &&
(G.inventory.cargo[itemIndex] > 0 || G.inventory.CheckCargo().length < G.stats.inventory)) (G.inventory.cargo[itemIndex] > 0 || G.inventory.CheckCargo().length < G.stats.inventory))
{ {
return true; return true;
} else { } else {
return false; return false;
} }
}, },
CanSell: function (itemIndex) { CanSell: function (itemIndex) {
return G.inventory.cargo[itemIndex] > 0; return G.inventory.cargo[itemIndex] > 0;
} }
}; };
G.stats = { G.stats = {
inventory: 3, // Maximum number of different things the cargo can hold. inventory: 3, // Maximum number of different things the cargo can hold.
hold: 20, // Maximum number of each individual kind of thing in the inventory. hold: 20, // Maximum number of each individual kind of thing in the inventory.
speed: 1, // How many pixels you move. speed: 1, // How many pixels you move.
hull: 3, // Your HP, pretty much. How many times you can crash without exploding. hull: 3, // Your HP, pretty much. How many times you can crash without exploding.
maxHull: 3, // How much your hull can refill to. maxHull: 3, // How much your hull can refill to.
popularity: 5, // Haggle success rate in percentage. popularity: 5, // Haggle success rate in percentage.
haggling: 10, // How much you can increase the asking price by. haggling: 10, // How much you can increase the asking price by.
crew: 2, // How many crew members you have. Influences how fast your energy recovers. crew: 2, // How many crew members you have. Influences how fast your energy recovers.
energy: 25, // Drains rate determined by current speed. When drained, currentSpeed reduces until you have enough energy to continue. energy: 25, // Drains rate determined by current speed. When drained, currentSpeed reduces until you have enough energy to continue.
maxEnergy: 50, // How much to refill your energy to. Can increase with upgrades. maxEnergy: 50, // How much to refill your energy to. Can increase with upgrades.
illness: 0 // Your crew's overall health. When this is low, your ship slows down. illness: 0, // Your crew's overall health. When this is low, your ship slows down.
}; };
G.economy = { // Aww yea, supply and demand. G.economy = { // Aww yea, supply and demand.
// Items are determined by their index, and their position on the sheet determines their index. // Items are determined by their index, and their position on the sheet determines their index.
// So the second item on the top row is index 1, and to get its value, you get `G.economy.cargoItemWorth[1]` // So the second item on the top row is index 1, and to get its value, you get `G.economy.cargoItemWorth[1]`
innCost: 50, innCost: 50,
innStays: 0, innStays: 0,
cargoItemWorth: [10, 20, 30, 30, //Can be adjusted based on sales. cargoItemWorth: [10, 20, 30, 30, //Can be adjusted based on sales.
40, 20, 50, 80, 40, 20, 50, 80,
65, 20, 20, 30, 65, 20, 20, 30,
30, 60, 45, 70], 30, 60, 45, 70],
maxPriceChange: 10, maxPriceChange: 10,
cargoSold: [0, 0, 0, 0, // The more you sell, the lower the price gets cargoSold: [0, 0, 0, 0, // The more you sell, the lower the price gets
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0], 0, 0, 0, 0],
cargoBought: [0, 0, 0, 0, // The more you buy, the higher the price gets cargoBought: [0, 0, 0, 0, // The more you buy, the higher the price gets
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0], 0, 0, 0, 0],
UpdateEconomy: function () { UpdateEconomy: function () {
// console.log(G.economy.cargoItemWorth); // console.log(G.economy.cargoItemWorth);
for (var i = 0; i < G.economy.cargoItemWorth.length; i++) { for (var i = 0; i < G.economy.cargoItemWorth.length; i++) {
var totalPriceDifference = 0; var totalPriceDifference = 0;
for (var m = 0; m < G.map.length; m++) { for (var m = 0; m < G.map.length; m++) {
// console.log("map: " + G.map[m].island); // console.log("map: " + G.map[m].island);
totalPriceDifference += G.map[m].island.priceDifferences[i]; totalPriceDifference += G.map[m].island.priceDifferences[i];
// console.log(G.map[m].island.priceDifferences[i]); // console.log(G.map[m].island.priceDifferences[i]);
} }
G.economy.cargoItemWorth[i] += Math.round(totalPriceDifference / G.map.length); // Apply the average price difference for the item. G.economy.cargoItemWorth[i] += Math.round(totalPriceDifference / G.map.length); // Apply the average price difference for the item.
} }
var totalInnCost = 0; var totalInnCost = 0;
for (var m = 0; m < G.map.length; m++) { for (var m = 0; m < G.map.length; m++) {
totalInnCost += G.map[m].island.innPriceDifference; totalInnCost += G.map[m].island.innPriceDifference;
} }
G.economy.innCost += Math.round(totalInnCost / G.map.length); // Apply the average inn price. G.economy.innCost += Math.round(totalInnCost / G.map.length); // Apply the average inn price.
// console.log(G.economy.cargoItemWorth); // console.log(G.economy.cargoItemWorth);
} },
}; };
G.SaveGame = function () { G.SaveGame = function () {
var saveObject = { var saveObject = {
playerX: G.player.x, playerX: G.player.x,
playerY: G.player.y, playerY: G.player.y,
money: G.inventory.money, money: G.inventory.money,
supplies: G.inventory.supplies, supplies: G.inventory.supplies,
cargo: G.inventory.cargo.slice(), cargo: G.inventory.cargo.slice(),
stats: { stats: {
inventory: G.stats.inventory, inventory: G.stats.inventory,
hold: G.stats.hold, hold: G.stats.hold,
speed: G.stats.speed, speed: G.stats.speed,
hull: G.stats.hull, hull: G.stats.hull,
maxHull: G.stats.maxHull, maxHull: G.stats.maxHull,
popularity: G.stats.popularity, popularity: G.stats.popularity,
haggling: G.stats.haggling, haggling: G.stats.haggling,
crew: G.stats.crew, crew: G.stats.crew,
energy: G.stats.energy, energy: G.stats.energy,
maxEnergy: G.stats.maxEnergy, maxEnergy: G.stats.maxEnergy,
illness: G.stats.illness illness: G.stats.illness,
}, },
economy: { economy: {
innCost: G.economy.innCost, innCost: G.economy.innCost,
innStays: G.economy.innStays, innStays: G.economy.innStays,
itemWorth: G.economy.cargoItemWorth.slice(), itemWorth: G.economy.cargoItemWorth.slice(),
cargoSold: G.economy.cargoSold.slice(), cargoSold: G.economy.cargoSold.slice(),
cargoBought: G.economy.cargoBought.slice() cargoBought: G.economy.cargoBought.slice(),
}, },
map: [] map: [],
}; };
for (var i = 0; i < G.map.length; i++) { for (var i = 0; i < G.map.length; i++) {
saveObject.map.push({ saveObject.map.push({
drawX: G.map[i].drawX, drawX: G.map[i].drawX,
drawY: G.map[i].drawY, drawY: G.map[i].drawY,
drawWidth: G.map[i].drawWidth, drawWidth: G.map[i].drawWidth,
drawHeight: G.map[i].drawHeight, drawHeight: G.map[i].drawHeight,
inventory: G.map[i].island.inventory.slice(), inventory: G.map[i].island.inventory.slice(),
innPriceDifference: G.map[i].island.innPriceDifference, innPriceDifference: G.map[i].island.innPriceDifference,
innStays: G.map[i].island.innStays, innStays: G.map[i].island.innStays,
priceDifferences: G.map[i].island.priceDifferences.slice(), priceDifferences: G.map[i].island.priceDifferences.slice(),
itemsSold: G.map[i].island.itemsSold.slice(), itemsSold: G.map[i].island.itemsSold.slice(),
itemsBought: G.map[i].island.itemsBought.slice() itemsBought: G.map[i].island.itemsBought.slice(),
}); });
} }
if (OS.Save("TradeWindsSave", JSON.stringify(saveObject))) { if (OS.Save("TradeWindsSave", JSON.stringify(saveObject))) {
console.log("Game Saved!"); console.log("Game Saved!");
} }
} }
G.LoadGame = function () { G.LoadGame = function () {
var loadObject = OS.Load("TradeWindsSave"); var loadObject = OS.Load("TradeWindsSave");
if (loadObject) { if (loadObject) {
loadObject = JSON.parse(loadObject); loadObject = JSON.parse(loadObject);
G.player.x = loadObject.playerX; G.player.x = loadObject.playerX;
G.player.y = loadObject.playerY; G.player.y = loadObject.playerY;
G.inventory.money = loadObject.money; G.inventory.money = loadObject.money;
G.inventory.supplies = loadObject.supplies; G.inventory.supplies = loadObject.supplies;
G.inventory.cargo = loadObject.cargo.slice(); G.inventory.cargo = loadObject.cargo.slice();
G.stats.inventory = loadObject.stats.inventory; G.stats.inventory = loadObject.stats.inventory;
G.stats.hold = loadObject.stats.hold; G.stats.hold = loadObject.stats.hold;
G.stats.speed = loadObject.stats.speed; G.stats.speed = loadObject.stats.speed;
G.stats.hull = loadObject.stats.hull; G.stats.hull = loadObject.stats.hull;
G.stats.maxHull = loadObject.stats.maxHull; G.stats.maxHull = loadObject.stats.maxHull;
G.stats.popularity = loadObject.stats.popularity; G.stats.popularity = loadObject.stats.popularity;
G.stats.haggling = loadObject.stats.haggling; G.stats.haggling = loadObject.stats.haggling;
G.stats.crew = loadObject.stats.crew; G.stats.crew = loadObject.stats.crew;
G.stats.energy = loadObject.stats.energy; G.stats.energy = loadObject.stats.energy;
G.stats.maxEnergy = loadObject.stats.maxEnergy; G.stats.maxEnergy = loadObject.stats.maxEnergy;
G.stats.illness = loadObject.stats.illness; G.stats.illness = loadObject.stats.illness;
G.economy.innCost = loadObject.economy.innCost; G.economy.innCost = loadObject.economy.innCost;
G.economy.innStays = loadObject.economy.innStays; G.economy.innStays = loadObject.economy.innStays;
G.economy.cargoItemWorth = loadObject.economy.itemWorth.slice(); G.economy.cargoItemWorth = loadObject.economy.itemWorth.slice();
G.economy.cargoSold = loadObject.economy.cargoSold.slice(); G.economy.cargoSold = loadObject.economy.cargoSold.slice();
G.economy.cargoBought = loadObject.economy.cargoBought.slice(); G.economy.cargoBought = loadObject.economy.cargoBought.slice();
for (var i = 0; i < loadObject.map.length; i++) { for (var i = 0; i < loadObject.map.length; i++) {
G.map[i].drawX = loadObject.map[i].drawX; G.map[i].drawX = loadObject.map[i].drawX;
G.map[i].drawY = loadObject.map[i].drawY; G.map[i].drawY = loadObject.map[i].drawY;
G.map[i].drawWidth = loadObject.map[i].drawWidth; G.map[i].drawWidth = loadObject.map[i].drawWidth;
G.map[i].drawHeight = loadObject.map[i].drawHeight; G.map[i].drawHeight = loadObject.map[i].drawHeight;
G.map[i].island.x = rm_Ocean.squareSize * loadObject.map[i].drawX; G.map[i].island.x = rm_Ocean.squareSize * loadObject.map[i].drawX;
G.map[i].island.y = rm_Ocean.squareSize * loadObject.map[i].drawY; G.map[i].island.y = rm_Ocean.squareSize * loadObject.map[i].drawY;
G.map[i].island.inventory = loadObject.map[i].inventory.slice(); G.map[i].island.inventory = loadObject.map[i].inventory.slice();
G.map[i].island.innPriceDifference = loadObject.map[i].innPriceDifference; G.map[i].island.innPriceDifference = loadObject.map[i].innPriceDifference;
G.map[i].island.innStays = loadObject.map[i].innStays; G.map[i].island.innStays = loadObject.map[i].innStays;
G.map[i].island.priceDifferences = loadObject.map[i].priceDifferences.slice(); G.map[i].island.priceDifferences = loadObject.map[i].priceDifferences.slice();
G.map[i].island.itemsSold = loadObject.map[i].itemsSold.slice(); G.map[i].island.itemsSold = loadObject.map[i].itemsSold.slice();
G.map[i].island.itemsBought = loadObject.map[i].itemsBought.slice(); G.map[i].island.itemsBought = loadObject.map[i].itemsBought.slice();
} }
loadObject = null; loadObject = null;
console.log("Game Loaded!"); console.log("Game Loaded!");
} else { } else {
console.log("Could not load game!"); console.log("Could not load game!");
return false; return false;
} }
} }
function loadGameManager () { function loadGameManager () {
for (var i = 0; i < G.economy.cargoItemWorth.length; i++) { for (var i = 0; i < G.economy.cargoItemWorth.length; i++) {
G.economy.cargoItemWorth[i] += Math.round(Math.randomRange(-5, 5)); G.economy.cargoItemWorth[i] += Math.round(Math.randomRange(-5, 5));
} }
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadGameManager()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran loadGameManager()");
} }

View File

@ -1,33 +1,32 @@
var prefabsLoaded = 0; var prefabsLoaded = 0;
var prefabsToLoad = 4; var prefabsToLoad = 4;
function loadPrefabs() { function loadPrefabs() {
OS.AddScript("prefabs/shipPrefab.js"); OS.AddScript("prefabs/shipPrefab.js");
OS.AddScript("prefabs/islandPrefab.js"); OS.AddScript("prefabs/islandPrefab.js");
OS.AddScript("prefabs/oceanTilePrefab.js"); OS.AddScript("prefabs/oceanTilePrefab.js");
OS.AddScript("prefabs/wavePrefab.js"); OS.AddScript("prefabs/wavePrefab.js");
// Delay switching to Ocean room until everything is loaded. // Delay switching to Ocean room until everything is loaded.
WaitForPrefabsToLoad(); WaitForPrefabsToLoad();
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadPrefabs()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran loadPrefabs()");
} }
// Callback function that prevents Ocean room from loading before everything it references is loaded. // Callback function that prevents Ocean room from loading before everything it references is loaded.
WaitForPrefabsToLoad = function () { WaitForPrefabsToLoad = function () {
console.log("waiting for " + (prefabsToLoad - prefabsLoaded).toString() + " prefabs to load"); console.log("waiting for " + (prefabsToLoad - prefabsLoaded).toString() + " prefabs to load");
if (prefabsLoaded < prefabsToLoad || !window["oceanRoom"]) if (prefabsLoaded < prefabsToLoad || !window["oceanRoom"]) {
{ setTimeout(function(){WaitForPrefabsToLoad()}, 0.1);
setTimeout(function(){WaitForPrefabsToLoad()}, 0.1); } else {
// Create player and ocean objects in rm_Ocean.
G.player = rm_Ocean.AddObject(OS.P["Ship"]);
G.oceanParticle = rm_Ocean.AddObject(OS.P["Ocean Particle"]);
if (G.player.xBound) { // Force rm_Ocean to wait until G.player is completely loaded!
// Load the rooms only after the prefabs are loaded.
rm_Ocean.SetAsCurrentRoom();
} else { } else {
// Create player and ocean objects in rm_Ocean. setTimeout(function(){WaitForPrefabsToLoad()}, 0.1);
G.player = rm_Ocean.AddObject(OS.P["Ship"]);
G.oceanParticle = rm_Ocean.AddObject(OS.P["Ocean Particle"]);
if (G.player.xBound) { // Force rm_Ocean to wait until G.player is completely loaded!
// Load the rooms only after the prefabs are loaded.
rm_Ocean.SetAsCurrentRoom();
} else {
setTimeout(function(){WaitForPrefabsToLoad()}, 0.1);
}
} }
}
} }

View File

@ -1,20 +1,20 @@
var rm_Load = OS.R.Add("Default"); var rm_Load = OS.R.Add("Default");
var rm_Ocean = OS.R.Add("Ocean Room", { var rm_Ocean = OS.R.Add("Ocean Room", {
// 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.
height: pixel(64) * 44, height: pixel(64) * 44,
backgroundColor: "#1b2632", backgroundColor: "#1b2632",
squaresX: 50, squaresX: 50,
squaresY: 44, squaresY: 44,
squareSize: pixel(64), squareSize: pixel(64),
numberOfIslands: 10, numberOfIslands: 10,
clockTimerCutoff: ((1 / OS.S.defaultStep) * 60) * 5 // 5 minute day. clockTimerCutoff: ((1 / OS.S.defaultStep) * 60) * 5, // 5 minute day.
}); });
function loadRooms() { function loadRooms() {
OS.AddScript("rooms/oceanRoom.js"); OS.AddScript("rooms/oceanRoom.js");
rm_Load.SetAsCurrentRoom(); rm_Load.SetAsCurrentRoom();
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadRooms()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran loadRooms()");
} }

View File

@ -1,243 +1,243 @@
var ani_island_1 = OS.A.Add("Island 1", 256, 256, {}); var ani_island_1 = OS.A.Add("Island 1", 256, 256, {});
function islandPrefab() { function islandPrefab() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran islandPrefab()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran islandPrefab()");
prefabsLoaded++; prefabsLoaded++;
} }
var pr_island = OS.P.Add("Island", { var pr_island = OS.P.Add("Island", {
solid: true, solid: true,
imageSrc: "images/island.png", imageSrc: "images/island.png",
animations: [ani_island_1], animations: [ani_island_1],
depth: -50, depth: -50,
mapX: 0, mapX: 0,
mapY: 0, mapY: 0,
mapWidth: 1, mapWidth: 1,
mapHeight: 1, mapHeight: 1,
mapColor: "#00AB00", mapColor: "#00AB00",
canTrade: true, canTrade: true,
haggleAmount: 0, haggleAmount: 0,
timesHaggledToday: 0, timesHaggledToday: 0,
itemsSoldToday: [0, 0, 0, 0, itemsSoldToday: [0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0], 0, 0, 0, 0],
itemsBoughtToday: [0, 0, 0, 0, itemsBoughtToday: [0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0], 0, 0, 0, 0],
money: 0, money: 0,
inventory: [0, 0, 0, 0, inventory: [0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0], 0, 0, 0, 0],
storageSpace: [0, 0, 0, 0, storageSpace: [0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0], 0, 0, 0, 0],
innPriceDifference: 0, innPriceDifference: 0,
innStays: 0, innStays: 0,
priceDifferences: [0, 0, 0, 0, priceDifferences: [0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0], 0, 0, 0, 0],
itemsSold: [0, 0, 0, 0, // The more you sell, the lower the price gets itemsSold: [0, 0, 0, 0, // The more you sell, the lower the price gets
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0], 0, 0, 0, 0],
itemsBought: [0, 0, 0, 0, // The more you buy, the higher the price gets itemsBought: [0, 0, 0, 0, // The more you buy, the higher the price gets
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0], 0, 0, 0, 0],
storageFee: 10, storageFee: 10,
storageFeeMultiplier: 0.1, storageFeeMultiplier: 0.1,
storage: [0, 0, 0, 0, storage: [0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0] 0, 0, 0, 0],
}); });
pr_island.DoFirst = function () { pr_island.DoFirst = function () {
this.GetMapPosition(); this.GetMapPosition();
this.SetUp(); this.SetUp();
} }
pr_island.GetMapPosition = function () { pr_island.GetMapPosition = function () {
this.mapX = (this.x / OS.S.pixelScale) / (OS.camera.width / OS.S.pixelScale); this.mapX = (this.x / OS.S.pixelScale) / (OS.camera.width / OS.S.pixelScale);
this.mapY = (this.y / OS.S.pixelScale) / (OS.camera.height / OS.S.pixelScale); this.mapY = (this.y / OS.S.pixelScale) / (OS.camera.height / OS.S.pixelScale);
} }
pr_island.SetUp = function () { pr_island.SetUp = function () {
for (var i = 0; i < 16; i++) { for (var i = 0; i < 16; i++) {
this.storageSpace[i] = Math.round(Math.randomRange(20, 35)); this.storageSpace[i] = Math.round(Math.randomRange(20, 35));
if (this.storageSpace[i] > 30) { if (this.storageSpace[i] > 30) {
this.inventory[i] = Math.round(this.storageSpace[i] - Math.randomRange(0, 30)); this.inventory[i] = Math.round(this.storageSpace[i] - Math.randomRange(0, 30));
} else if (Math.randomRange(0, 100) < 25) { } else if (Math.randomRange(0, 100) < 25) {
this.inventory[i] = Math.round(Math.randomRange(0, this.storageSpace[i])); this.inventory[i] = Math.round(Math.randomRange(0, this.storageSpace[i]));
} }
} }
// console.log(this.name + " stock: " + this.inventory); // console.log(this.name + " stock: " + this.inventory);
this.AdjustPrices(); this.AdjustPrices();
// console.log(this.name + " pricing: " + this.priceDifferences); // console.log(this.name + " pricing: " + this.priceDifferences);
if (this.CheckInventory().length < 4) { if (this.CheckInventory().length < 4) {
this.SetUp(); this.SetUp();
} else { } else {
for (var i = 0; i < 16; i++) { for (var i = 0; i < 16; i++) {
// Generate the amount of money the shop has based on what it has. // Generate the amount of money the shop has based on what it has.
this.money += (G.economy.cargoItemWorth[i] + this.priceDifferences[i]) * this.inventory[i]; this.money += (G.economy.cargoItemWorth[i] + this.priceDifferences[i]) * this.inventory[i];
} }
// Minimum amount of money is 100. // Minimum amount of money is 100.
if (this.money < 100) this.money = 100; if (this.money < 100) this.money = 100;
} }
} }
pr_island.AdjustPrices = function () { pr_island.AdjustPrices = function () {
for (var i = 0; i < 16; i++) { for (var i = 0; i < 16; i++) {
// Save the previous price difference so the change doesn't get above a certain thereshold. // Save the previous price difference so the change doesn't get above a certain thereshold.
var previousPrice = newPriceDifference = this.priceDifferences[i]; var previousPrice = newPriceDifference = this.priceDifferences[i];
if (this.inventory[i] > (this.storageSpace[i] / 2)) { if (this.inventory[i] > (this.storageSpace[i] / 2)) {
newPriceDifference -= Math.round(this.inventory[i] * Math.randomRange(1, 3)); newPriceDifference -= Math.round(this.inventory[i] * Math.randomRange(1, 3));
} }
else if (this.inventory[i] < (this.storageSpace[i] / 4)) { else if (this.inventory[i] < (this.storageSpace[i] / 4)) {
newPriceDifference += Math.round((this.storageSpace[i] - this.inventory[i]) * Math.randomRange(1, 3)); newPriceDifference += Math.round((this.storageSpace[i] - this.inventory[i]) * Math.randomRange(1, 3));
} }
else { else {
newPriceDifference += Math.round(Math.randomRange(-2, 2)); newPriceDifference += Math.round(Math.randomRange(-2, 2));
} }
newPriceDifference = Math.round(newPriceDifference * ((this.itemsBought[i] + 1) / (this.itemsSold[i] + 1))); newPriceDifference = Math.round(newPriceDifference * ((this.itemsBought[i] + 1) / (this.itemsSold[i] + 1)));
if (Math.abs(newPriceDifference) > Math.abs(previousPrice) + G.economy.maxPriceChange) { if (Math.abs(newPriceDifference) > Math.abs(previousPrice) + G.economy.maxPriceChange) {
// Prevent price from changing more than the limit. // Prevent price from changing more than the limit.
newPriceDifference = previousPrice + ((previousPrice < 0) ? -G.economy.maxPriceChange : G.economy.maxPriceChange); newPriceDifference = previousPrice + ((previousPrice < 0) ? -G.economy.maxPriceChange : G.economy.maxPriceChange);
} }
if (G.economy.cargoItemWorth[i] + newPriceDifference < 0) { if (G.economy.cargoItemWorth[i] + newPriceDifference < 0) {
newPriceDifference = -G.economy.cargoItemWorth[i] + 1; newPriceDifference = -G.economy.cargoItemWorth[i] + 1;
} }
this.priceDifferences[i] = newPriceDifference; this.priceDifferences[i] = newPriceDifference;
} }
var priceDifferencesOrdered = this.priceDifferences.slice().sort(sortNumber); var priceDifferencesOrdered = this.priceDifferences.slice().sort(sortNumber);
this.innPriceDifference += Math.round(Math.randomRange(priceDifferencesOrdered[0], priceDifferencesOrdered[priceDifferencesOrdered.length -1])) - Math.round(Math.randomRange(0, this.innStays)); this.innPriceDifference += Math.round(Math.randomRange(priceDifferencesOrdered[0], priceDifferencesOrdered[priceDifferencesOrdered.length -1])) - Math.round(Math.randomRange(0, this.innStays));
} }
pr_island.SimulateTrade = function () { pr_island.SimulateTrade = function () {
// This will be run on a timer that runs when not trading. // This will be run on a timer that runs when not trading.
for (var i = 0; i < 16; i++) { for (var i = 0; i < 16; i++) {
var amount = 0; var amount = 0;
if (this.inventory[i] > 0) { if (this.inventory[i] > 0) {
amount = Math.round(Math.randomRange(-this.storageSpace[i], this.storageSpace[i])); amount = Math.round(Math.randomRange(-this.storageSpace[i], this.storageSpace[i]));
this.inventory[i] += amount; this.inventory[i] += amount;
if (this.inventory[i] < 0) { if (this.inventory[i] < 0) {
this.inventory[i] = 0; this.inventory[i] = 0;
} }
if (this.inventory[i] > this.storageSpace[i]) { if (this.inventory[i] > this.storageSpace[i]) {
this.inventory[i] = this.storageSpace[i]; this.inventory[i] = this.storageSpace[i];
} }
} else { } else {
if (Math.randomRange(0, 100) < 15) { if (Math.randomRange(0, 100) < 15) {
amount = Math.round(Math.randomRange(0, this.storageSpace[i])); amount = Math.round(Math.randomRange(0, this.storageSpace[i]));
this.inventory[i] = amount; this.inventory[i] = amount;
} }
} }
// If the amount is positive, then subtract half the amount from the money (because they bought stuff) // If the amount is positive, then subtract half the amount from the money (because they bought stuff)
// Otherwise, add the negative amount (because they sold that much) // Otherwise, add the negative amount (because they sold that much)
this.money += (-amount * (G.economy.cargoItemWorth[i] + this.priceDifferences[i])) * ((amount > 0) ? 0.5 : 1); this.money += (-amount * (G.economy.cargoItemWorth[i] + this.priceDifferences[i])) * ((amount > 0) ? 0.5 : 1);
} }
if (this.money <= 0) this.money = 100; // If they run out of money, give them some. if (this.money <= 0) this.money = 100; // If they run out of money, give them some.
this.AdjustPrices(); this.AdjustPrices();
} }
pr_island.NewDay = function () { pr_island.NewDay = function () {
this.haggleAmount = 0; this.haggleAmount = 0;
this.timesHaggledToday = 0; this.timesHaggledToday = 0;
this.itemsSoldToday = [0, 0, 0, 0, this.itemsSoldToday = [0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0]; 0, 0, 0, 0];
this.itemsBoughtToday = [0, 0, 0, 0, this.itemsBoughtToday = [0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0]; 0, 0, 0, 0];
this.SimulateTrade(); this.SimulateTrade();
} }
pr_island.CheckInventory = function () { // Returns an array of indices that have cargo pr_island.CheckInventory = function () { // Returns an array of indices that have cargo
var indicesWithCargo = []; var indicesWithCargo = [];
for (var i = 0; i < this.inventory.length; i++) { for (var i = 0; i < this.inventory.length; i++) {
if (this.inventory[i] > 0) { if (this.inventory[i] > 0) {
indicesWithCargo.push(i); indicesWithCargo.push(i);
} }
} }
return indicesWithCargo; return indicesWithCargo;
} }
pr_island.TradeWith = function () { pr_island.TradeWith = function () {
// Change music to Trade. // Change music to Trade.
// console.log(this.inventory); // console.log(this.inventory);
mus_sail.Stop(); mus_sail.Stop();
mus_trade.Play(); mus_trade.Play();
guiControl.trade.island = this; guiControl.trade.island = this;
guiControl.trade.haggleAmount = 0; guiControl.trade.haggleAmount = 0;
guiControl.trade.activateDelay = 5; guiControl.trade.activateDelay = 5;
guiControl.trade.show = true; guiControl.trade.show = true;
} }
pr_island.CanSellTo = function (itemIndex, price) { pr_island.CanSellTo = function (itemIndex, price) {
if (this.inventory[itemIndex] < this.storageSpace[itemIndex] && price < this.money) { if (this.inventory[itemIndex] < this.storageSpace[itemIndex] && price < this.money) {
// If there's space in the inventory and there's enough money. // If there's space in the inventory and there's enough money.
return true; return true;
} }
return false; return false;
} }
pr_island.SellTo = function (itemIndex, price) { pr_island.SellTo = function (itemIndex, price) {
// Play Buy sound. // Play Buy sound.
this.inventory[itemIndex]++; this.inventory[itemIndex]++;
this.itemsBought[itemIndex]++; this.itemsBought[itemIndex]++;
this.money -= price; this.money -= price;
G.inventory.cargo[itemIndex]--; G.inventory.cargo[itemIndex]--;
G.inventory.money += price; G.inventory.money += price;
G.economy.cargoSold[itemIndex]++; G.economy.cargoSold[itemIndex]++;
} }
pr_island.CanBuyFrom = function (itemIndex, price) { pr_island.CanBuyFrom = function (itemIndex, price) {
if (this.inventory[itemIndex] > 0) { // If there's enough of the item if (this.inventory[itemIndex] > 0) { // If there's enough of the item
return true; return true;
} }
return false; return false;
} }
pr_island.BuyFrom = function (itemIndex, price) { pr_island.BuyFrom = function (itemIndex, price) {
// Play Sell sound. // Play Sell sound.
this.inventory[itemIndex]--; this.inventory[itemIndex]--;
this.itemsSold[itemIndex]++; this.itemsSold[itemIndex]++;
this.money += price; this.money += price;
G.inventory.cargo[itemIndex]++; G.inventory.cargo[itemIndex]++;
G.inventory.money -= price; G.inventory.money -= price;
G.economy.cargoBought[itemIndex]++; G.economy.cargoBought[itemIndex]++;
} }
pr_island.StayAtInn = function () { pr_island.StayAtInn = function () {
// Play Sell sound. // Play Sell sound.
this.innStays++; this.innStays++;
G.stats.illness--; G.stats.illness--;
G.inventory.money -= G.economy.innCost + this.innPriceDifference; G.inventory.money -= G.economy.innCost + this.innPriceDifference;
G.economy.innStays++; G.economy.innStays++;
} }

View File

@ -1,84 +1,93 @@
var ani_ocean = OS.A.Add("Ocean", 256, 256, {columns: 10, speed: 1/60}); var ani_ocean = OS.A.Add("Ocean", 256, 256, { columns: 10, speed: 1/60 });
function oceanTilePrefab() { function oceanTilePrefab() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran oceanTilePrefab()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran oceanTilePrefab()");
prefabsLoaded++; prefabsLoaded++;
} }
var pr_ocean = OS.P.Add("Ocean Particle", { var pr_ocean = OS.P.Add("Ocean Particle", {
imageSrc: "images/ocean_sheet.png", imageSrc: "images/ocean_sheet.png",
animations: [ani_ocean], animations: [ani_ocean],
depth: -100, // Draw below everything. depth: -100, // Draw below everything.
positionCheckStep: 30, positionCheckStep: 30,
positionCheckProgress: 30, positionCheckProgress: 30,
doCheckPosition: false, doCheckPosition: false,
moveTimer: 0, moveTimer: 0,
}); });
pr_ocean.BeforeDo = function () { pr_ocean.BeforeDo = function () {
this.positionCheckProgress++; this.positionCheckProgress++;
if (this.positionCheckProgress >= this.positionCheckStep) { if (this.positionCheckProgress >= this.positionCheckStep) {
this.positionCheckProgress = 0; this.positionCheckProgress = 0;
this.doCheckPosition = true; this.doCheckPosition = true;
} }
} }
pr_ocean.Do = function () { pr_ocean.Do = function () {
// Move around randomly. // Move around randomly.
this.moveTimer++; this.moveTimer++;
if (this.moveTimer >= 120) { if (this.moveTimer >= 120) {
this.x += 1 * pixel(Math.round(Math.randomRange(-1, 1))); this.x += 1 * pixel(Math.round(Math.randomRange(-1, 1)));
this.y += 1 * pixel(Math.round(Math.randomRange(-1, 1))); this.y += 1 * pixel(Math.round(Math.randomRange(-1, 1)));
this.moveTimer = 0; this.moveTimer = 0;
} }
} }
pr_ocean.CheckPosition = function (checkX, checkY, direction) { pr_ocean.CheckPosition = function (checkX, checkY, direction) {
if (this.doCheckPosition) { if (this.doCheckPosition) {
// If it's completely off the screen, then update position. // If it's completely off the screen, then update position.
if ((Math.abs(this.x - checkX) > (OS.camera.width + this.xBound)) || if ((Math.abs(this.x - checkX) > (OS.camera.width + this.xBound)) ||
(Math.abs(this.y - checkY) > (OS.camera.height + this.yBound))) (Math.abs(this.y - checkY) > (OS.camera.height + this.yBound)))
{ {
switch (direction) { switch (direction) {
case 0: case 0: {
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge(); this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY + randomSmidge(); this.y = checkY + randomSmidge();
break; break;
case 45: }
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge(); case 45: {
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge(); this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
break; break;
case 90: }
this.x = checkX + randomSmidge(); case 90: {
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge(); this.x = checkX + randomSmidge();
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
break; break;
case 135: }
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge(); case 135: {
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge(); this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
break; break;
case 180: }
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge(); case 180: {
this.y = checkY + randomSmidge(); this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY + randomSmidge();
break; break;
case 225: }
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge(); case 225: {
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge(); this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
break; break;
case 270: }
this.x = checkX + randomSmidge(); case 270: {
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge(); this.x = checkX + randomSmidge();
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
break; break;
case 315: }
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge(); case 315: {
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge(); this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
break; break;
default: }
console.log("No valid direction"); default: {
console.log("No valid direction");
break; break;
} }
} }
}
this.doCheckPosition = false; this.doCheckPosition = false;
} }
} }

View File

@ -8,224 +8,233 @@ var ani_ship_d = OS.A.Add("Ship Down", 64, 64, {columns: 2, speed: 1/60, yOffset
var ani_ship_dr = OS.A.Add("Ship Down-Right", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 2}); var ani_ship_dr = OS.A.Add("Ship Down-Right", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 2});
function shipPrefab() { function shipPrefab() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran shipPrefab()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran shipPrefab()");
prefabsLoaded++; prefabsLoaded++;
} }
var pr_ship = OS.P.Add("Ship", { var pr_ship = OS.P.Add("Ship", {
solid: true, solid: true,
imageSrc: "images/ship_sheet.png", imageSrc: "images/ship_sheet.png",
maskImageSrc: "images/ship_mask.png", maskImageSrc: "images/ship_mask.png",
animations: [ani_ship_r, ani_ship_ur, ani_ship_u, ani_ship_ul, ani_ship_l, ani_ship_dl, ani_ship_d, ani_ship_dr], animations: [ani_ship_r, ani_ship_ur, ani_ship_u, ani_ship_ul, ani_ship_l, ani_ship_dl, ani_ship_d, ani_ship_dr],
direction: 0, direction: 0,
currentSpeed: 0, currentSpeed: 0,
pointInFront : {x: 0, y: 0 }, pointInFront : {x: 0, y: 0 },
moveStepSize: 3, moveStepSize: 3,
moveStepAmount: 5 * OS.R[OS.R.currentRoom].stepSpeed, moveStepAmount: 5 * OS.R[OS.R.currentRoom].stepSpeed,
moveStepProgress: 0, moveStepProgress: 0,
doTakeStep: false, doTakeStep: false,
energyRefillTimer: 0, energyRefillTimer: 0,
drawSickIndicator: 0, drawSickIndicator: 0,
drawSickIndicatorTime: secondsWorthOfFrames(1.5) drawSickIndicatorTime: secondsWorthOfFrames(1.5),
}); });
pr_ship.BeforeDo = function () { pr_ship.BeforeDo = function () {
if (G.gameStarted) { if (G.gameStarted) {
this.GetMapPosition(); this.GetMapPosition();
} }
} }
pr_ship.Do = function () { pr_ship.Do = function () {
if (G.gameStarted) { 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) {
this.direction += 45; this.direction += 45;
} else if (ct_right().down) { } else if (ct_right().down) {
this.direction -= 45; this.direction -= 45;
} }
this.direction = Math.clampAngle(this.direction); this.direction = Math.clampAngle(this.direction);
if (ct_up().down) { if (ct_up().down) {
this.currentSpeed++; this.currentSpeed++;
} else if (ct_down().down) { } else if (ct_down().down) {
this.currentSpeed--; this.currentSpeed--;
} }
this.AdjustSpeedBasedOnEnergy(); this.AdjustSpeedBasedOnEnergy();
this.CheckInteraction(); this.CheckInteraction();
} }
} }
this.currentSpeed = Math.clamp(this.currentSpeed, 0, 4); this.currentSpeed = Math.clamp(this.currentSpeed, 0, 4);
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;
this.doTakeStep = true; this.doTakeStep = true;
} else { } else {
this.doTakeStep = false; this.doTakeStep = false;
} }
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) { if (G.gameStarted) {
this.CheckMovement(); this.CheckMovement();
this.UpdateEnergy(); this.UpdateEnergy();
} }
} }
pr_ship.DrawAbove = function () { pr_ship.DrawAbove = function () {
if (G.gameStarted) { if (G.gameStarted) {
this.drawSickIndicator--; this.drawSickIndicator--;
if (this.drawSickIndicator < 0) { if (this.drawSickIndicator < 0) {
this.drawSickIndicator = 0; this.drawSickIndicator = 0;
} }
if (this.drawSickIndicator > 0) { if (this.drawSickIndicator > 0) {
var sickIndicatorHeight = Math.round((this.drawSickIndicatorTime - this.drawSickIndicator) / 2) / OS.S.pixelScale; var sickIndicatorHeight = Math.round((this.drawSickIndicatorTime - this.drawSickIndicator) / 2) / OS.S.pixelScale;
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 () {
this.mapX = pixel(Math.round(this.x / pixel(64))); this.mapX = pixel(Math.round(this.x / pixel(64)));
this.mapY = pixel(Math.round(this.y / pixel(64))); this.mapY = pixel(Math.round(this.y / pixel(64)));
// console.log(this.mapX + ", " + this.mapY); // console.log(this.mapX + ", " + this.mapY);
} }
pr_ship.CheckInteraction = function () { pr_ship.CheckInteraction = function () {
if (ct_confirm().down) { if (ct_confirm().down) {
var objectsFound = OS.GameObjectsAtPoint(this.pointInFront.x, this.pointInFront.y); var objectsFound = OS.GameObjectsAtPoint(this.pointInFront.x, this.pointInFront.y);
if (objectsFound.length > 0) { if (objectsFound.length > 0) {
for (var i = 0; i < objectsFound.length; i++) { for (var i = 0; i < objectsFound.length; i++) {
if (objectsFound[i].canTrade) { if (objectsFound[i].canTrade) {
// console.log("interacting with island: " + objectsFound[i].name); // console.log("interacting with island: " + objectsFound[i].name);
objectsFound[i].TradeWith(); objectsFound[i].TradeWith();
} }
} }
} }
} }
} }
pr_ship.CheckMovement = function () { pr_ship.CheckMovement = function () {
var moveAmount = pixel(G.stats.speed + this.currentSpeed); var moveAmount = pixel(G.stats.speed + this.currentSpeed);
var movedSuccessfully = false; var movedSuccessfully = false;
switch (this.direction) { switch (this.direction) {
case 0: case 0: {
if (this.sprite.currentAnimation != "Ship Right") this.SetAnimation("Ship Right"); if (this.sprite.currentAnimation != "Ship Right") this.SetAnimation("Ship Right");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, 0, true, pixel(4)); if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, 0, true, pixel(4));
this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount; this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount;
this.pointInFront.y = this.y; this.pointInFront.y = this.y;
break; break;
case 45: }
if (this.sprite.currentAnimation != "Ship Up-Right") this.SetAnimation("Ship Up-Right"); case 45: {
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, -moveAmount, true, pixel(4)); if (this.sprite.currentAnimation != "Ship Up-Right") this.SetAnimation("Ship Up-Right");
this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount; if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, -moveAmount, true, pixel(4));
this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount; this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount;
break; this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount;
case 90: break;
if (this.sprite.currentAnimation != "Ship Up") this.SetAnimation("Ship Up"); }
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, -moveAmount, true, pixel(4)); case 90: {
this.pointInFront.x = this.x; if (this.sprite.currentAnimation != "Ship Up") this.SetAnimation("Ship Up");
this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount; if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, -moveAmount, true, pixel(4));
break; this.pointInFront.x = this.x;
case 135: this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount;
if (this.sprite.currentAnimation != "Ship Up-Left") this.SetAnimation("Ship Up-Left"); break;
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, -moveAmount, true, pixel(4)); }
this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount; case 135: {
this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount; if (this.sprite.currentAnimation != "Ship Up-Left") this.SetAnimation("Ship Up-Left");
break; if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, -moveAmount, true, pixel(4));
case 180: this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount;
if (this.sprite.currentAnimation != "Ship Left") this.SetAnimation("Ship Left"); this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount;
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, 0, true, pixel(4)); break;
this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount; }
this.pointInFront.y = this.y; case 180: {
break; if (this.sprite.currentAnimation != "Ship Left") this.SetAnimation("Ship Left");
case 225: if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, 0, true, pixel(4));
if (this.sprite.currentAnimation != "Ship Down-Left") this.SetAnimation("Ship Down-Left"); this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount;
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, moveAmount, true, pixel(4)); this.pointInFront.y = this.y;
this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount; break;
this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount; }
break; case 225: {
case 270: if (this.sprite.currentAnimation != "Ship Down-Left") this.SetAnimation("Ship Down-Left");
if (this.sprite.currentAnimation != "Ship Down") this.SetAnimation("Ship Down"); if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, moveAmount, true, pixel(4));
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, moveAmount, true, pixel(4)); this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount;
this.pointInFront.x = this.x; this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount;
this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount; break;
break; }
case 315: case 270: {
if (this.sprite.currentAnimation != "Ship Down-Right") this.SetAnimation("Ship Down-Right"); if (this.sprite.currentAnimation != "Ship Down") this.SetAnimation("Ship Down");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, moveAmount, true, pixel(4)); if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, moveAmount, true, pixel(4));
this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount; this.pointInFront.x = this.x;
this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount; this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount;
break; break;
default: }
console.log("No valid direction"); case 315: {
break; if (this.sprite.currentAnimation != "Ship Down-Right") this.SetAnimation("Ship Down-Right");
} if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, moveAmount, true, pixel(4));
this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount;
this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount;
break;
}
default: {
console.log("No valid direction");
break;
}
}
if (this.doTakeStep && !movedSuccessfully) { if (this.doTakeStep && !movedSuccessfully) {
this.currentSpeed = 0; this.currentSpeed = 0;
} }
} }
pr_ship.UpdateEnergy = function () { pr_ship.UpdateEnergy = function () {
this.energyRefillTimer++; this.energyRefillTimer++;
if (this.energyRefillTimer >= (100 / G.stats.crew) + ((G.stats.illness) * (100 / G.stats.crew))) { if (this.energyRefillTimer >= (100 / G.stats.crew) + ((G.stats.illness) * (100 / G.stats.crew))) {
G.stats.energy += G.stats.crew; G.stats.energy += G.stats.crew;
this.energyRefillTimer = 0; this.energyRefillTimer = 0;
} }
if (this.doTakeStep) { if (this.doTakeStep) {
G.stats.energy -= ((this.currentSpeed / G.stats.speed) + ((G.stats.illness) * 0.1)) * 0.25; G.stats.energy -= ((this.currentSpeed / G.stats.speed) + ((G.stats.illness) * 0.1)) * 0.25;
} }
if (G.stats.energy < 0) G.stats.energy = 0; if (G.stats.energy < 0) G.stats.energy = 0;
if (G.stats.energy > G.stats.maxEnergy) G.stats.energy = G.stats.maxEnergy; if (G.stats.energy > G.stats.maxEnergy) G.stats.energy = G.stats.maxEnergy;
} }
pr_ship.SeamlessScroll = function () { pr_ship.SeamlessScroll = function () {
if (this.x <= rm_Ocean.mapLeftTrigger) { if (this.x <= rm_Ocean.mapLeftTrigger) {
this.x = rm_Ocean.mapLeftTriggerTarget; this.x = rm_Ocean.mapLeftTriggerTarget;
OS.SetCamera({x: rm_Ocean.width}); OS.SetCamera({x: rm_Ocean.width});
} }
else if (this.x >= rm_Ocean.mapRightTrigger) { else if (this.x >= rm_Ocean.mapRightTrigger) {
this.x = rm_Ocean.mapRightTriggerTarget; this.x = rm_Ocean.mapRightTriggerTarget;
OS.SetCamera({x: 0}); OS.SetCamera({x: 0});
} }
else if (this.y <= rm_Ocean.mapUpTrigger) { else if (this.y <= rm_Ocean.mapUpTrigger) {
this.y = rm_Ocean.mapUpTriggerTarget; this.y = rm_Ocean.mapUpTriggerTarget;
OS.SetCamera({y: rm_Ocean.height}); OS.SetCamera({y: rm_Ocean.height});
} }
else if (this.y >= rm_Ocean.mapDownTrigger) { else if (this.y >= rm_Ocean.mapDownTrigger) {
this.y = rm_Ocean.mapDownTriggerTarget; this.y = rm_Ocean.mapDownTriggerTarget;
OS.SetCamera({y: 0}); OS.SetCamera({y: 0});
} }
} }
pr_ship.AdjustSpeedBasedOnEnergy = function () { pr_ship.AdjustSpeedBasedOnEnergy = function () {
if (this.currentSpeed > 3 && G.stats.energy < (G.stats.maxEnergy * 0.3) || if (this.currentSpeed > 3 && G.stats.energy < (G.stats.maxEnergy * 0.3) ||
this.currentSpeed > 2 && G.stats.energy < (G.stats.maxEnergy * 0.15) || this.currentSpeed > 2 && G.stats.energy < (G.stats.maxEnergy * 0.15) ||
this.currentSpeed > 1 && G.stats.energy < (G.stats.maxEnergy * 0.05)) this.currentSpeed > 1 && G.stats.energy < (G.stats.maxEnergy * 0.05))
{ {
this.currentSpeed--; this.currentSpeed--;
} }
} }
pr_ship.CheckIllnessIncrease = function () { pr_ship.CheckIllnessIncrease = function () {
var percentChance = G.stats.crew + ((this.currentSpeed / (G.stats.energy + 0.001)) * G.stats.illness); // +0.001 on the off-chance that energy reaches 0. var percentChance = G.stats.crew + ((this.currentSpeed / (G.stats.energy + 0.001)) * G.stats.illness); // +0.001 on the off-chance that energy reaches 0.
if (Math.randomRange(0, 100) < percentChance) { if (Math.randomRange(0, 100) < percentChance) {
snd_illness.Play(); snd_illness.Play();
G.stats.illness++; G.stats.illness++;
this.drawSickIndicator += secondsWorthOfFrames(1.5); this.drawSickIndicator += secondsWorthOfFrames(1.5);
} }
} }

View File

@ -1,27 +1,27 @@
var ani_wave = OS.A.Add("Wave", 64, 64, {columns: 10, speed: 1/10}); var ani_wave = OS.A.Add("Wave", 64, 64, {columns: 10, speed: 1/10});
function wavePrefab() { function wavePrefab() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran wavePrefab()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran wavePrefab()");
prefabsLoaded++; prefabsLoaded++;
} }
var pr_wave = OS.P.Add("Wave Particle", { var pr_wave = OS.P.Add("Wave Particle", {
imageSrc: "images/wave_sheet.png", imageSrc: "images/wave_sheet.png",
animations: [ani_wave], animations: [ani_wave],
depth: -90, // Draw above ocean, below everything else. depth: -90, // Draw above ocean, below everything else.
lifeTimer: 100, lifeTimer: 100,
}); });
pr_wave.DoFirst = function () { pr_wave.DoFirst = function () {
if (!snd_wave.IsPlaying()) { if (!snd_wave.IsPlaying()) {
snd_wave.Play(); snd_wave.Play();
} }
} }
pr_wave.Do = function () { pr_wave.Do = function () {
// Move around randomly. // Move around randomly.
this.lifeTimer--; this.lifeTimer--;
if (this.lifeTimer <= 0) { if (this.lifeTimer <= 0) {
this.Destroy(); this.Destroy();
} }
} }

View File

@ -1,177 +1,177 @@
function oceanRoom () { function oceanRoom () {
if (Oversimplified.DEBUG.showMessages) console.log("Ran oceanRoom()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran oceanRoom()");
} }
rm_Ocean.waveTimer = Math.round(Math.randomRange(30, 150)); 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_title.Play(); mus_title.Play();
// G.player and G.oceanParticle are created in loadPrefabs.js // G.player and G.oceanParticle are created in loadPrefabs.js
rm_Ocean.GenerateMap(); rm_Ocean.GenerateMap();
console.log("player xBound: " + G.player.xBound); console.log("player xBound: " + G.player.xBound);
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));
// 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);
G.oceanParticle.x = G.player.x + randomSmidge(); G.oceanParticle.x = G.player.x + randomSmidge();
G.oceanParticle.y = G.player.y + randomSmidge(); G.oceanParticle.y = G.player.y + randomSmidge();
// Reset camera whenever room starts // Reset camera whenever room starts
OS.SetCamera({ OS.SetCamera({
x: G.player.x - (OS.camera.width / 2), x: G.player.x - (OS.camera.width / 2),
y: G.player.y - (OS.camera.height / 2), y: G.player.y - (OS.camera.height / 2),
objectToFollow: G.player objectToFollow: G.player,
}); });
this.mapLeftTrigger = OS.camera.hBorder; this.mapLeftTrigger = OS.camera.hBorder;
this.mapLeftTriggerTarget = this.width - (OS.camera.width - OS.camera.hBorder); this.mapLeftTriggerTarget = this.width - (OS.camera.width - OS.camera.hBorder);
this.mapRightTrigger = this.width - OS.camera.hBorder; this.mapRightTrigger = this.width - OS.camera.hBorder;
this.mapRightTriggerTarget = OS.camera.width - OS.camera.hBorder; this.mapRightTriggerTarget = OS.camera.width - OS.camera.hBorder;
this.mapUpTrigger = OS.camera.vBorder; this.mapUpTrigger = OS.camera.vBorder;
this.mapUpTriggerTarget = this.height - (OS.camera.height - OS.camera.vBorder); this.mapUpTriggerTarget = this.height - (OS.camera.height - OS.camera.vBorder);
this.mapDownTrigger = this.height - OS.camera.vBorder; this.mapDownTrigger = this.height - OS.camera.vBorder;
this.mapDownTriggerTarget = OS.camera.height - OS.camera.vBorder; this.mapDownTriggerTarget = OS.camera.height - OS.camera.vBorder;
// G.economy.UpdateEconomy(); // G.economy.UpdateEconomy();
} }
rm_Ocean.Do = function () { rm_Ocean.Do = function () {
if (G.gameStarted) { 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) {
// Move G.oceanParticle around based on player's movement. // 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.oceanParticle.CheckPosition) G.oceanParticle.CheckPosition(G.player.x, G.player.y, G.player.direction);
if (ct_cancel().down) { if (ct_cancel().down) {
snd_select.Play(); snd_select.Play();
guiControl.inventory.activateDelay = 5; guiControl.inventory.activateDelay = 5;
guiControl.inventory.show = true; guiControl.inventory.show = true;
}
if (ct_m.down) {
snd_select.Play();
guiControl.map.activateDelay = 5;
guiControl.map.show = true;
}
}
} }
if (ct_m.down) {
this.RunClock(); snd_select.Play();
} guiControl.map.activateDelay = 5;
// Make waves even if the game hasn't started, but not when on trade screen. guiControl.map.show = true;
if (guiControl && guiControl.trade) { // Force it to wait until loaded.
if (!guiControl.trade.show) {
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.RunClock();
}
// Make waves even if the game hasn't started, but not when on trade screen.
if (guiControl && guiControl.trade) { // Force it to wait until loaded.
if (!guiControl.trade.show) {
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));
}
}
}
} }
rm_Ocean.DrawAbove = function () { rm_Ocean.DrawAbove = function () {
if (G.gameStarted) { if (G.gameStarted) {
this.DrawNightDarkness(); this.DrawNightDarkness();
guiControl.drawSpeedGauge(); guiControl.drawSpeedGauge();
guiControl.drawEnergyBar(); guiControl.drawEnergyBar();
guiControl.drawClock(); guiControl.drawClock();
guiControl.inventory.Draw(); guiControl.inventory.Draw();
guiControl.map.Draw(); guiControl.map.Draw();
guiControl.trade.Draw(); guiControl.trade.Draw();
} else { } else {
guiControl.title.Draw(); guiControl.title.Draw();
} }
} }
rm_Ocean.DoLast = function () { rm_Ocean.DoLast = function () {
// Clear Objects on room exit. This is best practice unless you need persistent objects. // Clear Objects on room exit. This is best practice unless you need persistent objects.
//rm_Ocean.objects = {}; //rm_Ocean.objects = {};
} }
rm_Ocean.RunClock = function () { rm_Ocean.RunClock = function () {
if (guiControl.trade && !guiControl.trade.show) { // Only advance time when not trading. if (guiControl.trade && !guiControl.trade.show) { // Only advance time when not trading.
rm_Ocean.clockTimerCount++; rm_Ocean.clockTimerCount++;
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.
G.economy.UpdateEconomy(); G.economy.UpdateEconomy();
for (var i = 0; i < G.map.length; i++) { for (var i = 0; i < G.map.length; i++) {
G.map[i].island.NewDay(); G.map[i].island.NewDay();
} }
G.SaveGame(); G.SaveGame();
}
if (rm_Ocean.clockTimerCount == 0 ||
rm_Ocean.clockTimerCount == Math.round(rm_Ocean.clockTimerCutoff * 0.33) ||
rm_Ocean.clockTimerCount == Math.round(rm_Ocean.clockTimerCutoff * 0.66)) {
G.player.CheckIllnessIncrease();
}
} }
if (rm_Ocean.clockTimerCount == 0 ||
rm_Ocean.clockTimerCount == Math.round(rm_Ocean.clockTimerCutoff * 0.33) ||
rm_Ocean.clockTimerCount == Math.round(rm_Ocean.clockTimerCutoff * 0.66)) {
G.player.CheckIllnessIncrease();
}
}
} }
rm_Ocean.DrawNightDarkness = function () { rm_Ocean.DrawNightDarkness = function () {
var alphaFormula = (Math.sin((((this.clockTimerCount / (this.clockTimerCutoff * Math.PI)) * 10) * 1.5) - 2) - 0.4); var alphaFormula = (Math.sin((((this.clockTimerCount / (this.clockTimerCutoff * Math.PI)) * 10) * 1.5) - 2) - 0.4);
if (alphaFormula < 0) alphaFormula = 0; if (alphaFormula < 0) alphaFormula = 0;
if (alphaFormula > 0) { if (alphaFormula > 0) {
var saveGlobalAlpha = OS.context.globalAlpha; var saveGlobalAlpha = OS.context.globalAlpha;
var tmp = Oversimplified.context.fillStyle; var tmp = Oversimplified.context.fillStyle;
OS.context.globalAlpha = alphaFormula; OS.context.globalAlpha = alphaFormula;
Oversimplified.context.fillStyle = "#112189"; Oversimplified.context.fillStyle = "#112189";
Oversimplified.context.fillRect(0, 0, Oversimplified.camera.width, Oversimplified.camera.height); Oversimplified.context.fillRect(0, 0, Oversimplified.camera.width, Oversimplified.camera.height);
Oversimplified.context.fillStyle = tmp; Oversimplified.context.fillStyle = tmp;
Oversimplified.context.globalAlpha = saveGlobalAlpha; Oversimplified.context.globalAlpha = saveGlobalAlpha;
} }
} }
rm_Ocean.GenerateMap = function () { rm_Ocean.GenerateMap = function () {
var xSquares = [25]; var xSquares = [25];
var ySquares = [22]; var ySquares = [22];
while (xSquares.length < this.numberOfIslands) { while (xSquares.length < this.numberOfIslands) {
var randomNumber = Math.round(Math.randomRange(2, this.squaresX - 2)); var randomNumber = Math.round(Math.randomRange(2, this.squaresX - 2));
var found = false; var found = false;
for (var i = 0; i < xSquares.length; i++) { for (var i = 0; i < xSquares.length; i++) {
if (xSquares[i] - ((this.squaresX / this.numberOfIslands) / 2) < randomNumber && randomNumber < xSquares[i] + ((this.squaresX / this.numberOfIslands) / 2)) { if (xSquares[i] - ((this.squaresX / this.numberOfIslands) / 2) < randomNumber && randomNumber < xSquares[i] + ((this.squaresX / this.numberOfIslands) / 2)) {
found = true; found = true;
break; break;
} }
} }
if (!found) xSquares.push(randomNumber); if (!found) xSquares.push(randomNumber);
} }
while (ySquares.length < this.numberOfIslands) { while (ySquares.length < this.numberOfIslands) {
var randomNumber = Math.round(Math.randomRange(2, this.squaresY - 2)); var randomNumber = Math.round(Math.randomRange(2, this.squaresY - 2));
var found = false; var found = false;
for (var i = 0; i < ySquares.length; i++) { for (var i = 0; i < ySquares.length; i++) {
if (ySquares[i] - ((this.squaresY / this.numberOfIslands) / 2) < randomNumber && randomNumber < ySquares[i] + ((this.squaresY / this.numberOfIslands) / 2)) { if (ySquares[i] - ((this.squaresY / this.numberOfIslands) / 2) < randomNumber && randomNumber < ySquares[i] + ((this.squaresY / this.numberOfIslands) / 2)) {
found = true; found = true;
break; break;
} }
} }
if (!found) ySquares.push(randomNumber); if (!found) ySquares.push(randomNumber);
} }
for (var i = 0; i < this.numberOfIslands; i++) { for (var i = 0; i < this.numberOfIslands; i++) {
G.map[i] = { G.map[i] = {
island: rm_Ocean.AddObject(OS.P["Island"], { island: rm_Ocean.AddObject(OS.P["Island"], {
x: this.squareSize * xSquares[i], x: this.squareSize * xSquares[i],
y: this.squareSize * ySquares[i] y: this.squareSize * ySquares[i]
}), }),
drawX: xSquares[i], drawX: xSquares[i],
drawY: ySquares[i], drawY: ySquares[i],
drawWidth: 1, drawWidth: 1,
drawHeight: 1 drawHeight: 1,
}; };
} }
} }

View File

@ -3,36 +3,36 @@ OS.S.numberOfScriptsToLoad = 16;
OS.S.pixelScale = 4; OS.S.pixelScale = 4;
// Oversimplified.DEBUG.showMessages = false; // Oversimplified.DEBUG.showMessages = false;
OS.SetCamera({ OS.SetCamera({
width: pixel(160), // 640 width: pixel(160), // 640
height: pixel(120), // 480 height: pixel(120), // 480
hBorder: pixel(64), hBorder: pixel(64),
vBorder: pixel(48)}); vBorder: pixel(48),
});
function start() function start() {
{ OS.AddScript("loadControls.js");
OS.AddScript("loadControls.js"); OS.AddScript("loadAudio.js");
OS.AddScript("loadAudio.js"); OS.AddScript("loadGameManager.js");
OS.AddScript("loadGameManager.js"); OS.AddScript("loadGUIs.js");
OS.AddScript("loadGUIs.js"); OS.AddScript("loadPrefabs.js");
OS.AddScript("loadPrefabs.js"); OS.AddScript("loadRooms.js");
OS.AddScript("loadRooms.js");
if (Oversimplified.DEBUG.showMessages) console.log("Ran start()"); if (Oversimplified.DEBUG.showMessages) console.log("Ran start()");
} }
function pixel(number) { function pixel(number) {
return ((typeof number !== 'undefined') ? number : 1) * OS.S.pixelScale; return ((typeof number !== 'undefined') ? number : 1) * OS.S.pixelScale;
} }
function secondsWorthOfFrames(seconds) { function secondsWorthOfFrames(seconds) {
return seconds * (1 / OS.R[OS.R.currentRoom].stepSpeed); return seconds * (1 / OS.R[OS.R.currentRoom].stepSpeed);
} }
function randomSmidge() { function randomSmidge() {
// Return a random amount between -10 and 10 on the pixel scale. // Return a random amount between -10 and 10 on the pixel scale.
return (pixel(Math.round(Math.randomRange(-10, 10)))); return (pixel(Math.round(Math.randomRange(-10, 10))));
} }
function sortNumber(a, b) { function sortNumber(a, b) {
return a - b; return a - b;
} }

View File

@ -28,13 +28,12 @@ time, mark, audio, video {
body { body {
padding:10px 50px 0 0; padding:10px 50px 0 0;
font-family:"Helvetica Neue", Helvetica, Arial, sans-serif; font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px; font-size: 14px;
color: #232323; color: #232323;
background-color: #FBFAF7; background-color: #FBFAF7;
margin: 0; margin: 0;
line-height: 1.8em; line-height: 1.8em;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
} }
h1, h2, h3, h4, h5, h6 { h1, h2, h3, h4, h5, h6 {
@ -47,32 +46,32 @@ p, ul, ol, table, dl {
} }
h1, h2, h3 { h1, h2, h3 {
font-family: Arvo, Monaco, serif; font-family: Arvo, Monaco, serif;
line-height:1.3; line-height:1.3;
font-weight: normal; font-weight: normal;
} }
h1,h2, h3 { h1,h2, h3 {
display: block; display: block;
border-bottom: 1px solid #ccc; border-bottom: 1px solid #ccc;
padding-bottom: 5px; padding-bottom: 5px;
} }
h1 { h1 {
font-size: 30px; font-size: 30px;
} }
h2 { h2 {
font-size: 24px; font-size: 24px;
} }
h3 { h3 {
font-size: 18px; font-size: 18px;
} }
h4, h5, h6 { h4, h5, h6 {
font-family: Arvo, Monaco, serif; font-family: Arvo, Monaco, serif;
font-weight: 700; font-weight: 700;
} }
a { a {
@ -82,15 +81,15 @@ a {
} }
a:hover { a:hover {
text-decoration: underline; text-decoration: underline;
} }
a small { a small {
font-size: 12px; font-size: 12px;
} }
em { em {
font-style: italic; font-style: italic;
} }
strong { strong {
@ -116,7 +115,7 @@ blockquote {
} }
dl, dt, dd, dl p { dl, dt, dd, dl p {
font-color: #444; font-color: #444;
} }
dl dt { dl dt {
@ -163,19 +162,19 @@ p img {
/* Code blocks */ /* Code blocks */
code, pre { code, pre {
font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace; font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
color:#000; color:#000;
font-size:14px; font-size:14px;
} }
pre { pre {
padding: 4px 12px; padding: 4px 12px;
background: #FDFEFB; background: #FDFEFB;
border-radius:4px; border-radius:4px;
border:1px solid #D7D8C8; border:1px solid #D7D8C8;
overflow: auto; overflow: auto;
overflow-y: hidden; overflow-y: hidden;
margin-bottom: 32px; margin-bottom: 32px;
} }
@ -193,8 +192,8 @@ table {
th { th {
font-family: 'Arvo', Helvetica, Arial, sans-serif; font-family: 'Arvo', Helvetica, Arial, sans-serif;
font-size: 18px; font-size: 18px;
font-weight: normal; font-weight: normal;
padding: 10px; padding: 10px;
background: #232323; background: #232323;
color: #FDFEFB; color: #FDFEFB;
@ -202,7 +201,7 @@ th {
td { td {
padding: 10px; padding: 10px;
background: #ccc; background: #ccc;
} }
@ -215,47 +214,47 @@ td {
/* Header */ /* Header */
header { header {
background-color: #171717; background-color: #171717;
color: #FDFDFB; color: #FDFDFB;
width:170px; width:170px;
float:left; float:left;
position:fixed; position:fixed;
border: 1px solid #000; border: 1px solid #000;
-webkit-border-top-right-radius: 4px; -webkit-border-top-right-radius: 4px;
-webkit-border-bottom-right-radius: 4px; -webkit-border-bottom-right-radius: 4px;
-moz-border-radius-topright: 4px; -moz-border-radius-topright: 4px;
-moz-border-radius-bottomright: 4px; -moz-border-radius-bottomright: 4px;
border-top-right-radius: 4px; border-top-right-radius: 4px;
border-bottom-right-radius: 4px; border-bottom-right-radius: 4px;
padding: 34px 25px 22px 50px; padding: 34px 25px 22px 50px;
margin: 30px 25px 0 0; margin: 30px 25px 0 0;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
} }
p.header { p.header {
font-size: 16px; font-size: 16px;
} }
h1.header { h1.header {
font-family: Arvo, sans-serif; font-family: Arvo, sans-serif;
font-size: 30px; font-size: 30px;
font-weight: 300; font-weight: 300;
line-height: 1.3em; line-height: 1.3em;
border-bottom: none; border-bottom: none;
margin-top: 0; margin-top: 0;
} }
h1.header, a.header, a.name, header a{ h1.header, a.header, a.name, header a{
color: #fff; color: #fff;
} }
a.header { a.header {
text-decoration: underline; text-decoration: underline;
} }
a.name { a.name {
white-space: nowrap; white-space: nowrap;
} }
header ul { header ul {
@ -264,32 +263,32 @@ header ul {
} }
header li { header li {
list-style-type: none; list-style-type: none;
width:132px; width:132px;
height:15px; height:15px;
margin-bottom: 12px; margin-bottom: 12px;
line-height: 1em; line-height: 1em;
padding: 6px 6px 6px 7px; padding: 6px 6px 6px 7px;
background: #AF0011; background: #AF0011;
background: -moz-linear-gradient(top, #AF0011 0%, #820011 100%); background: -moz-linear-gradient(top, #AF0011 0%, #820011 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f8f8f8), color-stop(100%,#dddddd)); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f8f8f8), color-stop(100%,#dddddd));
background: -webkit-linear-gradient(top, #AF0011 0%,#820011 100%); background: -webkit-linear-gradient(top, #AF0011 0%,#820011 100%);
background: -o-linear-gradient(top, #AF0011 0%,#820011 100%); background: -o-linear-gradient(top, #AF0011 0%,#820011 100%);
background: -ms-linear-gradient(top, #AF0011 0%,#820011 100%); background: -ms-linear-gradient(top, #AF0011 0%,#820011 100%);
background: linear-gradient(top, #AF0011 0%,#820011 100%); background: linear-gradient(top, #AF0011 0%,#820011 100%);
border-radius:4px; border-radius:4px;
border:1px solid #0D0D0D; border:1px solid #0D0D0D;
-webkit-box-shadow: inset 0px 1px 1px 0 rgba(233,2,38, 1); -webkit-box-shadow: inset 0px 1px 1px 0 rgba(233,2,38, 1);
box-shadow: inset 0px 1px 1px 0 rgba(233,2,38, 1); box-shadow: inset 0px 1px 1px 0 rgba(233,2,38, 1);
} }
header li:hover { header li:hover {
background: #C3001D; background: #C3001D;
background: -moz-linear-gradient(top, #C3001D 0%, #950119 100%); background: -moz-linear-gradient(top, #C3001D 0%, #950119 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f8f8f8), color-stop(100%,#dddddd)); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f8f8f8), color-stop(100%,#dddddd));
background: -webkit-linear-gradient(top, #C3001D 0%,#950119 100%); background: -webkit-linear-gradient(top, #C3001D 0%,#950119 100%);
background: -o-linear-gradient(top, #C3001D 0%,#950119 100%); background: -o-linear-gradient(top, #C3001D 0%,#950119 100%);
@ -298,21 +297,21 @@ header li:hover {
} }
a.buttons { a.buttons {
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
background: url(../images/arrow-down.png) no-repeat; background: url(../images/arrow-down.png) no-repeat;
font-weight: normal; font-weight: normal;
text-shadow: rgba(0, 0, 0, 0.4) 0 -1px 0; text-shadow: rgba(0, 0, 0, 0.4) 0 -1px 0;
padding: 2px 2px 2px 22px; padding: 2px 2px 2px 22px;
height: 30px; height: 30px;
} }
a.github { a.github {
background: url(../images/octocat-small.png) no-repeat 1px; background: url(../images/octocat-small.png) no-repeat 1px;
} }
a.buttons:hover { a.buttons:hover {
color: #fff; color: #fff;
text-decoration: none; text-decoration: none;
} }
@ -332,7 +331,7 @@ footer {
float:left; float:left;
position:fixed; position:fixed;
bottom:10px; bottom:10px;
padding-left: 50px; padding-left: 50px;
} }
@media print, screen and (max-width: 960px) { @media print, screen and (max-width: 960px) {
@ -348,11 +347,11 @@ footer {
width:auto; width:auto;
} }
footer { footer {
border-top: 1px solid #ccc; border-top: 1px solid #ccc;
margin:0 84px 0 50px; margin:0 84px 0 50px;
padding:0; padding:0;
} }
header { header {
padding-right:320px; padding-right:320px;
@ -381,17 +380,17 @@ footer {
header { header {
padding:10px 20px 0; padding:10px 20px 0;
margin-right: 0; margin-right: 0;
} }
section { section {
padding:10px 0 10px 20px; padding:10px 0 10px 20px;
margin:0 0 30px; margin:0 0 30px;
} }
footer { footer {
margin: 0 0 0 30px; margin: 0 0 0 30px;
} }
header ul, header p.view { header ul, header p.view {
position:static; position:static;
@ -404,13 +403,13 @@ footer {
display:none; display:none;
} }
footer { footer {
margin: 0 0 0 20px; margin: 0 0 0 20px;
} }
footer a{ footer a{
display:block; display:block;
} }
} }