Resized the ocean. Added map! Updated trade so you can't haggle forever. Each island knows when it's been haggled.

This commit is contained in:
Robbie Antenesse 2016-04-14 17:09:57 -06:00
parent d86b36883d
commit d45246b3d5
9 changed files with 281 additions and 160 deletions

View File

@ -2,12 +2,15 @@ function inventoryGUI() {
guiControl.inventory = {
screen: "main",
cursorPosition: 0,
show: false
show: false,
activateDelay: 0
}
}
function drawInventoryGUI() {
if (guiControl.inventory && guiControl.inventory.show) {
guiControl.inventory.activateDelay -= (guiControl.inventory.activateDelay > 0) ? 1 : 0;
OS.context.drawImage(guiControl.background, 0, 0, 240, 240, pixel(2), pixel(2), 240, 240);
if (ct_down().down) {
@ -28,6 +31,10 @@ function drawInventoryGUI() {
// 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);
// 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);
@ -45,6 +52,7 @@ function drawInventoryGUI() {
OS.context.drawImage(guiControl.cursor, 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:
@ -62,6 +70,21 @@ function drawInventoryGUI() {
}
guiControl.inventory.cursorPosition = 0;
guiControl.inventory.activateDelay = 5;
}
if (ct_cancel().down) {
guiControl.inventory.show = false;
}
if (ct_left().down) {
guiControl.inventory.show = false;
guiControl.map.activateDelay = 5;
guiControl.map.show = true;
}
if (ct_right().down) {
guiControl.inventory.show = false;
guiControl.map.activateDelay = 5;
guiControl.map.show = true;
}
}
}
else if (guiControl.inventory.screen == "money") {
@ -88,11 +111,14 @@ function drawInventoryGUI() {
OS.context.drawImage(guiControl.cursor, guiControl.leftBorder - (guiControl.iconScaled), guiControl.rowTop(4) - pixel(4));
// Button Action
if (guiControl.inventory.activateDelay <= 0) {
if (ct_confirm().down || ct_cancel().down) {
guiControl.inventory.screen = "main";
guiControl.inventory.activateDelay = 5;
guiControl.inventory.cursorPosition = 0;
}
}
}
else if (guiControl.inventory.screen == "supplies") {
// Limit Cursor
if (guiControl.inventory.cursorPosition < 0) {
@ -115,7 +141,7 @@ function drawInventoryGUI() {
// 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, "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);
@ -124,6 +150,7 @@ function drawInventoryGUI() {
guiControl.drawCursor(guiControl.leftBorder - (guiControl.iconScaled), guiControl.rowTop(guiControl.inventory.cursorPosition + 2) - pixel(4));
// Button Action
if (guiControl.inventory.activateDelay <= 0) {
if (ct_confirm().down) {
switch (guiControl.inventory.cursorPosition) {
case 1:
@ -137,13 +164,18 @@ function drawInventoryGUI() {
guiControl.inventory.cursorPosition = 1; // The position where "Supplies" is on main screen.
break;
}
// Give a cooldown so you don't accidentally do something you don't want.
guiControl.inventory.activateDelay = 5;
}
if (ct_cancel().down) {
guiControl.inventory.screen = "main";
guiControl.inventory.activateDelay = 5;
guiControl.inventory.cursorPosition = 1; // The position where "Supplies" is on main screen.
}
}
}
else if (guiControl.inventory.screen == "cargo") {
// Limit Cursor
if (guiControl.inventory.cursorPosition < 0) {
@ -170,10 +202,13 @@ function drawInventoryGUI() {
OS.context.drawImage(guiControl.cursor, guiControl.leftBorder - (guiControl.iconScaled), guiControl.rowTop(4) - pixel(4));
// Button Action
if (guiControl.inventory.activateDelay <= 0) {
if (ct_confirm().down || ct_cancel().down) {
guiControl.inventory.screen = "main";
guiControl.inventory.activateDelay = 5;
guiControl.inventory.cursorPosition = 2;
}
}
}
}
}

57
gui/mapGUI.js Normal file
View File

@ -0,0 +1,57 @@
function mapGUI() {
guiControl.map = {
show: false,
activateDelay: 0
}
}
function drawMapGUI() {
if (guiControl.map && guiControl.map.show) {
guiControl.map.activateDelay -= (guiControl.map.activateDelay > 0) ? 1 : 0;
OS.context.drawImage(guiControl.background, 0, 0, 240, 240, pixel(2), pixel(2), 240, 240);
// 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);
var saveFillStyle = OS.context.fillStyle;
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 = "#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 = saveFillStyle;
// Button Action
if (guiControl.map.activateDelay <= 0) {
if (ct_cancel().down) {
guiControl.map.show = false;
}
if (ct_left().down) {
guiControl.map.show = false;
guiControl.inventory.activateDelay = 5;
guiControl.inventory.show = true;
}
if (ct_right().down) {
guiControl.map.show = false;
guiControl.inventory.activateDelay = 5;
guiControl.inventory.show = true;
}
}
}
}

View File

@ -8,7 +8,6 @@ function tradeGUI() {
activateDelay: 0,
island: null,
haggleAmount: 0,
padding: pixel(2),
leftBorder: pixel(12),
@ -82,11 +81,13 @@ function drawTradeGUI() {
OS.context.drawImage(guiControl.cursor, guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition));
// Button Action
if (guiControl.trade.activateDelay <= 0 && ct_confirm().down) {
if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) {
case 0:
if (guiControl.trade.island.CheckInventory().length > 0) {
guiControl.trade.screen = "buy";
guiControl.trade.activateDelay = 5;
}
else {
// Play Cannot_Buy sound.
@ -95,12 +96,14 @@ function drawTradeGUI() {
case 1:
if (G.inventory.CheckCargo().length > 0) {
guiControl.trade.screen = "sell";
guiControl.trade.activateDelay = 5;
} else {
// Play Cannot_Buy sound.
}
break;
case 2:
guiControl.trade.screen = "gossip";
guiControl.trade.activateDelay = 5;
break;
default:
// Change music to Sail.
@ -113,6 +116,10 @@ function drawTradeGUI() {
guiControl.trade.page = 0;
// console.log(guiControl.trade.screen);
}
if (ct_cancel().down) {
guiControl.trade.show = false;
}
}
}
else if (guiControl.trade.screen == "buy") {
// console.log(guiControl.trade.screen);
@ -143,7 +150,7 @@ function drawTradeGUI() {
}
if (items.length > 0) {
var itemPrice = G.economy.cargoItemWorth[items[guiControl.trade.page]] + guiControl.trade.island.priceDifferences[items[guiControl.trade.page]] - guiControl.trade.haggleAmount;
var itemPrice = G.economy.cargoItemWorth[items[guiControl.trade.page]] + guiControl.trade.island.priceDifferences[items[guiControl.trade.page]] - guiControl.trade.island.haggleAmount;
if (itemPrice < 1) itemPrice = 1;
var itemPriceDisplay = itemPrice.toString() + " c";
guiControl.drawItem(items[guiControl.trade.page], guiControl.trade.leftBorder, guiControl.trade.rowTop(1) - pixel(5));
@ -166,7 +173,7 @@ function drawTradeGUI() {
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("Hagl?", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) - pixel(2), 8, (items.length > 0 && guiControl.trade.haggleAmount == 0) ? "black" : "white", 6);
guiControl.drawPixelText("Hagl?", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) - pixel(2), 8, (guiControl.trade.island.timesHaggledToday >= G.stats.popularity) ? "yellow" : ((items.length > 0 && guiControl.trade.island.haggleAmount == 0) ? "black" : "white"), 6);
guiControl.drawPixelText("Yes", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) - pixel(2), 8, (items.length > 0 && G.inventory.CanBuy(items[guiControl.trade.page], itemPrice)) ? "black" : "white", 6);
// Back Text
@ -176,16 +183,18 @@ function drawTradeGUI() {
OS.context.drawImage(guiControl.cursor, 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.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.
if (items.length > 0 && (guiControl.trade.island.timesHaggledToday <= G.stats.popularity) && // If there are items and you haven't haggled too much
guiControl.trade.island.haggleAmount == 0 && Math.floor(Math.randomRange(0, 100)) < G.stats.popularity) // Or you haven't haggled yet and get a random number less than your popularity, haggle successfully.
{
guiControl.trade.haggleAmount = G.stats.haggling;
guiControl.trade.island.haggleAmount = G.stats.haggling;
// Play Sell sound.
} else {
// Play Cannot_Buy sound.
guiControl.trade.island.timesHaggledToday++;
}
break;
case 1: // Buy
@ -198,19 +207,21 @@ function drawTradeGUI() {
break;
default:
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 0; // The position where "Buy" is on main screen.
break;
}
// Play Select sound.
// console.log(guiControl.trade.screen);
}
if (ct_cancel().down) {
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
@ -241,7 +252,7 @@ function drawTradeGUI() {
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.haggleAmount == 0) ? 0 : (G.stats.popularity * 0.01 * 0.5)); // If haggled successfully, lessen the price cut by half of your popularity's percent worth.
var priceCut = 0.5 + ((guiControl.trade.island.haggleAmount == 0) ? 0 : (G.stats.popularity * 0.01 * 0.5)); // If haggled successfully, lessen the price cut by half of your popularity's percent worth.
itemPrice = Math.round(itemPrice * priceCut);
if (itemPrice < 1) itemPrice = 1;
var itemPriceDisplay = itemPrice.toString() + " c";
@ -265,7 +276,7 @@ function drawTradeGUI() {
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, (items.length > 0 && guiControl.trade.haggleAmount == 0) ? "black" : "white", 6);
guiControl.drawPixelText("Hagl?", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) - pixel(2), 8, (guiControl.trade.island.timesHaggledToday >= G.stats.popularity) ? "yellow" : ((items.length > 0 && guiControl.trade.island.haggleAmount == 0) ? "black" : "white"), 6);
guiControl.drawPixelText("Yes", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) - pixel(2), 8, (items.length > 0 && G.inventory.CanSell(items[guiControl.trade.page])) ? "black" : "white", 6);
// Back Text
@ -275,16 +286,18 @@ function drawTradeGUI() {
OS.context.drawImage(guiControl.cursor, 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.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.
if (items.length > 0 && (guiControl.trade.island.timesHaggledToday <= G.stats.popularity) &&
guiControl.trade.island.haggleAmount == 0 && Math.floor(Math.randomRange(0, 100)) < G.stats.popularity) // If you haven't haggled yet and get a random number less than your popularity, haggle successfully.
{
guiControl.trade.haggleAmount = G.stats.haggling;
// Play Sell sound.
guiControl.trade.island.haggleAmount = G.stats.haggling;
} else {
// Play Cannot_Buy sound.
guiControl.trade.island.timesHaggledToday++;
}
break;
case 1: // Sell
@ -298,19 +311,21 @@ function drawTradeGUI() {
break;
default:
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 1; // The position where "Sell" is on main screen.
break;
}
// Play Select sound.
// console.log(guiControl.trade.screen);
}
if (ct_cancel().down) {
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 == "gossip") {
// console.log(guiControl.trade.screen);
// Limit Cursor
@ -333,11 +348,13 @@ function drawTradeGUI() {
OS.context.drawImage(guiControl.cursor, 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) {
guiControl.trade.screen = "main";
guiControl.trade.cursorPosition = 2;
// Play Select sound.
// console.log(guiControl.trade.screen);
guiControl.trade.screen = "main";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 2;
}
}
}
}

View File

@ -1,5 +1,6 @@
function loadGUIs() {
OS.AddScript("gui/inventoryGUI.js");
OS.AddScript("gui/mapGUI.js");
OS.AddScript("gui/tradeGUI.js");
}

View File

@ -1,8 +1,8 @@
// var rm_TitleScreen = OS.R.Add("Default");
// var rm_Ocean = OS.R.Add("Ocean", {
var rm_Ocean = OS.R.Add("Default", {
width: pixel(64) * 50, //50x50 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) * 50,
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"
});

View File

@ -14,6 +14,8 @@ var pr_island = OS.P.Add("Island", {
mapColor: "#00AB00",
canTrade: true,
haggleAmount: 0,
timesHaggledToday: 0,
inventory: [0, 0, 0, 0,
0, 0, 0, 0,

View File

@ -26,9 +26,13 @@ var pr_ship = OS.P.Add("Ship", {
energyRefillTimer: 0
});
pr_ship.BeforeDo = function () {
this.GetMapPosition();
}
pr_ship.Do = function () {
if (guiControl && guiControl.inventory && guiControl.trade) { // Force it to wait until loaded.
if (!guiControl.inventory.show && !guiControl.trade.show) {
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) {
@ -67,6 +71,12 @@ pr_ship.AfterDo = function () {
this.UpdateEnergy();
}
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);
}
pr_ship.CheckInteraction = function () {
if (ct_confirm().down) {
var objectsFound = OS.GameObjectsAtPoint(this.pointInFront.x, this.pointInFront.y);

View File

@ -22,7 +22,7 @@ rm_Ocean.clockImg.src = "images/clock_sheet.png";
rm_Ocean.DoFirst = function () {
G.player.x = (pixel(64) * 25) - pixel(32) - G.player.xBound;
G.player.y = pixel(64) * 25;
G.player.y = pixel(64) * 22;
console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y);
G.oceanParticle.x = G.player.x + randomSmidge();
@ -60,14 +60,11 @@ rm_Ocean.Do = function () {
}
if (guiControl && guiControl.inventory && guiControl.trade) { // Force it to wait until loaded.
if (!guiControl.inventory.show && !guiControl.trade.show) {
if (!guiControl.inventory.show && !guiControl.map.show && !guiControl.trade.show) {
if (ct_cancel().down) {
guiControl.inventory.activateDelay = 5;
guiControl.inventory.show = true;
}
if (ct_esc.down) {
guiControl.trade.show = true;
G.player.speed = 0;
}
}
}
}
@ -113,6 +110,8 @@ rm_Ocean.DrawClock = function () {
G.economy.UpdateEconomy();
for (var i = 0; i < G.map.length; i++) {
G.map[i].island.haggleAmount = 0;
G.map[i].island.timesHaggledToday = 0;
G.map[i].island.SimulateTrade();
}
}
@ -129,21 +128,21 @@ rm_Ocean.DrawClock = function () {
rm_Ocean.GenerateMap = function () {
var island1 = rm_Ocean.AddObject(OS.P["Island"], {
x: pixel(64) * 25, //Exact center of map.
y: pixel(64) * 25
y: pixel(64) * 22
});
console.log(island1.name + " created at " + island1.x + ", " + island1.y);
G.map.push({
island: island1,
drawX: 25,
drawY: 25,
drawY: 22,
drawWidth: 1,
drawHeight: 1
});
var usedXSquares = [];
var usedYSquares = [];
for (var i = 0; i < 5; i++) {
for (var i = 0; i < 9; i++) {
var xSquare = Math.round(Math.randomRange(1, 49));
while (usedXSquares.indexOf(xSquare) != -1 &&
usedXSquares.indexOf(xSquare + 1) != -1 && usedXSquares.indexOf(xSquare - 1) != -1 &&
@ -153,7 +152,7 @@ rm_Ocean.GenerateMap = function () {
}
usedXSquares.push(xSquare);
var ySquare = Math.round(Math.randomRange(1, 49));
var ySquare = Math.round(Math.randomRange(1, 43));
while (usedYSquares.indexOf(ySquare) != -1 &&
usedYSquares.indexOf(ySquare + 1) != -1 && usedYSquares.indexOf(ySquare - 1) != -1 &&
usedYSquares.indexOf(ySquare + 2) != -1 && usedYSquares.indexOf(ySquare - 2) != -1)

View File

@ -1,5 +1,5 @@
OS.S.defaultStep = 1 / 120;
OS.S.numberOfScriptsToLoad = 13; // Excludes the titleScreen.js room, which is not loaded yet.
OS.S.numberOfScriptsToLoad = 14; // Excludes the titleScreen.js room, which is not loaded yet.
OS.S.pixelScale = 4;
OS.SetCamera({
width: pixel(64),