Procedurally generate islands and update economy on a timer.
This commit is contained in:
parent
f8e2fa3cb9
commit
d86b36883d
Binary file not shown.
After Width: | Height: | Size: 749 B |
Binary file not shown.
|
@ -91,14 +91,18 @@ G.economy = { // Aww yea, supply and demand.
|
|||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0],
|
||||
CheckEconomy: function () {
|
||||
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++) {
|
||||
totalPriceDifference += G.map.island.priceDifferences[i];
|
||||
// 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.
|
||||
}
|
||||
// console.log(G.economy.cargoItemWorth);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -15,7 +15,10 @@ var pr_island = OS.P.Add("Island", {
|
|||
|
||||
canTrade: true,
|
||||
|
||||
inventory: [],
|
||||
inventory: [0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0],
|
||||
priceDifferences: [],
|
||||
itemsSold: [0, 0, 0, 0, // The more you sell, the lower the price gets
|
||||
0, 0, 0, 0,
|
||||
|
@ -43,8 +46,10 @@ pr_island.SetUp = function () {
|
|||
this.inventory[i] = Math.round(Math.randomRange(0, 20));
|
||||
}
|
||||
}
|
||||
// console.log(this.name + " stock: " + this.inventory);
|
||||
|
||||
this.AdjustPrices();
|
||||
// console.log(this.name + " pricing: " + this.priceDifferences);
|
||||
|
||||
if (this.CheckInventory().length < 4) {
|
||||
this.SetUp();
|
||||
|
@ -58,7 +63,7 @@ pr_island.AdjustPrices = function () {
|
|||
} else if (this.inventory[i] < 5) {
|
||||
this.priceDifferences[i] = Math.round((10 - this.inventory[i]) * Math.randomRange(1, 3));
|
||||
} else {
|
||||
this.priceDifferences[i] = 0;
|
||||
this.priceDifferences[i] = Math.round(Math.randomRange(-2, 2));
|
||||
}
|
||||
|
||||
if (G.economy.cargoItemWorth[i] + this.priceDifferences[i] < 0) {
|
||||
|
@ -97,7 +102,8 @@ pr_island.CheckInventory = function () { // Returns an array of indices that hav
|
|||
|
||||
pr_island.TradeWith = function () {
|
||||
// Change music to Trade.
|
||||
guiControl.trade.island = this.self;
|
||||
// console.log(this.inventory);
|
||||
guiControl.trade.island = this;
|
||||
guiControl.trade.haggleAmount = 0;
|
||||
guiControl.trade.activateDelay = 5;
|
||||
guiControl.trade.show = true;
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
function oceanRoom () {
|
||||
// Create objects on room creation for persistence.
|
||||
G.player = rm_Ocean.AddObject(OS.P["Ship"]);
|
||||
G.player.x = (pixel(64) * 25) - pixel(32) - G.player.xBound;
|
||||
G.player.y = pixel(64) * 25;
|
||||
console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y);
|
||||
G.oceanParticle = rm_Ocean.AddObject(OS.P["Ocean Particle"]);
|
||||
G.oceanParticle.x = G.player.x + randomSmidge();
|
||||
G.oceanParticle.y = G.player.y + randomSmidge();
|
||||
|
||||
rm_Ocean.GenerateMap();
|
||||
|
||||
|
||||
// When room is loaded, explicitly set room to rm_Ocean, just in case "Default" doesn't work/is loaded too slowly
|
||||
// to make sure DoFirst runs.
|
||||
OS.SetRoom(rm_Ocean);
|
||||
|
@ -19,8 +14,20 @@ rm_Ocean.waveTimer = Math.round(Math.randomRange(30, 150));
|
|||
rm_Ocean.speedGaugeImg = new Image();
|
||||
rm_Ocean.speedGaugeImg.src = "images/speed_gauge_sheet.png";
|
||||
|
||||
rm_Ocean.clockTimerCutoff = (1 / OS.S.defaultStep) * 60 * 10; // 10 minute day.
|
||||
rm_Ocean.clockTimerCount = 0;
|
||||
rm_Ocean.clockImg = new Image();
|
||||
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;
|
||||
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();
|
||||
|
||||
// Reset camera whenever room starts
|
||||
OS.SetCamera({
|
||||
x: G.player.x - (OS.camera.width / 2),
|
||||
|
@ -36,6 +43,8 @@ rm_Ocean.DoFirst = function () {
|
|||
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();
|
||||
}
|
||||
rm_Ocean.Do = function () {
|
||||
// Move G.oceanParticle around based on player's movement.
|
||||
|
@ -67,12 +76,14 @@ rm_Ocean.DrawAbove = function () {
|
|||
// Draw the speed indicator in Bottom Left corner.
|
||||
OS.context.drawImage(rm_Ocean.speedGaugeImg, G.player.currentSpeed * 32, 0, 32, 32, 16, OS.camera.height - 32 - 16, 32, 32);
|
||||
|
||||
// Draw Energy Bar
|
||||
this.DrawEnergyBar();
|
||||
|
||||
this.DrawClock();
|
||||
|
||||
// drawPixelText("Testing 1 2 3!", 0, 0, 0, "white", 4);
|
||||
// drawPixelText("Testing 1 2 3!", 0, 64, 0, "white", 6);
|
||||
drawInventoryGUI();
|
||||
drawMapGUI();
|
||||
drawTradeGUI();
|
||||
}
|
||||
|
||||
|
@ -93,6 +104,28 @@ rm_Ocean.DrawEnergyBar = function () {
|
|||
OS.context.fillStyle = saveFillStyle;
|
||||
}
|
||||
|
||||
rm_Ocean.DrawClock = 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();
|
||||
|
||||
for (var i = 0; i < G.map.length; i++) {
|
||||
G.map[i].island.SimulateTrade();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var screenX = OS.camera.width - pixel(9) - pixel(2);
|
||||
var screenY = OS.camera.height - pixel(9) - pixel(2);
|
||||
var percentOfClock = rm_Ocean.clockTimerCount / rm_Ocean.clockTimerCutoff;
|
||||
var clockFrameX = Math.floor(16 * percentOfClock) * pixel(9);
|
||||
OS.context.drawImage(rm_Ocean.clockImg, clockFrameX, 0, pixel(9), pixel(9), screenX, screenY, pixel(9), pixel(9));
|
||||
// console.log(rm_Ocean.clockTimerCount);
|
||||
}
|
||||
|
||||
rm_Ocean.GenerateMap = function () {
|
||||
var island1 = rm_Ocean.AddObject(OS.P["Island"], {
|
||||
x: pixel(64) * 25, //Exact center of map.
|
||||
|
@ -101,7 +134,11 @@ rm_Ocean.GenerateMap = function () {
|
|||
|
||||
console.log(island1.name + " created at " + island1.x + ", " + island1.y);
|
||||
G.map.push({
|
||||
island: island1
|
||||
island: island1,
|
||||
drawX: 25,
|
||||
drawY: 25,
|
||||
drawWidth: 1,
|
||||
drawHeight: 1
|
||||
});
|
||||
|
||||
var usedXSquares = [];
|
||||
|
@ -134,7 +171,9 @@ rm_Ocean.GenerateMap = function () {
|
|||
y: yPosition
|
||||
}),
|
||||
drawX: xSquare,
|
||||
drawY: ySquare
|
||||
drawY: ySquare,
|
||||
drawWidth: 1,
|
||||
drawHeight: 1
|
||||
});
|
||||
console.log(G.map[i + 1].island.name + " created at " + G.map[i + 1].island.x + ", " + G.map[i + 1].island.y);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue