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

View File

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

View File

@ -3,111 +3,114 @@ function titleScreen () {
}
guiControl.title = {
screen: "main",
show: true,
cursorPosition: 0,
activateDelay: 0,
screen: "main",
show: true,
cursorPosition: 0,
activateDelay: 0,
padding: pixel(2),
leftBorder: pixel(12),
padding: pixel(2),
leftBorder: pixel(12),
rowTop: function (rowNumber) {
return pixel(32) + pixel(2) + pixel((guiControl.iconSize + 2) * rowNumber);
}
rowTop: function (rowNumber) {
return pixel(32) + pixel(2) + pixel((guiControl.iconSize + 2) * rowNumber);
},
}
guiControl.title.Draw = function () {
if (guiControl.title && guiControl.title.show) {
guiControl.title.activateDelay -= (guiControl.title.activateDelay > 0) ? 1 : 0;
if (guiControl.title && guiControl.title.show) {
guiControl.title.activateDelay -= (guiControl.title.activateDelay > 0) ? 1 : 0;
if (guiControl.title.screen == "main") {
if (ct_down().down) {
snd_cursordown.Play();
guiControl.title.cursorPosition++;
if (guiControl.title.screen == "main") {
if (ct_down().down) {
snd_cursordown.Play();
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) {
snd_cursordown.Play();
guiControl.title.cursorPosition--;
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;
}
// 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;
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();
}
}
}
// 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;
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";
}
}
guiControl.title.cursorPosition = 0;
// console.log(guiControl.title.screen);
}
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";
}
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) {
guiControl.title.screen = "main";
}
}
}
}

View File

