Everything having to do with sickness and healing. Plus some unnecessary spaces on the Title screen.

This commit is contained in:
Robbie Antenesse 2016-04-15 23:15:38 -06:00
parent 55ce2e7c1f
commit 69888da3c6
8 changed files with 208 additions and 88 deletions

View File

@ -38,12 +38,12 @@ function drawInventoryGUI() {
// 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);
// Supplies icon
guiControl.drawIcon(9, 2, guiControl.leftBorder, guiControl.rowTop(1));
guiControl.drawPixelText(G.inventory.supplies.toString(), guiControl.leftBorder + pixel(guiControl.iconSize + 4), guiControl.rowTop(1) + pixel(), 8, "black", 6);
// Cargo icon
guiControl.drawIcon(1, 0, guiControl.leftBorder, guiControl.rowTop(2));
guiControl.drawPixelText(G.inventory.CargoTotal().toString(), guiControl.leftBorder + pixel(guiControl.iconSize + 4), guiControl.rowTop(2) + pixel(), 8, "black", 6);
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);
@ -59,10 +59,10 @@ function drawInventoryGUI() {
guiControl.inventory.screen = "money";
break;
case 1:
guiControl.inventory.screen = "supplies";
guiControl.inventory.screen = "cargo";
break;
case 2:
guiControl.inventory.screen = "cargo";
guiControl.inventory.screen = "status";
break;
default:
guiControl.inventory.show = false;
@ -97,7 +97,7 @@ function drawInventoryGUI() {
}
// Title
guiControl.drawPixelText("Money", guiControl.leftBorder - pixel(2), guiControl.topOfBackground, 8, "black", 6);
guiControl.drawPixelText("Money", guiControl.leftBorder + pixel(3), guiControl.topOfBackground, 8, "black", 6);
guiControl.drawPixelText("Actual Amt", guiControl.leftBorder - pixel(5), guiControl.rowTop(0) + pixel(), 10, "black", 4);
// Money icon
@ -119,63 +119,6 @@ function drawInventoryGUI() {
}
}
}
else if (guiControl.inventory.screen == "supplies") {
// Limit Cursor
if (guiControl.inventory.cursorPosition < 0) {
guiControl.inventory.cursorPosition = 2;
}
if (guiControl.inventory.cursorPosition > 2) {
guiControl.inventory.cursorPosition = 0;
}
// Title
guiControl.drawPixelText("Supplies", guiControl.leftBorder - pixel(6), guiControl.topOfBackground, 8, "black", 6);
guiControl.drawPixelText("Heal Crew?", guiControl.leftBorder - pixel(5), guiControl.rowTop(0) + pixel(), 10, "black", 4);
// Supplies icon
guiControl.drawIcon(9, 2, guiControl.leftBorder - pixel(5), guiControl.rowTop(1) - pixel(3));
guiControl.drawPixelText(G.inventory.supplies.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(guiControl.inventory.cursorPosition + 2) - pixel(4));
// Button Action
if (guiControl.inventory.activateDelay <= 0) {
if (ct_confirm().down) {
switch (guiControl.inventory.cursorPosition) {
case 1:
if (G.inventory.supplies > 0 && G.stats.illness > 0) { //If cursor is over yes, heal illness with supplies.
G.inventory.supplies--;
G.stats.illness--;
}
break;
default:
guiControl.inventory.screen = "main";
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) {
@ -186,7 +129,7 @@ function drawInventoryGUI() {
}
// Title
guiControl.drawPixelText("Cargo", guiControl.leftBorder - pixel(2), guiControl.topOfBackground, 8, "black", 6);
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
@ -206,7 +149,53 @@ function drawInventoryGUI() {
if (ct_confirm().down || ct_cancel().down) {
guiControl.inventory.screen = "main";
guiControl.inventory.activateDelay = 5;
guiControl.inventory.cursorPosition = 2;
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);
// 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);
// 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) {
guiControl.inventory.screen = "main";
guiControl.inventory.activateDelay = 5;
guiControl.inventory.cursorPosition = 2; // The position where "Supplies" is on main screen.
}
}
}

View File

@ -72,7 +72,7 @@ function drawTradeGUI() {
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("Gossip", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) + pixel(), 8, "black", 6);
guiControl.drawPixelText("Tavern", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) + pixel(), 8, "black", 6);
// Close Text
guiControl.drawPixelText("Leave", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) + pixel(), 8, "black", 6);
@ -102,7 +102,7 @@ function drawTradeGUI() {
}
break;
case 2:
guiControl.trade.screen = "gossip";
guiControl.trade.screen = "tavern";
guiControl.trade.activateDelay = 5;
break;
default:
@ -326,6 +326,72 @@ function drawTradeGUI() {
}
}
}
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);
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));
// Button Action
if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down) {
switch (guiControl.trade.cursorPosition) {
case 0:
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.
guiControl.trade.island.StayAtInn();
} else {
// Play Cant_Buy sound.
}
break;
default:
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;
}
if (ct_cancel().down) {
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
@ -351,9 +417,9 @@ function drawTradeGUI() {
if (guiControl.trade.activateDelay <= 0) {
if (ct_confirm().down || ct_cancel().down) {
// Play Select sound.
guiControl.trade.screen = "main";
guiControl.trade.screen = "tavern";
guiControl.trade.activateDelay = 5;
guiControl.trade.cursorPosition = 2;
guiControl.trade.cursorPosition = 0;
}
}
}

View File

@ -79,6 +79,8 @@ G.stats = {
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,
@ -102,6 +104,11 @@ G.economy = { // Aww yea, supply and demand.
}
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);
}
};

