Started work on Trade interaction.

This commit is contained in:
Robbie Antenesse 2016-04-12 10:02:27 -06:00
parent 1e2638c1f0
commit 4cee4c49b6
6 changed files with 78 additions and 39 deletions

View File

@ -2,28 +2,7 @@ function inventoryGUI() {
guiControl.inventory = {
screen: "main",
cursorPosition: 0,
show: false,
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;
}
show: false
}
}
@ -41,17 +20,17 @@ function drawInventoryGUI() {
if (guiControl.inventory.screen == "main") {
// Limit Cursor
if (guiControl.inventory.cursorPosition < 0) {
guiControl.inventory.cursorPosition = 0;
guiControl.inventory.cursorPosition = 3;
}
if (guiControl.inventory.cursorPosition > 3) {
guiControl.inventory.cursorPosition = 3;
guiControl.inventory.cursorPosition = 0;
}
// Title
guiControl.drawPixelText("Storage", guiControl.leftBorder - (2 * OS.S.pixelScale), guiControl.topOfBackground, 8, "black", 6);
// Money icon
guiControl.drawIcon(7, 2, guiControl.leftBorder, guiControl.rowTop(0));
guiControl.drawPixelText(guiControl.inventory.moneyDisplay(), guiControl.leftBorder + ((guiControl.iconSize + 4) * OS.S.pixelScale), guiControl.rowTop(0) + OS.S.pixelScale, 8, "black", 6);
guiControl.drawPixelText(G.inventory.moneyDisplay(), guiControl.leftBorder + ((guiControl.iconSize + 4) * OS.S.pixelScale), guiControl.rowTop(0) + OS.S.pixelScale, 8, "black", 6);
// Supplies icon
guiControl.drawIcon(9, 2, guiControl.leftBorder, guiControl.rowTop(1));
guiControl.drawPixelText(G.inventory.supplies.toString(), guiControl.leftBorder + ((guiControl.iconSize + 4) * OS.S.pixelScale), guiControl.rowTop(1) + OS.S.pixelScale, 8, "black", 6);
@ -117,10 +96,10 @@ function drawInventoryGUI() {
else if (guiControl.inventory.screen == "supplies") {
// Limit Cursor
if (guiControl.inventory.cursorPosition < 0) {
guiControl.inventory.cursorPosition = 0;
guiControl.inventory.cursorPosition = 2;
}
if (guiControl.inventory.cursorPosition > 2) {
guiControl.inventory.cursorPosition = 2;
guiControl.inventory.cursorPosition = 0;
}
// Title

View File

@ -2,7 +2,9 @@ function tradeGUI() {
guiControl.trade = {
screen: "main", // "main", "buy", "sell", "gossip"
cursorPosition: 0,
scroll: 0, // horizontal scroll on item lists.
show: false,
activateDelay: 0,
island: null,
@ -17,6 +19,7 @@ function tradeGUI() {
function drawTradeGUI() {
if (guiControl.trade.show) {
guiControl.trade.activateDelay--;
var tmp = Oversimplified.context.fillStyle;
Oversimplified.context.fillStyle = "#D9BEA5";
Oversimplified.context.fillRect(0, 0, Oversimplified.camera.width, Oversimplified.camera.height);
@ -32,10 +35,10 @@ function drawTradeGUI() {
if (guiControl.trade.screen == "main") {
// Limit Cursor
if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 0;
guiControl.trade.cursorPosition = 3;
}
if (guiControl.trade.cursorPosition > 3) {
guiControl.trade.cursorPosition = 3;
guiControl.trade.cursorPosition = 0;
}
// Title
@ -57,7 +60,7 @@ function drawTradeGUI() {
OS.context.drawImage(guiControl.cursor, guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition));
// Button Action
if (ct_confirm().down) {
if (guiControl.trade.activateDelay <= 0 && ct_confirm().down) {
switch (guiControl.trade.cursorPosition) {
case 0:
guiControl.trade.screen = "buy";
@ -88,10 +91,19 @@ function drawTradeGUI() {
// Title
guiControl.drawPixelText("Buy", guiControl.trade.leftBorder - (2 * OS.S.pixelScale), guiControl.topOfBackground, 10, "black", 6);
guiControl.drawPixelText("Actual Amt", guiControl.trade.leftBorder - (5 * OS.S.pixelScale), guiControl.trade.rowTop(0) + OS.S.pixelScale, 10, "black", 4);
// Money icon
guiControl.drawIcon(7, 2, guiControl.trade.leftBorder - (5 * OS.S.pixelScale), guiControl.trade.rowTop(1) - (3 * OS.S.pixelScale));
guiControl.drawPixelText(G.inventory.money.toString(), guiControl.trade.leftBorder - (5 * OS.S.pixelScale) + ((guiControl.iconSize + 2) * OS.S.pixelScale), guiControl.trade.rowTop(1) + (2 * OS.S.pixelScale) - (3 * OS.S.pixelScale), 10, "black", 4);
guiControl.drawIcon(7, 2, guiControl.trade.leftBorder - (5 * OS.S.pixelScale), guiControl.trade.rowTop(0) - (3 * OS.S.pixelScale));
guiControl.drawPixelText(G.inventory.moneyDisplay(), guiControl.trade.leftBorder - (5 * OS.S.pixelScale) + ((guiControl.iconSize + 2) * OS.S.pixelScale), guiControl.trade.rowTop(0) + (2 * OS.S.pixelScale) - (3 * OS.S.pixelScale), 10, "black", 4);
// Cargo icons
var cargo = guiControl.trade.island.CheckInventory(); // Contains the item ids that have more than 1 item
for (var i = 0; i < cargo.length; i++) {
guiControl.drawItem(cargo[i], guiControl.trade.leftBorder, guiControl.trade.rowTop(i + 1));
var itemPrice = G.economy.cargoItemWorth[cargo[i]] + guiControl.trade.island.priceDifferences[cargo[i]];
var itemPriceDisplay = itemPrice.toString() + " c";
guiControl.drawPixelText(itemPriceDisplay, guiControl.trade.leftBorder + ((guiControl.iconSize + 4) * OS.S.pixelScale), guiControl.trade.rowTop(i + 1) + OS.S.pixelScale, 8, "black", 6);
// guiControl.drawPixelText(guiControl.trade.island.inventory[cargo[i]], guiControl.trade.leftBorder + ((guiControl.iconSize + 4) * OS.S.pixelScale), guiControl.trade.rowTop(i + 1) + OS.S.pixelScale, 8, "black", 6);
}
// Back Text
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - (3 * OS.S.pixelScale), 8, "black", 6);
@ -108,10 +120,10 @@ function drawTradeGUI() {
else if (guiControl.trade.screen == "sell") {
// Limit Cursor
if (guiControl.trade.cursorPosition < 0) {
guiControl.trade.cursorPosition = 0;
guiControl.trade.cursorPosition = 2;
}
if (guiControl.trade.cursorPosition > 2) {
guiControl.trade.cursorPosition = 2;
guiControl.trade.cursorPosition = 0;
}
// Title

View File

@ -12,6 +12,26 @@ G.inventory = {
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++) {

View File

@ -13,6 +13,8 @@ var pr_island = OS.P.Add("Island", {
mapHeight: 1,
mapColor: "#00AB00",
canTrade: true,
inventory: [],
priceDifferences: [],
itemsSold: [0, 0, 0, 0, // The more you sell, the lower the price gets
@ -27,7 +29,7 @@ var pr_island = OS.P.Add("Island", {
pr_island.DoFirst = function () {
this.GetMapPosition();
this.SetUpPrices();
this.SetUp();
}
pr_island.GetMapPosition = function () {
@ -38,7 +40,10 @@ pr_island.GetMapPosition = function () {
pr_island.SetUp = function () {
for (var i = 0; i < 15; i++) {
this.inventory[i] = Math.round(Math.randomRange(0, 20));
this.priceDifferences[i] = Math.round(Math.randomRange(-100, 100));
this.priceDifferences[i] = Math.round(Math.randomRange(-50, 50));
if (G.economy.cargoItemWorth[i] + this.priceDifferences[i]) {
this.priceDifferences[i] = -G.economy.cargoItemWorth[i] + 1;
}
}
}
@ -53,10 +58,28 @@ pr_island.AdjustPrices = function () {
}
}
pr_island.CheckInventory = function () { // Returns an array of indices that have cargo
var indicesWithCargo = [];
for (var i = 0; i < G.inventory.cargo.length; i++) {
if (this.inventory[i] > 0) {
indicesWithCargo.push(i);
}
}
return indicesWithCargo;
}
pr_island.TradeWith = function () {
guiControl.trade.island = this.self;
guiControl.trade.activateDelay = 5;
guiControl.trade.show = true;
}
pr_island.SellTo = function (itemIndex, amount) {
this.inventory[itemIndex] += amount;
this.itemsBought[itemIndex] += amount;
}
pr_island.BuyFrom = function (itemIndex, amount) {
this.inventory[itemIndex] += amount;
this.itemsSold[itemIndex] += amount;
}

View File

@ -41,6 +41,8 @@ pr_ship.Do = function () {
this.currentSpeed--;
}
this.AdjustSpeedBasedOnEnergy();
this.CheckInteraction();
}
this.currentSpeed = Math.clamp(this.currentSpeed, 0, 4);
@ -53,6 +55,7 @@ pr_ship.Do = function () {
this.doTakeStep = false;
}
this.SeamlessScroll();
// console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y);
}
@ -68,7 +71,7 @@ pr_ship.CheckInteraction = function () {
if (objectsFound.length > 0) {
for (var i = 0; i < objectsFound.length; i++) {
if (objectsFound[i].canTrade) {
// open the trading screen for the island.
objectsFound[i].TradeWith();
}
}
}

View File

@ -1,6 +1,8 @@
function tradeRoom () {}
rm_Trade.DoFirst = function () {}
rm_Trade.DoFirst = function () {
OS.canvas.style.background = this.background.color;
}
rm_Trade.Do = function () {}