@ -1,448 +1,461 @@
function tradeGUI() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran tradeGUI()");
if (Oversimplified.DEBUG.showMessages) console.log("Ran tradeGUI()");
}
guiControl.trade = {
screen: "main", // "main", "buy", "sell", "gossip"
cursorPosition: 0,
page: 0, // horizontal page on item lists. Base 1 to match number of pages var "pages" within the gui.
itemsPerPage: 3,
show: false,
activateDelay: 0,
screen: "main", // "main", "buy", "sell", "gossip"
cursorPosition: 0,
page: 0, // horizontal page on item lists. Base 1 to match number of pages var "pages" within the gui.
itemsPerPage: 3,
show: false,
activateDelay: 0,
island: null,
island: null,
padding: pixel(2),
leftBorder: pixel(12),
padding: pixel(2),
leftBorder: pixel(12),
rowTop: function (rowNumber) {
return (guiControl.trade.padding + pixel(6) + (guiControl.trade.padding * 3)) + pixel((guiControl.iconSize + 3) * rowNumber);
}
rowTop: function (rowNumber) {
return (guiControl.trade.padding + pixel(6) + (guiControl.trade.padding * 3)) + pixel((guiControl.iconSize + 3) * rowNumber);
},
}
guiControl.trade.Draw = function () {
if (guiControl.trade && guiControl.trade.show) {
guiControl.trade.activateDelay -= (guiControl.trade.activateDelay > 0) ? 1 : 0;
// console.log("trade screen island: " + guiControl.trade.island.name);
// Draw background color.
var tmp = Oversimplified.context.fillStyle;
Oversimplified.context.fillStyle = "#D9BEA5";
Oversimplified.context.fillRect(0, 0, Oversimplified.camera.width, Oversimplified.camera.height);
Oversimplified.context.fillStyle = tmp;
if (guiControl.trade && guiControl.trade.show) {
guiControl.trade.activateDelay -= (guiControl.trade.activateDelay > 0) ? 1 : 0;
// console.log("trade screen island: " + guiControl.trade.island.name);
// Draw background color.
var tmp = Oversimplified.context.fillStyle;
Oversimplified.context.fillStyle = "#D9BEA5";
Oversimplified.context.fillRect(0, 0, Oversimplified.camera.width, Oversimplified.camera.height);
Oversimplified.context.fillStyle = tmp;
if (ct_down().down) {
snd_cursordown.Play();
guiControl.trade.cursorPosition++;
}
if (ct_up().down) {
snd_cursordown.Play();
guiControl.trade.cursorPosition--;
}
if (ct_right().down) {
snd_cursordown.Play();
guiControl.trade.page++;
}
if (ct_left().down) {
snd_cursordown.Play();
guiControl.trade.page--;
}
if (guiControl.trade.screen == "main") {
// console.log(guiControl.trade.screen);
// Limit Cursor
if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 3;
}
if (guiControl.trade.cursorPosition > 3) {
guiControl.trade.cursorPosition = 0;
}
// Limit page
if (guiControl.trade.page < 0) {
guiControl.trade.page = 0;
}
if (guiControl.trade.page > 0) {
guiControl.trade.page = 0;
}
if (ct_down().down) {
snd_cursordown.Play();
guiControl.trade.cursorPosition++;
}
if (ct_up().down) {
snd_cursordown.Play();
guiControl.trade.cursorPosition--;
}
if (ct_right().down) {
snd_cursordown.Play();
guiControl.trade.page++;
}
if (ct_left().down) {
snd_cursordown.Play();
guiControl.trade.page--;
}
if (guiControl.trade.screen == "main") {
// console.log(guiControl.trade.screen);
// Limit Cursor
if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 3;
}
if (guiControl.trade.cursorPosition > 3) {
guiControl.trade.cursorPosition = 0;
}
// Limit page
if (guiControl.trade.page < 0) {
guiControl.trade.page = 0;
}
if (guiControl.trade.page > 0) {
guiControl.trade.page = 0;
}
// Title
guiControl.drawPixelText("On Island", (guiControl.trade.padding * 2), guiControl.trade.padding, 10, "black", 6);
// Money icon
// 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);
// Supplies icon
// 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);
// Cargo icon
// 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);
// Close Text
guiControl.drawPixelText("Leave", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) + pixel(), 8, "black", 6);
// Draw cursor
guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition));
// Title
guiControl.drawPixelText("On Island", (guiControl.trade.padding * 2), guiControl.trade.padding, 10, "black", 6);
// Money icon
// 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);
// Supplies icon
// 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);
// Cargo icon
// 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);
// Close Text
guiControl.drawPixelText("Leave", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) + pixel(), 8, "black", 6);
// Draw cursor
guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition));
// Button Action
if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) {
case 0:
if (guiControl.trade.island.CheckInventory().length > 0) {
snd_select.Play();
guiControl.trade.screen = "buy";
guiControl.trade.activateDelay = 5;
}
else {
snd_cannotbuy.Play();
}
// Button Action
if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) {
case 0: {
if (guiControl.trade.island.CheckInventory().length > 0) {
snd_select.Play();
guiControl.trade.screen = "buy";
guiControl.trade.activateDelay = 5;
}
else {
snd_cannotbuy.Play();
}
break;
case 1:
if (G.inventory.CheckCargo().length > 0) {
snd_select.Play();
guiControl.trade.screen = "sell";
guiControl.trade.activateDelay = 5;
} else {
snd_cannotbuy.Play();
}
}
case 1: {
if (G.inventory.CheckCargo().length > 0) {
snd_select.Play();
guiControl.trade.screen = "sell";
guiControl.trade.activateDelay = 5;
} else {
snd_cannotbuy.Play();
}
break;
case 2:
snd_select.Play();
guiControl.trade.screen = "tavern";
guiControl.trade.activateDelay = 5;
}
case 2: {
snd_select.Play();
guiControl.trade.screen = "tavern";
guiControl.trade.activateDelay = 5;
break;
default:
snd_cursorup.Play();
mus_trade.Stop();
mus_sail.Play();
guiControl.trade.show = false;
}
default: {
snd_cursorup.Play();
mus_trade.Stop();
mus_sail.Play();
guiControl.trade.show = false;
break;
}
}
}
// snd_select.Play();
guiControl.trade.cursorPosition = 0;
guiControl.trade.page = 0;
// console.log(guiControl.trade.screen);
}
if (ct_cancel().down) {
snd_cursorup.Play();
mus_trade.Stop();
mus_sail.Play();
guiControl.trade.show = false;
}
}
}
else if (guiControl.trade.screen == "buy") {
// console.log(guiControl.trade.screen);
// Limit Cursor
if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 2;
}
if (guiControl.trade.cursorPosition > 2) {
guiControl.trade.cursorPosition = 0;
}
// snd_select.Play();
guiControl.trade.cursorPosition = 0;
guiControl.trade.page = 0;
// console.log(guiControl.trade.screen);
}
if (ct_cancel().down) {
snd_cursorup.Play();
mus_trade.Stop();
mus_sail.Play();
guiControl.trade.show = false;
}
}
}
else if (guiControl.trade.screen == "buy") {
// console.log(guiControl.trade.screen);
// Limit Cursor
if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 2;
}
if (guiControl.trade.cursorPosition > 2) {
guiControl.trade.cursorPosition = 0;
}
// Title
guiControl.drawPixelText("Buy", guiControl.trade.leftBorder - pixel(2), guiControl.topOfBackground, 10, "black", 6);
// Title
guiControl.drawPixelText("Buy", guiControl.trade.leftBorder - pixel(2), guiControl.topOfBackground, 10, "black", 6);
// Money icon
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);
// Cargo icons
var items = guiControl.trade.island.CheckInventory(); // Contains the item ids that have more than 1 item
// Money icon
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);
// Cargo icons
var items = guiControl.trade.island.CheckInventory(); // Contains the item ids that have more than 1 item
// Limit page
if (guiControl.trade.page < 0) {
guiControl.trade.page = items.length - 1;
}
if (guiControl.trade.page > items.length - 1) {
guiControl.trade.page = 0;
}
// Limit page
if (guiControl.trade.page < 0) {
guiControl.trade.page = items.length - 1;
}
if (guiControl.trade.page > items.length - 1) {
guiControl.trade.page = 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;
if (itemPrice < 1) itemPrice = 1;
var itemPriceDisplay = itemPrice.toString() + " c";
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);
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;
if (itemPrice < 1) itemPrice = 1;
var itemPriceDisplay = itemPrice.toString() + " c";
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);
if (items.length > 1) {
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));
}
if (items.length > 1) {
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));
}
// 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("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 {
guiControl.drawPixelText("Sold Out!", guiControl.trade.leftBorder, guiControl.trade.rowTop(1) - pixel(5) + pixel(), 10, "black", 6);
}
// Draw Amount of Cargo
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);
// 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("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 {
guiControl.drawPixelText("Sold Out!", guiControl.trade.leftBorder, guiControl.trade.rowTop(1) - pixel(5) + pixel(), 10, "black", 6);
}
// Draw Amount of Cargo
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);
// 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((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);
// 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((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
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
// Draw cursor
guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(3));
// Back Text
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
// Draw cursor
guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(3));
// Button Action
if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) {
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
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();
guiControl.trade.island.haggleAmount = G.stats.haggling;
} else {
snd_cannotbuy.Play();
guiControl.trade.island.timesHaggledToday++;
}
// Button Action
if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) {
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
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();
guiControl.trade.island.haggleAmount = G.stats.haggling;
} else {
snd_cannotbuy.Play();
guiControl.trade.island.timesHaggledToday++;
}
break;
case 1: // Buy
if (items.length > 0 &&
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);
} else {
snd_cannotbuy.Play();
}
}
case 1: { // Buy
if (items.length > 0 &&
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);
} else {
snd_cannotbuy.Play();
}
break;
default:
snd_cursorup.Play();
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 0; // The position where "Buy" is on main screen.
}
default: {
snd_cursorup.Play();
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 0; // The position where "Buy" is on main screen.
break;
}
// console.log(guiControl.trade.screen);
}
if (ct_cancel().down) {
snd_cursorup.Play();
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
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);
// Limit Cursor
if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 2;
}
if (guiControl.trade.cursorPosition > 2) {
guiControl.trade.cursorPosition = 0;
}
}
}
// console.log(guiControl.trade.screen);
}
if (ct_cancel().down) {
snd_cursorup.Play();
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
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);
// Limit Cursor
if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 2;
}
if (guiControl.trade.cursorPosition > 2) {
guiControl.trade.cursorPosition = 0;
}
// Title
guiControl.drawPixelText("Sell", guiControl.trade.leftBorder - pixel(2), guiControl.topOfBackground, 10, "black", 6);
// Title
guiControl.drawPixelText("Sell", guiControl.trade.leftBorder - pixel(2), guiControl.topOfBackground, 10, "black", 6);
// Money icon
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);
// Cargo icons
var items = G.inventory.CheckCargo(); // Contains the item ids that have more than 1 item
// Money icon
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);
// Cargo icons
var items = G.inventory.CheckCargo(); // Contains the item ids that have more than 1 item
// Limit page
if (guiControl.trade.page < 0) {
guiControl.trade.page = items.length - 1;
}
if (guiControl.trade.page > items.length - 1) {
guiControl.trade.page = 0;
}
// Limit page
if (guiControl.trade.page < 0) {
guiControl.trade.page = items.length - 1;
}
if (guiControl.trade.page > items.length - 1) {
guiControl.trade.page = 0;
}
if (items.length > 0) {
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.
itemPrice = Math.round(itemPrice * priceCut);
if (itemPrice < 1) itemPrice = 1;
var itemPriceDisplay = itemPrice.toString() + " c";
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);
if (items.length > 0) {
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.
itemPrice = Math.round(itemPrice * priceCut);
if (itemPrice < 1) itemPrice = 1;
var itemPriceDisplay = itemPrice.toString() + " c";
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);
if (items.length > 1) {
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));
}
if (items.length > 1) {
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));
}
// 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("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 {
guiControl.drawPixelText("No Cargo!", guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel(5) + pixel(), 10, "black", 6);
}
// 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("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 {
guiControl.drawPixelText("No Cargo!", guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel(5) + pixel(), 10, "black", 6);
}
// Draw Amount of Cargo
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);
// Draw Amount of Cargo
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);
// 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((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);
// 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((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
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
// Draw cursor
guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(3));
// Back Text
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
// Draw cursor
guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(3));
// Button Action
if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) {
case 0: // Haggle
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.
{
snd_sell.Play();
guiControl.trade.island.haggleAmount = G.stats.haggling;
} else {
snd_cannotbuy.Play();
guiControl.trade.island.timesHaggledToday++;
}
// Button Action
if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) {
case 0: { // Haggle
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.
{
snd_sell.Play();
guiControl.trade.island.haggleAmount = G.stats.haggling;
} else {
snd_cannotbuy.Play();
guiControl.trade.island.timesHaggledToday++;
}
break;
case 1: // Sell
if (items.length > 0 &&
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);
} else {
snd_cannotbuy.Play();
}
}
case 1: { // Sell
if (items.length > 0 &&
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);
} else {
snd_cannotbuy.Play();
}
break;
default:
snd_cursorup.Play();
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 1; // The position where "Sell" is on main screen.
}
default: {
snd_cursorup.Play();
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 1; // The position where "Sell" is on main screen.
break;
}
// console.log(guiControl.trade.screen);
}
if (ct_cancel().down) {
snd_cursorup.Play();
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
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
if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 2;
}
if (guiControl.trade.cursorPosition > 2) {
guiControl.trade.cursorPosition = 0;
}
}
}
// console.log(guiControl.trade.screen);
}
if (ct_cancel().down) {
snd_cursorup.Play();
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
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
if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 2;
}
if (guiControl.trade.cursorPosition > 2) {
guiControl.trade.cursorPosition = 0;
}
// Title
guiControl.drawPixelText("Tavern", guiControl.leftBorder - pixel(6), guiControl.topOfBackground, 8, "black", 6);
// Title
guiControl.drawPixelText("Tavern", guiControl.leftBorder - pixel(6), guiControl.topOfBackground, 8, "black", 6);
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);
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);
// Money icon
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);
// Options
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);
// Illness icon
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);
// Back Text
guiControl.drawPixelText("Back", guiControl.leftBorder, guiControl.trade.rowTop(4) - pixel(), 8, "black", 6);
// Draw cursor
guiControl.drawCursor(guiControl.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(2));
// Money icon
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);
// Options
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);
// Illness icon
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);
// Back Text
guiControl.drawPixelText("Back", guiControl.leftBorder, guiControl.trade.rowTop(4) - pixel(), 8, "black", 6);
// Draw cursor
guiControl.drawCursor(guiControl.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(2));
// Button Action
if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) {
case 0:
snd_select.Play();
guiControl.trade.screen = "gossip";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 2; // The position where "Supplies" is on main screen.
// Button Action
if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) {
case 0: {
snd_select.Play();
guiControl.trade.screen = "gossip";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 2; // The position where "Supplies" is on main screen.
break;
case 1:
if (G.stats.illness > 0 && G.inventory.money > innPrice) { //If cursor is over yes, heal illness with supplies.
snd_heal.Play();
guiControl.trade.island.StayAtInn();
} else {
snd_cannotbuy.Play();
}
}
case 1: {
if (G.stats.illness > 0 && G.inventory.money > innPrice) { //If cursor is over yes, heal illness with supplies.
snd_heal.Play();
guiControl.trade.island.StayAtInn();
} else {
snd_cannotbuy.Play();
}
break;
default:
snd_cursorup.Play();
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 2; // The position where "Supplies" is on main screen.
}
default: {
snd_cursorup.Play();
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 2; // The position where "Supplies" is on main screen.
break;
}
}
}
// Give a cooldown so you don't accidentally do something you don't want.
guiControl.trade.activateDelay = 5;
}
// Give a cooldown so you don't accidentally do something you don't want.
guiControl.trade.activateDelay = 5;
}
if (ct_cancel().down) {
snd_cursorup.Play();
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 2; // The position where "Supplies" is on main screen.
}
}
}
else if (guiControl.trade.screen == "gossip") {
// console.log(guiControl.trade.screen);
// Limit Cursor
if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 0;
}
if (guiControl.trade.cursorPosition > 0) {
guiControl.trade.cursorPosition = 0;
}
if (ct_cancel().down) {
snd_cursorup.Play();
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 2; // The position where "Supplies" is on main screen.
}
}
}
else if (guiControl.trade.screen == "gossip") {
// console.log(guiControl.trade.screen);
// Limit Cursor
if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 0;
}
if (guiControl.trade.cursorPosition > 0) {
guiControl.trade.cursorPosition = 0;
}
// Title
guiControl.drawPixelText("Gossip", guiControl.trade.padding, guiControl.topOfBackground, 10, "black", 6);
// Title
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);
// Back Text
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
// Draw cursor
guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(4) - pixel(3));
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
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
// Draw cursor
guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(4) - pixel(3));
// Button Action
if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down || ct_cancel().down) {
snd_cursorup.Play();
guiControl.trade.screen = "tavern";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 0;
}
}
}
}
// Button Action
if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down || ct_cancel().down) {
snd_cursorup.Play();
guiControl.trade.screen = "tavern";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 0;
}
}
}
}
}

View File

@ -15,38 +15,41 @@
<![endif]-->
</head>
<body>
<div class="wrapper">
<header>
<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>
<div class="wrapper">
<header>
<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>
<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/tarball/master">Download TAR</a></li>
<li><a class="buttons github" href="https://github.com/AlamantusGameDev/Trade-Winds">View On GitHub</a></li>
</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/tarball/master">Download TAR</a></li>
<li><a class="buttons github" href="https://github.com/AlamantusGameDev/Trade-Winds">View On GitHub</a></li>
</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>
<section>
<h2>Play</h2>
<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">
Your browser is really old, dude - no canvas support! Update this thing!
</canvas>
<div id="audio"></div>
</section>
<section>
<h2>
<a id="about" class="anchor" href="#about" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>About</h2>
</header>
<section>
<h2>Play</h2>
<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">
Your browser is really old, dude - no canvas support! Update this thing!
</canvas>
<div id="audio"></div>
</section>
<section>
<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>
<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>
<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>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>
<footer>
<p><small>Hosted on <a href="https://pages.github.com">GitHub Pages</a> using the Dinky theme</small></p>
</footer>
</div>
<!--[if !IE]><script>fixScale(document);</script><![endif]-->
</body>
</section>
<footer>
<p><small>Hosted on <a href="https://pages.github.com">GitHub Pages</a> using the Dinky theme</small></p>
</footer>
</div>
<!--[if !IE]><script>fixScale(document);</script><![endif]-->
</body>
</html>