View File

@ -22,6 +22,8 @@ var pr_island = OS.P.Add("Island", {
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
innPriceDifference: 0,
innStays: 0,
priceDifferences: [],
itemsSold: [0, 0, 0, 0, // The more you sell, the lower the price gets
0, 0, 0, 0,
@ -73,6 +75,9 @@ pr_island.AdjustPrices = function () {
this.priceDifferences[i] = -G.economy.cargoItemWorth[i] + 1;
}
}
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 () {
@ -93,6 +98,12 @@ pr_island.SimulateTrade = function () {
this.AdjustPrices();
}
pr_island.NewDay = function () {
this.haggleAmount = 0;
this.timesHaggledToday = 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++) {
@ -131,3 +142,12 @@ pr_island.BuyFrom = function (itemIndex, price) {
G.inventory.money -= price;
G.economy.cargoBought[itemIndex]++;
}
pr_island.StayAtInn = function () {
// Play Sell sound.
this.innStays++;
G.stats.illness--;
G.inventory.money -= G.economy.innCost + this.innPriceDifference;
G.economy.innStays++;
}

View File

@ -23,7 +23,10 @@ var pr_ship = OS.P.Add("Ship", {
moveStepProgress: 0,
doTakeStep: false,
energyRefillTimer: 0
energyRefillTimer: 0,
drawSickIndicator: 0,
drawSickIndicatorTime: secondsWorthOfFrames(1.5)
});
pr_ship.BeforeDo = function () {
@ -71,6 +74,18 @@ pr_ship.AfterDo = function () {
this.UpdateEnergy();
}
pr_ship.DrawAbove = function () {
this.drawSickIndicator--;
if (this.drawSickIndicator < 0) {
this.drawSickIndicator = 0;
}
if (this.drawSickIndicator > 0) {
var sickIndicatorHeight = Math.round((this.drawSickIndicatorTime - this.drawSickIndicator) / 2) / OS.S.pixelScale;
var sickIndicatorY = this.y - sickIndicatorHeight - Oversimplified.camera.y - (guiControl.iconScaled / 2);
guiControl.drawIcon(4, 1, this.x - Oversimplified.camera.x - (guiControl.iconScaled / 2), sickIndicatorY);
}
}
pr_ship.GetMapPosition = function () {
this.mapX = pixel(Math.round(this.x / pixel(64)));
this.mapY = pixel(Math.round(this.y / pixel(64)));
@ -195,3 +210,12 @@ pr_ship.AdjustSpeedBasedOnEnergy = function () {
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) {
// Play Illness sound.
G.stats.illness++;
this.drawSickIndicator += secondsWorthOfFrames(1.5);
}
}

View File

@ -11,7 +11,7 @@ function oceanRoom () {
}
rm_Ocean.waveTimer = Math.round(Math.randomRange(30, 150));
rm_Ocean.clockTimerCount = 0;
rm_Ocean.clockTimerCount = 1; // Set it to 1 so it doesn't check for player illness immediately!
rm_Ocean.DoFirst = function () {
G.player.x = (this.squareSize * (this.squaresX / 2)) - (this.squareSize / 2) - G.player.xBound;
@ -95,11 +95,15 @@ rm_Ocean.RunClock = 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();
G.map[i].island.NewDay();
}
}
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();
}
}
}

View File

@ -12,6 +12,8 @@ rm_TitleScreen.DrawBelow = function () {
Oversimplified.context.fillStyle = "#D9BEA5";
Oversimplified.context.fillRect(0, 0, Oversimplified.camera.width, Oversimplified.camera.height);
Oversimplified.context.fillStyle = tmp;
}
rm_TitleScreen.DoLast = function () {
// Clear Objects on room exit. This is best practice unless you need persistent objects.

View File

@ -21,7 +21,15 @@ function pixel(number) {
return ((typeof number !== 'undefined') ? number : 1) * OS.S.pixelScale;
}
function secondsWorthOfFrames(seconds) {
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))));
}
function sortNumber(a, b) {
return a - b;
}