From 9ad26265d134b24208d02fa7120689e7a7185dad Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Fri, 8 Apr 2016 00:19:55 -0600 Subject: [PATCH] Setting up island economy functions. --- loadControls.js | 18 ++++++++++++++ prefabs/islandPrefab.js | 53 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/loadControls.js b/loadControls.js index b8a052c..7b18fe7 100644 --- a/loadControls.js +++ b/loadControls.js @@ -9,6 +9,8 @@ var ct_arrow_right = OS.C.Add("Arrow Right", OS.Keycode.right); var ct_shift = OS.C.Add("Shift", OS.Keycode.shift); var ct_space = OS.C.Add("Confirm", OS.Keycode.space); +var ct_z = OS.C.Add("Shift", OS.Keycode.z); +var ct_x = OS.C.Add("Confirm", OS.Keycode.x); var ct_esc = OS.C.Add("Cancel", OS.Keycode.escape); function loadControls () {} @@ -44,3 +46,19 @@ function ct_right () { 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 + } +} + +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 + } +} diff --git a/prefabs/islandPrefab.js b/prefabs/islandPrefab.js index d336b0e..cdf8e4c 100644 --- a/prefabs/islandPrefab.js +++ b/prefabs/islandPrefab.js @@ -5,5 +5,56 @@ function islandPrefab() {} var pr_island = OS.P.Add("Island", { solid: true, imageSrc: "images/island.png", - animations: [ani_island_1] + animations: [ani_island_1], + + mapX: 0, + mapY: 0, + mapWidth: 1, + mapHeight: 1, + mapColor: "#00AB00", + + priceDifferences: [], + 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], }); + +pr_island.DoFirst = function () { + this.GetMapPosition(); + this.SetUpPrices(); +} + +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); +} + +pr_island.SetUpPrices = function () { + for (var i = 0; i < 15; i++) { + this.priceDifferences[i] = Math.randomRange(-100, 100); + } +} + +pr_island.AdjustPrices = function () { + for (var i = 0; i < 15; i++) { + var saleDifference = this.itemsSold[i] - this.itemsBought[i]; + if (saleDifference = 0) { + this.priceDifferences[i] += Math.round(Math.randomRange(-1, 1)) * 5; + } else { + this.priceDifferences[i] += saleDifference * 5; + } + } +} + +pr_island.SellTo = function (itemIndex, amount) { + this.itemsBought[itemIndex] += amount; +} + +pr_island.BuyFrom = function (itemIndex, amount) { + this.itemsSold[itemIndex] += amount; +}