View File

@ -1,20 +1,19 @@
fixScale = function(doc) {
var addEvent = 'addEventListener',
type = 'gesturestart',
qsa = 'querySelectorAll',
scales = [1, 1],
meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
var addEvent = 'addEventListener',
type = 'gesturestart',
qsa = 'querySelectorAll',
scales = [1, 1],
meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
function fix() {
meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
doc.removeEventListener(type, fix, true);
}
if ((meta = meta[meta.length - 1]) && addEvent in doc) {
fix();
scales = [.25, 1.6];
doc[addEvent](type, fix, true);
}
function fix() {
meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
doc.removeEventListener(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"});
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);
function loadControls () {
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadControls()");
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadControls()");
}
function ct_up () {
return {
held : ct_wasd_up.held || ct_arrow_up.held,
down : ct_wasd_up.down || ct_arrow_up.down,
up : ct_wasd_up.up || ct_arrow_up.up
}
return {
held : ct_wasd_up.held || ct_arrow_up.held,
down : ct_wasd_up.down || ct_arrow_up.down,
up : ct_wasd_up.up || ct_arrow_up.up,
}
}
function ct_left () {
return {
held : ct_wasd_left.held || ct_arrow_left.held,
down : ct_wasd_left.down || ct_arrow_left.down,
up : ct_wasd_left.up || ct_arrow_left.up
}
return {
held : ct_wasd_left.held || ct_arrow_left.held,
down : ct_wasd_left.down || ct_arrow_left.down,
up : ct_wasd_left.up || ct_arrow_left.up,
}
}
function ct_down () {
return {
held : ct_wasd_down.held || ct_arrow_down.held,
down : ct_wasd_down.down || ct_arrow_down.down,
up : ct_wasd_down.up || ct_arrow_down.up
}
return {
held : ct_wasd_down.held || ct_arrow_down.held,
down : ct_wasd_down.down || ct_arrow_down.down,
up : ct_wasd_down.up || ct_arrow_down.up,
}
}
function ct_right () {
return {
held : ct_wasd_right.held || ct_arrow_right.held,
down : ct_wasd_right.down || ct_arrow_right.down,
up : ct_wasd_right.up || ct_arrow_right.up
}
return {
held : ct_wasd_right.held || ct_arrow_right.held,
down : ct_wasd_right.down || ct_arrow_right.down,
up : ct_wasd_right.up || ct_arrow_right.up,
}
}
function ct_confirm () {
return {
held : ct_space.held || ct_z.held,
down : ct_space.down || ct_z.down,
up : ct_space.up || ct_z.up
}
return {
held : ct_space.held || ct_z.held,
down : ct_space.down || ct_z.down,
up : ct_space.up || ct_z.up,
}
}
function ct_cancel () {
return {
held : ct_shift.held || ct_x.held,
down : ct_shift.down || ct_x.down,
up : ct_shift.up || ct_x.up
}
return {
held : ct_shift.held || ct_x.held,
down : ct_shift.down || ct_x.down,
up : ct_shift.up || ct_x.up,
}
}

View File

@ -1,79 +1,79 @@
function loadGUIs() {
OS.AddScript("gui/titleScreen.js");
OS.AddScript("gui/inventoryGUI.js");
OS.AddScript("gui/mapGUI.js");
OS.AddScript("gui/tradeGUI.js");
OS.AddScript("gui/titleScreen.js");
OS.AddScript("gui/inventoryGUI.js");
OS.AddScript("gui/mapGUI.js");
OS.AddScript("gui/tradeGUI.js");
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadGUIs()");
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadGUIs()");
}
var guiControl = {
topOfBackground: pixel(2 + 2),
upperBorder: pixel(13 + 2),
lowerBorder: pixel(3 + 2),
leftBorder: pixel(10 + 2),
rightBorder: pixel(5 + 2),
iconSize: 8,
iconScaled: pixel(8),
topOfBackground: pixel(2 + 2),
upperBorder: pixel(13 + 2),
lowerBorder: pixel(3 + 2),
leftBorder: pixel(10 + 2),
rightBorder: pixel(5 + 2),
iconSize: 8,
iconScaled: pixel(8),
drawEnergyBar: function () {
var percentage = G.stats.energy / G.stats.maxEnergy;
var barHeight = pixel(2);
var maxBarWidth = 32;
var barWidth = pixel(Math.round(maxBarWidth * percentage));
drawEnergyBar: function () {
var percentage = G.stats.energy / G.stats.maxEnergy;
var barHeight = pixel(2);
var maxBarWidth = 32;
var barWidth = pixel(Math.round(maxBarWidth * percentage));
var saveFillStyle = OS.context.fillStyle;
OS.context.fillStyle = "#0055FF";
OS.context.fillRect(64, OS.camera.height - barHeight - pixel(4), barWidth, barHeight);
OS.context.fillStyle = saveFillStyle;
},
drawClock: function () {
var screenX = OS.camera.width - pixel(9) - pixel(2);
var screenY = OS.camera.height - pixel(9) - pixel(2);
var percentOfClock = guiControl.clockTimerCount / guiControl.clockTimerCutoff;
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));
},
drawSpeedGauge: function () {
var screenX = pixel(4);
var screenY = OS.camera.height - guiControl.iconScaled - pixel(4);
var sheetX = guiControl.gui_sheet.gauge.x + (G.player.currentSpeed * guiControl.iconScaled);
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);
},
var saveFillStyle = OS.context.fillStyle;
OS.context.fillStyle = "#0055FF";
OS.context.fillRect(64, OS.camera.height - barHeight - pixel(4), barWidth, barHeight);
OS.context.fillStyle = saveFillStyle;
},
drawClock: function () {
var screenX = OS.camera.width - pixel(9) - pixel(2);
var screenY = OS.camera.height - pixel(9) - pixel(2);
var percentOfClock = guiControl.clockTimerCount / guiControl.clockTimerCutoff;
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));
},
drawSpeedGauge: function () {
var screenX = pixel(4);
var screenY = OS.camera.height - guiControl.iconScaled - pixel(4);
var sheetX = guiControl.gui_sheet.gauge.x + (G.player.currentSpeed * guiControl.iconScaled);
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);
},
iconPosition: function (cellPosition) {
return (guiControl.iconScaled * cellPosition);
},
rowTop: function (rowNumber) {
return guiControl.upperBorder + pixel((guiControl.iconSize + 2) * rowNumber);
},
iconPosition: function (cellPosition) {
return (guiControl.iconScaled * cellPosition);
},
rowTop: function (rowNumber) {
return guiControl.upperBorder + pixel((guiControl.iconSize + 2) * rowNumber);
},
drawIcon: function (cellX, cellY, xPosition, yPosition) {
var iconSheetX = guiControl.gui_sheet.icons.x + guiControl.iconPosition(cellX);
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);
},
drawItem: function (itemId, xPosition, yPosition) {
var cellX = itemId % 4;
var cellY = Math.floor(itemId / 4);
var itemSheetX = guiControl.gui_sheet.items.x + guiControl.iconPosition(cellX);
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);
},
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);
},
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);
},
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);
},
drawPageArrow: function (direction, xPosition, yPosition) {
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));
}
drawIcon: function (cellX, cellY, xPosition, yPosition) {
var iconSheetX = guiControl.gui_sheet.icons.x + guiControl.iconPosition(cellX);
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);
},
drawItem: function (itemId, xPosition, yPosition) {
var cellX = itemId % 4;
var cellY = Math.floor(itemId / 4);
var itemSheetX = guiControl.gui_sheet.items.x + guiControl.iconPosition(cellX);
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);
},
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);
},
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);
},
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);
},
drawPageArrow: function (direction, xPosition, yPosition) {
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));
}
}
guiControl.gui_sheet = new Image();
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!
// 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
text = text.toString().toUpperCase();
var letterSizeX = pixel((size == 6) ? size - 1 : size);
var letterSizeY = pixel(size);
var maxWrapWidth = Math.floor(OS.camera.width / (letterSizeX + pixel(1)));
wrapWidth = (wrapWidth <= 0 || wrapWidth > maxWrapWidth) ? maxWrapWidth : wrapWidth;
// var alphabet = guiControl.alphabet_sheet[color + size.toString()];
text = text.toString().toUpperCase();
var letterSizeX = pixel((size == 6) ? size - 1 : size);
var letterSizeY = pixel(size);
var maxWrapWidth = Math.floor(OS.camera.width / (letterSizeX + pixel(1)));
wrapWidth = (wrapWidth <= 0 || wrapWidth > maxWrapWidth) ? maxWrapWidth : wrapWidth;
// var alphabet = guiControl.alphabet_sheet[color + size.toString()];
// Make words wrap nicely, but let punctuation wrap.
var wordsInText = text.split(" ");
if (wordsInText.length > 1) {
var indexToBreak = 0;
var replacementText = "";
var punctuation = [".", ",", "-", "?", "!"];
for (var w = 0; w < wordsInText.length; w++) {
// 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 the last character of a word is punctuation, separate it out
wordsInText.splice(w + 1, 0, 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);
// console.log("Turns to:" + wordsInText[w]);
w--;
} else if (replacementText.substr(indexToBreak).length + wordsInText[w].length + 1 <= wrapWidth) {
// console.log("Adding: \"" + wordsInText[w] + " \" to \"" + replacementText.substr(indexToBreak) + "\"");
// console.log(replacementText.substr(indexToBreak).length + wordsInText[w].length + " < " + wrapWidth);
// console.log("\"" + replacementText.substr(indexToBreak) + "\"");
replacementText += wordsInText[w];
// Make words wrap nicely, but let punctuation wrap.
var wordsInText = text.split(" ");
if (wordsInText.length > 1) {
var indexToBreak = 0;
var replacementText = "";
var punctuation = [".", ",", "-", "?", "!"];
for (var w = 0; w < wordsInText.length; w++) {
// 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 the last character of a word is punctuation, separate it out
wordsInText.splice(w + 1, 0, 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);
// console.log("Turns to:" + wordsInText[w]);
w--;
} else if (replacementText.substr(indexToBreak).length + wordsInText[w].length + 1 <= wrapWidth) {
// console.log("Adding: \"" + wordsInText[w] + " \" to \"" + replacementText.substr(indexToBreak) + "\"");
// console.log(replacementText.substr(indexToBreak).length + wordsInText[w].length + " < " + wrapWidth);
// console.log("\"" + replacementText.substr(indexToBreak) + "\"");
replacementText += wordsInText[w];
if (punctuation.indexOf(wordsInText[w + 1]) == -1) { // If the next word in the array is not punctuation,
replacementText += " "; // Then add a space after.
}
// console.log("Turns to: \"" + replacementText.substr(indexToBreak) + "\"");
} else if (replacementText.substr(indexToBreak).length + wordsInText[w].length <= wrapWidth) {
// console.log("Adding: \"" + wordsInText[w] + "\" to \"" + replacementText.substr(indexToBreak) + "\"");
// console.log(replacementText.substr(indexToBreak).length + wordsInText[w].length + " < " + wrapWidth);
// console.log("\"" + replacementText.substr(indexToBreak) + "\"");
replacementText += wordsInText[w];
// console.log("Turns to: \"" + replacementText.substr(indexToBreak) + "\"");
indexToBreak = replacementText.length;
} else {
// console.log("Checking: \"" + replacementText.substr(indexToBreak) + wordsInText[w] + "\"");
// console.log(replacementText.substr(indexToBreak).length + wordsInText[w].length + " > " + wrapWidth);
// console.log("\"" + replacementText.substr(indexToBreak) + "\"");
// indexToBreak = replacementText.length - 1;
var numberOfSpaces = wrapWidth - replacementText.substr(indexToBreak).length;
for (var s = 0; s < numberOfSpaces; s++) {
replacementText += " ";
}
// console.log("Turns to: \"" + replacementText.substr(indexToBreak) + "\"");
indexToBreak = replacementText.length;
w--;
// replacementText += wordsInText[w];
if (punctuation.indexOf(wordsInText[w + 1]) == -1) { // If the next word in the array is not punctuation,
replacementText += " "; // Then add a space after.
}
// console.log("Turns to: \"" + replacementText.substr(indexToBreak) + "\"");
} else if (replacementText.substr(indexToBreak).length + wordsInText[w].length <= wrapWidth) {
// console.log("Adding: \"" + wordsInText[w] + "\" to \"" + replacementText.substr(indexToBreak) + "\"");
// console.log(replacementText.substr(indexToBreak).length + wordsInText[w].length + " < " + wrapWidth);
// console.log("\"" + replacementText.substr(indexToBreak) + "\"");
replacementText += wordsInText[w];
// console.log("Turns to: \"" + replacementText.substr(indexToBreak) + "\"");
indexToBreak = replacementText.length;
} else {
// console.log("Checking: \"" + replacementText.substr(indexToBreak) + wordsInText[w] + "\"");
// console.log(replacementText.substr(indexToBreak).length + wordsInText[w].length + " > " + wrapWidth);
// console.log("\"" + replacementText.substr(indexToBreak) + "\"");
// indexToBreak = replacementText.length - 1;
var numberOfSpaces = wrapWidth - replacementText.substr(indexToBreak).length;
for (var s = 0; s < numberOfSpaces; s++) {
replacementText += " ";
}
// console.log("Turns to: \"" + replacementText.substr(indexToBreak) + "\"");
indexToBreak = replacementText.length;
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("----");
}
text = replacementText;
}
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;
}
}
for (var i = 0; i < text.length; i++) {
var letterCellX, letterCellY;
switch (text.charAt(i)) {
case "A":
letterCellX = 0;
letterCellY = 0;
break;
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);
}
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.savedGameExists = (OS.Load("TradeWindsSave")) ? true : false;
G.player = {}; // Just a reference until G.player is created at rm_Ocean's load time.
G.oceanParticle = {}; // One ocean particle will exist at any time and move around the boat.
G.map = []; // List of island objects, generated/loaded and saved at game start, loaded on room start.
G.currentScreen = ""; // For pause screen, stats screen, inventory screen
G.player = {}; // Just a reference until G.player is created at rm_Ocean's load time.
G.oceanParticle = {}; // One ocean particle will exist at any time and move around the boat.
G.map = []; // List of island objects, generated/loaded and saved at game start, loaded on room start.
G.currentScreen = ""; // For pause screen, stats screen, inventory screen
G.inventory = {
money: 100,
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.
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],
moneyDisplay: function () {
var moneyString = "";
if (G.inventory.money >= 1000000) {
moneyString = G.inventory.money.toString().substr(0, 1);
if (parseInt(G.inventory.money.toString().substr(1, 1)) > 0) {
moneyString += "." + G.inventory.money.toString().substr(1, 1);
}
}
if (G.inventory.money >= 1000000000000) {
moneyString += "T";
} else if (G.inventory.money >= 1000000000) {
moneyString += "B";
} else if (G.inventory.money >= 1000000) {
moneyString += "M";
} else {
moneyString = G.inventory.money.toString();
}
money: 100,
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.
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],
moneyDisplay: function () {
var moneyString = "";
if (G.inventory.money >= 1000000) {
moneyString = G.inventory.money.toString().substr(0, 1);
if (parseInt(G.inventory.money.toString().substr(1, 1)) > 0) {
moneyString += "." + G.inventory.money.toString().substr(1, 1);
}
}
if (G.inventory.money >= 1000000000000) {
moneyString += "T";
} else if (G.inventory.money >= 1000000000) {
moneyString += "B";
} else if (G.inventory.money >= 1000000) {
moneyString += "M";
} else {
moneyString = G.inventory.money.toString();
}
return moneyString;
},
CheckCargo: function () { // Returns an array of indices that have cargo
var indicesWithCargo = [];
for (var i = 0; i < G.inventory.cargo.length; i++) {
if (G.inventory.cargo[i] > 0) {
indicesWithCargo.push(i);
}
}
return indicesWithCargo;
},
CargoTotal: function () {
var cargo = G.inventory.CheckCargo();
var cargoTotal = 0;
for (var i = 0; i < cargo.length; i++) {
cargoTotal += G.inventory.cargo[cargo[i]];
}
return cargoTotal;
},
CanBuy: function (itemIndex, 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))
{
return true;
} else {
return false;
}
},
CanSell: function (itemIndex) {
return G.inventory.cargo[itemIndex] > 0;
}
return moneyString;
},
CheckCargo: function () { // Returns an array of indices that have cargo
var indicesWithCargo = [];
for (var i = 0; i < G.inventory.cargo.length; i++) {
if (G.inventory.cargo[i] > 0) {
indicesWithCargo.push(i);
}
}
return indicesWithCargo;
},
CargoTotal: function () {
var cargo = G.inventory.CheckCargo();
var cargoTotal = 0;
for (var i = 0; i < cargo.length; i++) {
cargoTotal += G.inventory.cargo[cargo[i]];
}
return cargoTotal;
},
CanBuy: function (itemIndex, 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))
{
return true;
} else {
return false;
}
},
CanSell: function (itemIndex) {
return G.inventory.cargo[itemIndex] > 0;
}
};
G.stats = {
inventory: 3, // Maximum number of different things the cargo can hold.
hold: 20, // Maximum number of each individual kind of thing in the inventory.
speed: 1, // How many pixels you move.
hull: 3, // Your HP, pretty much. How many times you can crash without exploding.
maxHull: 3, // How much your hull can refill to.
popularity: 5, // Haggle success rate in percentage.
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.
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.
illness: 0 // Your crew's overall health. When this is low, your ship slows down.
inventory: 3, // Maximum number of different things the cargo can hold.
hold: 20, // Maximum number of each individual kind of thing in the inventory.
speed: 1, // How many pixels you move.
hull: 3, // Your HP, pretty much. How many times you can crash without exploding.
maxHull: 3, // How much your hull can refill to.
popularity: 5, // Haggle success rate in percentage.
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.
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.
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.
// So the second item on the top row is index 1, and to get its value, you get `G.economy.cargoItemWorth[1]`
innCost: 50,
innStays: 0,
cargoItemWorth: [10, 20, 30, 30, //Can be adjusted based on sales.
40, 20, 50, 80,
65, 20, 20, 30,
30, 60, 45, 70],
maxPriceChange: 10,
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],
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],
UpdateEconomy: function () {
// console.log(G.economy.cargoItemWorth);
for (var i = 0; i < G.economy.cargoItemWorth.length; i++) {
var totalPriceDifference = 0;
for (var m = 0; m < G.map.length; m++) {
// console.log("map: " + G.map[m].island);
totalPriceDifference += 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.
}
var totalInnCost = 0;
for (var m = 0; m < G.map.length; m++) {
totalInnCost += G.map[m].island.innPriceDifference;
}
G.economy.innCost += Math.round(totalInnCost / G.map.length); // Apply the average inn price.
// console.log(G.economy.cargoItemWorth);
}
innCost: 50,
innStays: 0,
cargoItemWorth: [10, 20, 30, 30, //Can be adjusted based on sales.
40, 20, 50, 80,
65, 20, 20, 30,
30, 60, 45, 70],
maxPriceChange: 10,
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],
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],
UpdateEconomy: function () {
// console.log(G.economy.cargoItemWorth);
for (var i = 0; i < G.economy.cargoItemWorth.length; i++) {
var totalPriceDifference = 0;
for (var m = 0; m < G.map.length; m++) {
// console.log("map: " + G.map[m].island);
totalPriceDifference += 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.
}
var totalInnCost = 0;
for (var m = 0; m < G.map.length; m++) {
totalInnCost += G.map[m].island.innPriceDifference;
}
G.economy.innCost += Math.round(totalInnCost / G.map.length); // Apply the average inn price.
// console.log(G.economy.cargoItemWorth);
},
};
G.SaveGame = function () {
var saveObject = {
playerX: G.player.x,
playerY: G.player.y,
money: G.inventory.money,
supplies: G.inventory.supplies,
cargo: G.inventory.cargo.slice(),
stats: {
inventory: G.stats.inventory,
hold: G.stats.hold,
speed: G.stats.speed,
hull: G.stats.hull,
maxHull: G.stats.maxHull,
popularity: G.stats.popularity,
haggling: G.stats.haggling,
crew: G.stats.crew,
energy: G.stats.energy,
maxEnergy: G.stats.maxEnergy,
illness: G.stats.illness
},
economy: {
innCost: G.economy.innCost,
innStays: G.economy.innStays,
itemWorth: G.economy.cargoItemWorth.slice(),
cargoSold: G.economy.cargoSold.slice(),
cargoBought: G.economy.cargoBought.slice()
},
map: []
};
for (var i = 0; i < G.map.length; i++) {
saveObject.map.push({
drawX: G.map[i].drawX,
drawY: G.map[i].drawY,
drawWidth: G.map[i].drawWidth,
drawHeight: G.map[i].drawHeight,
inventory: G.map[i].island.inventory.slice(),
innPriceDifference: G.map[i].island.innPriceDifference,
innStays: G.map[i].island.innStays,
priceDifferences: G.map[i].island.priceDifferences.slice(),
itemsSold: G.map[i].island.itemsSold.slice(),
itemsBought: G.map[i].island.itemsBought.slice()
});
}
var saveObject = {
playerX: G.player.x,
playerY: G.player.y,
money: G.inventory.money,
supplies: G.inventory.supplies,
cargo: G.inventory.cargo.slice(),
stats: {
inventory: G.stats.inventory,
hold: G.stats.hold,
speed: G.stats.speed,
hull: G.stats.hull,
maxHull: G.stats.maxHull,
popularity: G.stats.popularity,
haggling: G.stats.haggling,
crew: G.stats.crew,
energy: G.stats.energy,
maxEnergy: G.stats.maxEnergy,
illness: G.stats.illness,
},
economy: {
innCost: G.economy.innCost,
innStays: G.economy.innStays,
itemWorth: G.economy.cargoItemWorth.slice(),
cargoSold: G.economy.cargoSold.slice(),
cargoBought: G.economy.cargoBought.slice(),
},
map: [],
};
for (var i = 0; i < G.map.length; i++) {
saveObject.map.push({
drawX: G.map[i].drawX,
drawY: G.map[i].drawY,
drawWidth: G.map[i].drawWidth,
drawHeight: G.map[i].drawHeight,
inventory: G.map[i].island.inventory.slice(),
innPriceDifference: G.map[i].island.innPriceDifference,
innStays: G.map[i].island.innStays,
priceDifferences: G.map[i].island.priceDifferences.slice(),
itemsSold: G.map[i].island.itemsSold.slice(),
itemsBought: G.map[i].island.itemsBought.slice(),
});
}
if (OS.Save("TradeWindsSave", JSON.stringify(saveObject))) {
console.log("Game Saved!");
}
if (OS.Save("TradeWindsSave", JSON.stringify(saveObject))) {
console.log("Game Saved!");
}
}
G.LoadGame = function () {
var loadObject = OS.Load("TradeWindsSave");
if (loadObject) {
loadObject = JSON.parse(loadObject);
G.player.x = loadObject.playerX;
G.player.y = loadObject.playerY;
G.inventory.money = loadObject.money;
G.inventory.supplies = loadObject.supplies;
G.inventory.cargo = loadObject.cargo.slice();
G.stats.inventory = loadObject.stats.inventory;
G.stats.hold = loadObject.stats.hold;
G.stats.speed = loadObject.stats.speed;
G.stats.hull = loadObject.stats.hull;
G.stats.maxHull = loadObject.stats.maxHull;
G.stats.popularity = loadObject.stats.popularity;
G.stats.haggling = loadObject.stats.haggling;
G.stats.crew = loadObject.stats.crew;
G.stats.energy = loadObject.stats.energy;
G.stats.maxEnergy = loadObject.stats.maxEnergy;
G.stats.illness = loadObject.stats.illness;
G.economy.innCost = loadObject.economy.innCost;
G.economy.innStays = loadObject.economy.innStays;
G.economy.cargoItemWorth = loadObject.economy.itemWorth.slice();
G.economy.cargoSold = loadObject.economy.cargoSold.slice();
G.economy.cargoBought = loadObject.economy.cargoBought.slice();
var loadObject = OS.Load("TradeWindsSave");
if (loadObject) {
loadObject = JSON.parse(loadObject);
G.player.x = loadObject.playerX;
G.player.y = loadObject.playerY;
G.inventory.money = loadObject.money;
G.inventory.supplies = loadObject.supplies;
G.inventory.cargo = loadObject.cargo.slice();
G.stats.inventory = loadObject.stats.inventory;
G.stats.hold = loadObject.stats.hold;
G.stats.speed = loadObject.stats.speed;
G.stats.hull = loadObject.stats.hull;
G.stats.maxHull = loadObject.stats.maxHull;
G.stats.popularity = loadObject.stats.popularity;
G.stats.haggling = loadObject.stats.haggling;
G.stats.crew = loadObject.stats.crew;
G.stats.energy = loadObject.stats.energy;
G.stats.maxEnergy = loadObject.stats.maxEnergy;
G.stats.illness = loadObject.stats.illness;
G.economy.innCost = loadObject.economy.innCost;
G.economy.innStays = loadObject.economy.innStays;
G.economy.cargoItemWorth = loadObject.economy.itemWorth.slice();
G.economy.cargoSold = loadObject.economy.cargoSold.slice();
G.economy.cargoBought = loadObject.economy.cargoBought.slice();
for (var i = 0; i < loadObject.map.length; i++) {
G.map[i].drawX = loadObject.map[i].drawX;
G.map[i].drawY = loadObject.map[i].drawY;
G.map[i].drawWidth = loadObject.map[i].drawWidth;
G.map[i].drawHeight = loadObject.map[i].drawHeight;
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.inventory = loadObject.map[i].inventory.slice();
G.map[i].island.innPriceDifference = loadObject.map[i].innPriceDifference;
G.map[i].island.innStays = loadObject.map[i].innStays;
G.map[i].island.priceDifferences = loadObject.map[i].priceDifferences.slice();
G.map[i].island.itemsSold = loadObject.map[i].itemsSold.slice();
G.map[i].island.itemsBought = loadObject.map[i].itemsBought.slice();
}
loadObject = null;
console.log("Game Loaded!");
} else {
console.log("Could not load game!");
return false;
}
for (var i = 0; i < loadObject.map.length; i++) {
G.map[i].drawX = loadObject.map[i].drawX;
G.map[i].drawY = loadObject.map[i].drawY;
G.map[i].drawWidth = loadObject.map[i].drawWidth;
G.map[i].drawHeight = loadObject.map[i].drawHeight;
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.inventory = loadObject.map[i].inventory.slice();
G.map[i].island.innPriceDifference = loadObject.map[i].innPriceDifference;
G.map[i].island.innStays = loadObject.map[i].innStays;
G.map[i].island.priceDifferences = loadObject.map[i].priceDifferences.slice();
G.map[i].island.itemsSold = loadObject.map[i].itemsSold.slice();
G.map[i].island.itemsBought = loadObject.map[i].itemsBought.slice();
}
loadObject = null;
console.log("Game Loaded!");
} else {
console.log("Could not load game!");
return false;
}
}
function loadGameManager () {
for (var i = 0; i < G.economy.cargoItemWorth.length; i++) {
G.economy.cargoItemWorth[i] += Math.round(Math.randomRange(-5, 5));
}
for (var i = 0; i < G.economy.cargoItemWorth.length; i++) {
G.economy.cargoItemWorth[i] += Math.round(Math.randomRange(-5, 5));
}
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadGameManager()");
}

View File

@ -1,33 +1,32 @@
var prefabsLoaded = 0;
var prefabsToLoad = 4;
function loadPrefabs() {
OS.AddScript("prefabs/shipPrefab.js");
OS.AddScript("prefabs/islandPrefab.js");
OS.AddScript("prefabs/oceanTilePrefab.js");
OS.AddScript("prefabs/wavePrefab.js");
OS.AddScript("prefabs/shipPrefab.js");
OS.AddScript("prefabs/islandPrefab.js");
OS.AddScript("prefabs/oceanTilePrefab.js");
OS.AddScript("prefabs/wavePrefab.js");
// Delay switching to Ocean room until everything is loaded.
WaitForPrefabsToLoad();
// Delay switching to Ocean room until everything is loaded.
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.
WaitForPrefabsToLoad = function () {
console.log("waiting for " + (prefabsToLoad - prefabsLoaded).toString() + " prefabs to load");
if (prefabsLoaded < prefabsToLoad || !window["oceanRoom"])
{
setTimeout(function(){WaitForPrefabsToLoad()}, 0.1);
console.log("waiting for " + (prefabsToLoad - prefabsLoaded).toString() + " prefabs to load");
if (prefabsLoaded < prefabsToLoad || !window["oceanRoom"]) {
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 {
// 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 {
setTimeout(function(){WaitForPrefabsToLoad()}, 0.1);
}
setTimeout(function(){WaitForPrefabsToLoad()}, 0.1);
}
}
}

View File

@ -1,20 +1,20 @@
var rm_Load = OS.R.Add("Default");
var rm_Ocean = OS.R.Add("Ocean Room", {
// 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.
height: pixel(64) * 44,
backgroundColor: "#1b2632",
squaresX: 50,
squaresY: 44,
squareSize: pixel(64),
numberOfIslands: 10,
clockTimerCutoff: ((1 / OS.S.defaultStep) * 60) * 5 // 5 minute day.
// 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.
height: pixel(64) * 44,
backgroundColor: "#1b2632",
squaresX: 50,
squaresY: 44,
squareSize: pixel(64),
numberOfIslands: 10,
clockTimerCutoff: ((1 / OS.S.defaultStep) * 60) * 5, // 5 minute day.
});
function loadRooms() {
OS.AddScript("rooms/oceanRoom.js");
rm_Load.SetAsCurrentRoom();
OS.AddScript("rooms/oceanRoom.js");
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, {});
function islandPrefab() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran islandPrefab()");
prefabsLoaded++;
if (Oversimplified.DEBUG.showMessages) console.log("Ran islandPrefab()");
prefabsLoaded++;
}
var pr_island = OS.P.Add("Island", {
solid: true,
imageSrc: "images/island.png",
animations: [ani_island_1],
depth: -50,
solid: true,
imageSrc: "images/island.png",
animations: [ani_island_1],
depth: -50,
mapX: 0,
mapY: 0,
mapWidth: 1,
mapHeight: 1,
mapColor: "#00AB00",
mapX: 0,
mapY: 0,
mapWidth: 1,
mapHeight: 1,
mapColor: "#00AB00",
canTrade: true,
haggleAmount: 0,
timesHaggledToday: 0,
itemsSoldToday: [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
itemsBoughtToday: [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
money: 0,
inventory: [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
storageSpace: [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
innPriceDifference: 0,
innStays: 0,
priceDifferences: [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
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
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
canTrade: true,
haggleAmount: 0,
timesHaggledToday: 0,
itemsSoldToday: [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
itemsBoughtToday: [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
money: 0,
inventory: [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
storageSpace: [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
innPriceDifference: 0,
innStays: 0,
priceDifferences: [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
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
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
storageFee: 10,
storageFeeMultiplier: 0.1,
storage: [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0]
storageFee: 10,
storageFeeMultiplier: 0.1,
storage: [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
});
pr_island.DoFirst = function () {
this.GetMapPosition();
this.SetUp();
this.GetMapPosition();
this.SetUp();
}
pr_island.GetMapPosition = function () {
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.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);
}
pr_island.SetUp = function () {
for (var i = 0; i < 16; i++) {
this.storageSpace[i] = Math.round(Math.randomRange(20, 35));
for (var i = 0; i < 16; i++) {
this.storageSpace[i] = Math.round(Math.randomRange(20, 35));
if (this.storageSpace[i] > 30) {
this.inventory[i] = Math.round(this.storageSpace[i] - Math.randomRange(0, 30));
} else if (Math.randomRange(0, 100) < 25) {
this.inventory[i] = Math.round(Math.randomRange(0, this.storageSpace[i]));
}
}
// console.log(this.name + " stock: " + this.inventory);
if (this.storageSpace[i] > 30) {
this.inventory[i] = Math.round(this.storageSpace[i] - Math.randomRange(0, 30));
} else if (Math.randomRange(0, 100) < 25) {
this.inventory[i] = Math.round(Math.randomRange(0, this.storageSpace[i]));
}
}
// console.log(this.name + " stock: " + this.inventory);
this.AdjustPrices();
// console.log(this.name + " pricing: " + this.priceDifferences);
this.AdjustPrices();
// console.log(this.name + " pricing: " + this.priceDifferences);
if (this.CheckInventory().length < 4) {
this.SetUp();
} else {
for (var i = 0; i < 16; i++) {
// 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];
}
// Minimum amount of money is 100.
if (this.money < 100) this.money = 100;
}
if (this.CheckInventory().length < 4) {
this.SetUp();
} else {
for (var i = 0; i < 16; i++) {
// 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];
}
// Minimum amount of money is 100.
if (this.money < 100) this.money = 100;
}
}
pr_island.AdjustPrices = function () {
for (var i = 0; i < 16; i++) {
// Save the previous price difference so the change doesn't get above a certain thereshold.
var previousPrice = newPriceDifference = this.priceDifferences[i];
for (var i = 0; i < 16; i++) {
// Save the previous price difference so the change doesn't get above a certain thereshold.
var previousPrice = newPriceDifference = this.priceDifferences[i];
if (this.inventory[i] > (this.storageSpace[i] / 2)) {
newPriceDifference -= Math.round(this.inventory[i] * Math.randomRange(1, 3));
}
else if (this.inventory[i] < (this.storageSpace[i] / 4)) {
newPriceDifference += Math.round((this.storageSpace[i] - this.inventory[i]) * Math.randomRange(1, 3));
}
else {
newPriceDifference += Math.round(Math.randomRange(-2, 2));
}
if (this.inventory[i] > (this.storageSpace[i] / 2)) {
newPriceDifference -= Math.round(this.inventory[i] * Math.randomRange(1, 3));
}
else if (this.inventory[i] < (this.storageSpace[i] / 4)) {
newPriceDifference += Math.round((this.storageSpace[i] - this.inventory[i]) * Math.randomRange(1, 3));
}
else {
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) {
// Prevent price from changing more than the limit.
newPriceDifference = previousPrice + ((previousPrice < 0) ? -G.economy.maxPriceChange : G.economy.maxPriceChange);
}
if (Math.abs(newPriceDifference) > Math.abs(previousPrice) + G.economy.maxPriceChange) {
// Prevent price from changing more than the limit.
newPriceDifference = previousPrice + ((previousPrice < 0) ? -G.economy.maxPriceChange : G.economy.maxPriceChange);
}
if (G.economy.cargoItemWorth[i] + newPriceDifference < 0) {
newPriceDifference = -G.economy.cargoItemWorth[i] + 1;
}
if (G.economy.cargoItemWorth[i] + newPriceDifference < 0) {
newPriceDifference = -G.economy.cargoItemWorth[i] + 1;
}
this.priceDifferences[i] = newPriceDifference;
}
this.priceDifferences[i] = newPriceDifference;
}
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));
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));
}
pr_island.SimulateTrade = function () {
// This will be run on a timer that runs when not trading.
for (var i = 0; i < 16; i++) {
var amount = 0;
if (this.inventory[i] > 0) {
amount = Math.round(Math.randomRange(-this.storageSpace[i], this.storageSpace[i]));
this.inventory[i] += amount;
for (var i = 0; i < 16; i++) {
var amount = 0;
if (this.inventory[i] > 0) {
amount = Math.round(Math.randomRange(-this.storageSpace[i], this.storageSpace[i]));
this.inventory[i] += amount;
if (this.inventory[i] < 0) {
this.inventory[i] = 0;
}
if (this.inventory[i] > this.storageSpace[i]) {
this.inventory[i] = this.storageSpace[i];
}
} else {
if (Math.randomRange(0, 100) < 15) {
amount = Math.round(Math.randomRange(0, this.storageSpace[i]));
this.inventory[i] = amount;
}
}
// 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)
this.money += (-amount * (G.economy.cargoItemWorth[i] + this.priceDifferences[i])) * ((amount > 0) ? 0.5 : 1);
}
if (this.inventory[i] < 0) {
this.inventory[i] = 0;
}
if (this.inventory[i] > this.storageSpace[i]) {
this.inventory[i] = this.storageSpace[i];
}
} else {
if (Math.randomRange(0, 100) < 15) {
amount = Math.round(Math.randomRange(0, this.storageSpace[i]));
this.inventory[i] = amount;
}
}
// 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)
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 () {
this.haggleAmount = 0;
this.haggleAmount = 0;
this.timesHaggledToday = 0;
this.itemsSoldToday = [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0];
this.itemsBoughtToday = [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0];
this.itemsSoldToday = [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0];
this.itemsBoughtToday = [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0];
this.SimulateTrade();
}
pr_island.CheckInventory = function () { // Returns an array of indices that have cargo
var indicesWithCargo = [];
for (var i = 0; i < this.inventory.length; i++) {
if (this.inventory[i] > 0) {
indicesWithCargo.push(i);
}
}
return indicesWithCargo;
pr_island.CheckInventory = function () { // Returns an array of indices that have cargo
var indicesWithCargo = [];
for (var i = 0; i < this.inventory.length; i++) {
if (this.inventory[i] > 0) {
indicesWithCargo.push(i);
}
}
return indicesWithCargo;
}
pr_island.TradeWith = function () {
// Change music to Trade.
// console.log(this.inventory);
mus_sail.Stop();
mus_trade.Play();
guiControl.trade.island = this;
guiControl.trade.haggleAmount = 0;
guiControl.trade.activateDelay = 5;
guiControl.trade.show = true;
// Change music to Trade.
// console.log(this.inventory);
mus_sail.Stop();
mus_trade.Play();
guiControl.trade.island = this;
guiControl.trade.haggleAmount = 0;
guiControl.trade.activateDelay = 5;
guiControl.trade.show = true;
}
pr_island.CanSellTo = function (itemIndex, price) {
if (this.inventory[itemIndex] < this.storageSpace[itemIndex] && price < this.money) {
// If there's space in the inventory and there's enough money.
return true;
}
return false;
if (this.inventory[itemIndex] < this.storageSpace[itemIndex] && price < this.money) {
// If there's space in the inventory and there's enough money.
return true;
}
return false;
}
pr_island.SellTo = function (itemIndex, price) {
// Play Buy sound.
this.inventory[itemIndex]++;
this.itemsBought[itemIndex]++;
this.money -= price;
// Play Buy sound.
this.inventory[itemIndex]++;
this.itemsBought[itemIndex]++;
this.money -= price;
G.inventory.cargo[itemIndex]--;
G.inventory.money += price;
G.economy.cargoSold[itemIndex]++;
G.inventory.cargo[itemIndex]--;
G.inventory.money += price;
G.economy.cargoSold[itemIndex]++;
}
pr_island.CanBuyFrom = function (itemIndex, price) {
if (this.inventory[itemIndex] > 0) { // If there's enough of the item
return true;
}
return false;
if (this.inventory[itemIndex] > 0) { // If there's enough of the item
return true;
}
return false;
}
pr_island.BuyFrom = function (itemIndex, price) {
// Play Sell sound.
this.inventory[itemIndex]--;
this.itemsSold[itemIndex]++;
this.money += price;
// Play Sell sound.
this.inventory[itemIndex]--;
this.itemsSold[itemIndex]++;
this.money += price;
G.inventory.cargo[itemIndex]++;
G.inventory.money -= price;
G.economy.cargoBought[itemIndex]++;
G.inventory.cargo[itemIndex]++;
G.inventory.money -= price;
G.economy.cargoBought[itemIndex]++;
}
pr_island.StayAtInn = function () {
// Play Sell sound.
this.innStays++;
// Play Sell sound.
this.innStays++;
G.stats.illness--;
G.inventory.money -= G.economy.innCost + this.innPriceDifference;
G.economy.innStays++;
G.stats.illness--;
G.inventory.money -= G.economy.innCost + this.innPriceDifference;
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() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran oceanTilePrefab()");
prefabsLoaded++;
if (Oversimplified.DEBUG.showMessages) console.log("Ran oceanTilePrefab()");
prefabsLoaded++;
}
var pr_ocean = OS.P.Add("Ocean Particle", {
imageSrc: "images/ocean_sheet.png",
animations: [ani_ocean],
depth: -100, // Draw below everything.
imageSrc: "images/ocean_sheet.png",
animations: [ani_ocean],
depth: -100, // Draw below everything.
positionCheckStep: 30,
positionCheckProgress: 30,
doCheckPosition: false,
positionCheckStep: 30,
positionCheckProgress: 30,
doCheckPosition: false,
moveTimer: 0,
moveTimer: 0,
});
pr_ocean.BeforeDo = function () {
this.positionCheckProgress++;
if (this.positionCheckProgress >= this.positionCheckStep) {
this.positionCheckProgress = 0;
this.doCheckPosition = true;
}
this.positionCheckProgress++;
if (this.positionCheckProgress >= this.positionCheckStep) {
this.positionCheckProgress = 0;
this.doCheckPosition = true;
}
}
pr_ocean.Do = function () {
// Move around randomly.
this.moveTimer++;
if (this.moveTimer >= 120) {
this.x += 1 * pixel(Math.round(Math.randomRange(-1, 1)));
this.y += 1 * pixel(Math.round(Math.randomRange(-1, 1)));
this.moveTimer = 0;
}
// Move around randomly.
this.moveTimer++;
if (this.moveTimer >= 120) {
this.x += 1 * pixel(Math.round(Math.randomRange(-1, 1)));
this.y += 1 * pixel(Math.round(Math.randomRange(-1, 1)));
this.moveTimer = 0;
}
}
pr_ocean.CheckPosition = function (checkX, checkY, direction) {
if (this.doCheckPosition) {
// If it's completely off the screen, then update position.
if ((Math.abs(this.x - checkX) > (OS.camera.width + this.xBound)) ||
(Math.abs(this.y - checkY) > (OS.camera.height + this.yBound)))
{
switch (direction) {
case 0:
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY + randomSmidge();
if (this.doCheckPosition) {
// If it's completely off the screen, then update position.
if ((Math.abs(this.x - checkX) > (OS.camera.width + this.xBound)) ||
(Math.abs(this.y - checkY) > (OS.camera.height + this.yBound)))
{
switch (direction) {
case 0: {
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY + randomSmidge();
break;
case 45:
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
}
case 45: {
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
break;
case 90:
this.x = checkX + randomSmidge();
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
}
case 90: {
this.x = checkX + randomSmidge();
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
break;
case 135:
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
}
case 135: {
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY - (OS.camera.height + this.yBound) + randomSmidge();
break;
case 180:
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY + randomSmidge();
}
case 180: {
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY + randomSmidge();
break;
case 225:
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
}
case 225: {
this.x = checkX - (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
break;
case 270:
this.x = checkX + randomSmidge();
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
}
case 270: {
this.x = checkX + randomSmidge();
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
break;
case 315:
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
}
case 315: {
this.x = checkX + (OS.camera.width + this.xBound) + randomSmidge();
this.y = checkY + (OS.camera.height + this.yBound) + randomSmidge();
break;
default:
console.log("No valid direction");
}
default: {
console.log("No valid direction");
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});
function shipPrefab() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran shipPrefab()");
prefabsLoaded++;
if (Oversimplified.DEBUG.showMessages) console.log("Ran shipPrefab()");
prefabsLoaded++;
}
var pr_ship = OS.P.Add("Ship", {
solid: true,
imageSrc: "images/ship_sheet.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],
direction: 0,
currentSpeed: 0,
pointInFront : {x: 0, y: 0 },
moveStepSize: 3,
moveStepAmount: 5 * OS.R[OS.R.currentRoom].stepSpeed,
moveStepProgress: 0,
doTakeStep: false,
solid: true,
imageSrc: "images/ship_sheet.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],
direction: 0,
currentSpeed: 0,
pointInFront : {x: 0, y: 0 },
moveStepSize: 3,
moveStepAmount: 5 * OS.R[OS.R.currentRoom].stepSpeed,
moveStepProgress: 0,
doTakeStep: false,
energyRefillTimer: 0,
energyRefillTimer: 0,
drawSickIndicator: 0,
drawSickIndicatorTime: secondsWorthOfFrames(1.5)
drawSickIndicator: 0,
drawSickIndicatorTime: secondsWorthOfFrames(1.5),
});
pr_ship.BeforeDo = function () {
if (G.gameStarted) {
this.GetMapPosition();
}
if (G.gameStarted) {
this.GetMapPosition();
}
}
pr_ship.Do = function () {
if (G.gameStarted) {
if (guiControl && guiControl.inventory && guiControl.map && guiControl.trade) { // Force it to wait until loaded.
if (!guiControl.inventory.show && !guiControl.map.show && !guiControl.trade.show) {
if (ct_left().down) {
this.direction += 45;
} else if (ct_right().down) {
this.direction -= 45;
}
this.direction = Math.clampAngle(this.direction);
if (ct_up().down) {
this.currentSpeed++;
} else if (ct_down().down) {
this.currentSpeed--;
}
this.AdjustSpeedBasedOnEnergy();
if (G.gameStarted) {
if (guiControl && guiControl.inventory && guiControl.map && guiControl.trade) { // Force it to wait until loaded.
if (!guiControl.inventory.show && !guiControl.map.show && !guiControl.trade.show) {
if (ct_left().down) {
this.direction += 45;
} else if (ct_right().down) {
this.direction -= 45;
}
this.direction = Math.clampAngle(this.direction);
if (ct_up().down) {
this.currentSpeed++;
} else if (ct_down().down) {
this.currentSpeed--;
}
this.AdjustSpeedBasedOnEnergy();
this.CheckInteraction();
}
}
this.CheckInteraction();
}
}
this.currentSpeed = Math.clamp(this.currentSpeed, 0, 4);
this.moveStepProgress += this.currentSpeed * this.moveStepAmount;
if (this.moveStepProgress >= this.moveStepSize) {
this.moveStepProgress -= this.moveStepSize;
this.doTakeStep = true;
} else {
this.doTakeStep = false;
}
this.currentSpeed = Math.clamp(this.currentSpeed, 0, 4);
this.moveStepProgress += this.currentSpeed * this.moveStepAmount;
if (this.moveStepProgress >= this.moveStepSize) {
this.moveStepProgress -= this.moveStepSize;
this.doTakeStep = true;
} else {
this.doTakeStep = false;
}
this.SeamlessScroll();
// console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y);
}
this.SeamlessScroll();
// console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y);
}
}
pr_ship.AfterDo = function () {
if (G.gameStarted) {
this.CheckMovement();
this.UpdateEnergy();
}
if (G.gameStarted) {
this.CheckMovement();
this.UpdateEnergy();
}
}
pr_ship.DrawAbove = function () {
if (G.gameStarted) {
this.drawSickIndicator--;
if (this.drawSickIndicator < 0) {
this.drawSickIndicator = 0;
}
if (this.drawSickIndicator > 0) {
var sickIndicatorHeight = Math.round((this.drawSickIndicatorTime - this.drawSickIndicator) / 2) / OS.S.pixelScale;
var sickIndicatorY = this.y - sickIndicatorHeight - Oversimplified.camera.y - (guiControl.iconScaled / 2);
guiControl.drawIcon(4, 1, this.x - Oversimplified.camera.x - (guiControl.iconScaled / 2), sickIndicatorY);
}
}
if (G.gameStarted) {
this.drawSickIndicator--;
if (this.drawSickIndicator < 0) {
this.drawSickIndicator = 0;
}
if (this.drawSickIndicator > 0) {
var sickIndicatorHeight = Math.round((this.drawSickIndicatorTime - this.drawSickIndicator) / 2) / OS.S.pixelScale;
var sickIndicatorY = this.y - sickIndicatorHeight - Oversimplified.camera.y - (guiControl.iconScaled / 2);
guiControl.drawIcon(4, 1, this.x - Oversimplified.camera.x - (guiControl.iconScaled / 2), sickIndicatorY);
}
}
}
pr_ship.GetMapPosition = function () {
this.mapX = pixel(Math.round(this.x / pixel(64)));
this.mapY = pixel(Math.round(this.y / pixel(64)));
// console.log(this.mapX + ", " + this.mapY);
this.mapX = pixel(Math.round(this.x / pixel(64)));
this.mapY = pixel(Math.round(this.y / pixel(64)));
// console.log(this.mapX + ", " + this.mapY);
}
pr_ship.CheckInteraction = function () {
if (ct_confirm().down) {
var objectsFound = OS.GameObjectsAtPoint(this.pointInFront.x, this.pointInFront.y);
if (objectsFound.length > 0) {
for (var i = 0; i < objectsFound.length; i++) {
if (objectsFound[i].canTrade) {
// console.log("interacting with island: " + objectsFound[i].name);
objectsFound[i].TradeWith();
}
}
}
}
if (ct_confirm().down) {
var objectsFound = OS.GameObjectsAtPoint(this.pointInFront.x, this.pointInFront.y);
if (objectsFound.length > 0) {
for (var i = 0; i < objectsFound.length; i++) {
if (objectsFound[i].canTrade) {
// console.log("interacting with island: " + objectsFound[i].name);
objectsFound[i].TradeWith();
}
}
}
}
}
pr_ship.CheckMovement = function () {
var moveAmount = pixel(G.stats.speed + this.currentSpeed);
var movedSuccessfully = false;
switch (this.direction) {
case 0:
if (this.sprite.currentAnimation != "Ship Right") this.SetAnimation("Ship Right");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, 0, true, pixel(4));
this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount;
this.pointInFront.y = this.y;
break;
case 45:
if (this.sprite.currentAnimation != "Ship Up-Right") this.SetAnimation("Ship Up-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;
case 90:
if (this.sprite.currentAnimation != "Ship Up") this.SetAnimation("Ship Up");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, -moveAmount, true, pixel(4));
this.pointInFront.x = this.x;
this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount;
break;
case 135:
if (this.sprite.currentAnimation != "Ship Up-Left") this.SetAnimation("Ship Up-Left");
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;
case 180:
if (this.sprite.currentAnimation != "Ship Left") this.SetAnimation("Ship Left");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, 0, true, pixel(4));
this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount;
this.pointInFront.y = this.y;
break;
case 225:
if (this.sprite.currentAnimation != "Ship Down-Left") this.SetAnimation("Ship Down-Left");
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;
case 270:
if (this.sprite.currentAnimation != "Ship Down") this.SetAnimation("Ship Down");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, moveAmount, true, pixel(4));
this.pointInFront.x = this.x;
this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount;
break;
case 315:
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;
}
var moveAmount = pixel(G.stats.speed + this.currentSpeed);
var movedSuccessfully = false;
switch (this.direction) {
case 0: {
if (this.sprite.currentAnimation != "Ship Right") this.SetAnimation("Ship Right");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, 0, true, pixel(4));
this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount;
this.pointInFront.y = this.y;
break;
}
case 45: {
if (this.sprite.currentAnimation != "Ship Up-Right") this.SetAnimation("Ship Up-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;
}
case 90: {
if (this.sprite.currentAnimation != "Ship Up") this.SetAnimation("Ship Up");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, -moveAmount, true, pixel(4));
this.pointInFront.x = this.x;
this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount;
break;
}
case 135: {
if (this.sprite.currentAnimation != "Ship Up-Left") this.SetAnimation("Ship Up-Left");
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;
}
case 180: {
if (this.sprite.currentAnimation != "Ship Left") this.SetAnimation("Ship Left");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, 0, true, pixel(4));
this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount;
this.pointInFront.y = this.y;
break;
}
case 225: {
if (this.sprite.currentAnimation != "Ship Down-Left") this.SetAnimation("Ship Down-Left");
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;
}
case 270: {
if (this.sprite.currentAnimation != "Ship Down") this.SetAnimation("Ship Down");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, moveAmount, true, pixel(4));
this.pointInFront.x = this.x;
this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount;
break;
}
case 315: {
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) {
this.currentSpeed = 0;
}
if (this.doTakeStep && !movedSuccessfully) {
this.currentSpeed = 0;
}
}
pr_ship.UpdateEnergy = function () {
this.energyRefillTimer++;
if (this.energyRefillTimer >= (100 / G.stats.crew) + ((G.stats.illness) * (100 / G.stats.crew))) {
G.stats.energy += G.stats.crew;
this.energyRefillTimer = 0;
}
this.energyRefillTimer++;
if (this.energyRefillTimer >= (100 / G.stats.crew) + ((G.stats.illness) * (100 / G.stats.crew))) {
G.stats.energy += G.stats.crew;
this.energyRefillTimer = 0;
}
if (this.doTakeStep) {
G.stats.energy -= ((this.currentSpeed / G.stats.speed) + ((G.stats.illness) * 0.1)) * 0.25;
}
if (this.doTakeStep) {
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 > G.stats.maxEnergy) G.stats.energy = G.stats.maxEnergy;
if (G.stats.energy < 0) G.stats.energy = 0;
if (G.stats.energy > G.stats.maxEnergy) G.stats.energy = G.stats.maxEnergy;
}
pr_ship.SeamlessScroll = function () {
if (this.x <= rm_Ocean.mapLeftTrigger) {
this.x = rm_Ocean.mapLeftTriggerTarget;
OS.SetCamera({x: rm_Ocean.width});
}
else if (this.x >= rm_Ocean.mapRightTrigger) {
this.x = rm_Ocean.mapRightTriggerTarget;
OS.SetCamera({x: 0});
}
else if (this.y <= rm_Ocean.mapUpTrigger) {
this.y = rm_Ocean.mapUpTriggerTarget;
OS.SetCamera({y: rm_Ocean.height});
}
else if (this.y >= rm_Ocean.mapDownTrigger) {
this.y = rm_Ocean.mapDownTriggerTarget;
OS.SetCamera({y: 0});
}
if (this.x <= rm_Ocean.mapLeftTrigger) {
this.x = rm_Ocean.mapLeftTriggerTarget;
OS.SetCamera({x: rm_Ocean.width});
}
else if (this.x >= rm_Ocean.mapRightTrigger) {
this.x = rm_Ocean.mapRightTriggerTarget;
OS.SetCamera({x: 0});
}
else if (this.y <= rm_Ocean.mapUpTrigger) {
this.y = rm_Ocean.mapUpTriggerTarget;
OS.SetCamera({y: rm_Ocean.height});
}
else if (this.y >= rm_Ocean.mapDownTrigger) {
this.y = rm_Ocean.mapDownTriggerTarget;
OS.SetCamera({y: 0});
}
}
pr_ship.AdjustSpeedBasedOnEnergy = function () {
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 > 1 && G.stats.energy < (G.stats.maxEnergy * 0.05))
{
this.currentSpeed--;
}
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 > 1 && G.stats.energy < (G.stats.maxEnergy * 0.05))
{
this.currentSpeed--;
}
}
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.
if (Math.randomRange(0, 100) < percentChance) {
snd_illness.Play();
G.stats.illness++;
this.drawSickIndicator += secondsWorthOfFrames(1.5);
}
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) {
snd_illness.Play();
G.stats.illness++;
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});
function wavePrefab() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran wavePrefab()");
prefabsLoaded++;
if (Oversimplified.DEBUG.showMessages) console.log("Ran wavePrefab()");
prefabsLoaded++;
}
var pr_wave = OS.P.Add("Wave Particle", {
imageSrc: "images/wave_sheet.png",
animations: [ani_wave],
depth: -90, // Draw above ocean, below everything else.
imageSrc: "images/wave_sheet.png",
animations: [ani_wave],
depth: -90, // Draw above ocean, below everything else.
lifeTimer: 100,
lifeTimer: 100,
});
pr_wave.DoFirst = function () {
if (!snd_wave.IsPlaying()) {
snd_wave.Play();
}
if (!snd_wave.IsPlaying()) {
snd_wave.Play();
}
}
pr_wave.Do = function () {
// Move around randomly.
this.lifeTimer--;
if (this.lifeTimer <= 0) {
this.Destroy();
}
// Move around randomly.
this.lifeTimer--;
if (this.lifeTimer <= 0) {
this.Destroy();
}
}

View File

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

View File

@ -3,36 +3,36 @@ OS.S.numberOfScriptsToLoad = 16;
OS.S.pixelScale = 4;
// Oversimplified.DEBUG.showMessages = false;
OS.SetCamera({
width: pixel(160), // 640
height: pixel(120), // 480
hBorder: pixel(64),
vBorder: pixel(48)});
width: pixel(160), // 640
height: pixel(120), // 480
hBorder: pixel(64),
vBorder: pixel(48),
});
function start()
{
OS.AddScript("loadControls.js");
OS.AddScript("loadAudio.js");
OS.AddScript("loadGameManager.js");
OS.AddScript("loadGUIs.js");
OS.AddScript("loadPrefabs.js");
OS.AddScript("loadRooms.js");
function start() {
OS.AddScript("loadControls.js");
OS.AddScript("loadAudio.js");
OS.AddScript("loadGameManager.js");
OS.AddScript("loadGUIs.js");
OS.AddScript("loadPrefabs.js");
OS.AddScript("loadRooms.js");
if (Oversimplified.DEBUG.showMessages) console.log("Ran start()");
if (Oversimplified.DEBUG.showMessages) console.log("Ran start()");
}
function pixel(number) {
return ((typeof number !== 'undefined') ? number : 1) * OS.S.pixelScale;
return ((typeof number !== 'undefined') ? number : 1) * OS.S.pixelScale;
}
function secondsWorthOfFrames(seconds) {
return seconds * (1 / OS.R[OS.R.currentRoom].stepSpeed);
return seconds * (1 / OS.R[OS.R.currentRoom].stepSpeed);
}
function randomSmidge() {
// 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) {
return a - b;
return a - b;
}

View File

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