Added checks to make sure objects exist before trying to reference them.

This commit is contained in:
Robbie Antenesse 2016-04-14 14:58:19 -06:00
parent 5224f69de2
commit f8e2fa3cb9
5 changed files with 33 additions and 25 deletions

View file

@ -7,7 +7,7 @@ function inventoryGUI() {
} }
function drawInventoryGUI() { function drawInventoryGUI() {
if (guiControl.inventory.show) { if (guiControl.inventory && guiControl.inventory.show) {
OS.context.drawImage(guiControl.background, 0, 0, 240, 240, pixel(2), pixel(2), 240, 240); OS.context.drawImage(guiControl.background, 0, 0, 240, 240, pixel(2), pixel(2), 240, 240);
if (ct_down().down) { if (ct_down().down) {

View file

@ -20,8 +20,10 @@ function tradeGUI() {
} }
function drawTradeGUI() { function drawTradeGUI() {
if (guiControl.trade.show) { if (guiControl.trade && guiControl.trade.show) {
guiControl.trade.activateDelay -= (guiControl.trade.activateDelay > 0) ? 1 : 0; guiControl.trade.activateDelay -= (guiControl.trade.activateDelay > 0) ? 1 : 0;
// console.log("trade screen island: " + guiControl.trade.island.name);
// Draw background color.
var tmp = Oversimplified.context.fillStyle; var tmp = Oversimplified.context.fillStyle;
Oversimplified.context.fillStyle = "#D9BEA5"; Oversimplified.context.fillStyle = "#D9BEA5";
Oversimplified.context.fillRect(0, 0, Oversimplified.camera.width, Oversimplified.camera.height); Oversimplified.context.fillRect(0, 0, Oversimplified.camera.width, Oversimplified.camera.height);

View file

@ -27,22 +27,24 @@ var pr_ship = OS.P.Add("Ship", {
}); });
pr_ship.Do = function () { pr_ship.Do = function () {
if (!guiControl.inventory.show && !guiControl.trade.show) { if (guiControl && guiControl.inventory && guiControl.trade) { // Force it to wait until loaded.
if (ct_left().down) { if (!guiControl.inventory.show && !guiControl.trade.show) {
this.direction += 45; if (ct_left().down) {
} else if (ct_right().down) { this.direction += 45;
this.direction -= 45; } else if (ct_right().down) {
} this.direction -= 45;
this.direction = Math.clampAngle(this.direction); }
this.direction = Math.clampAngle(this.direction);
if (ct_up().down) {
this.currentSpeed++; if (ct_up().down) {
} else if (ct_down().down) { this.currentSpeed++;
this.currentSpeed--; } else if (ct_down().down) {
} this.currentSpeed--;
this.AdjustSpeedBasedOnEnergy(); }
this.AdjustSpeedBasedOnEnergy();
this.CheckInteraction(); this.CheckInteraction();
}
} }
this.currentSpeed = Math.clamp(this.currentSpeed, 0, 4); this.currentSpeed = Math.clamp(this.currentSpeed, 0, 4);
@ -71,6 +73,7 @@ pr_ship.CheckInteraction = function () {
if (objectsFound.length > 0) { if (objectsFound.length > 0) {
for (var i = 0; i < objectsFound.length; i++) { for (var i = 0; i < objectsFound.length; i++) {
if (objectsFound[i].canTrade) { if (objectsFound[i].canTrade) {
// console.log("interacting with island: " + objectsFound[i].name);
objectsFound[i].TradeWith(); objectsFound[i].TradeWith();
} }
} }

View file

@ -39,7 +39,7 @@ rm_Ocean.DoFirst = function () {
} }
rm_Ocean.Do = function () { rm_Ocean.Do = function () {
// Move G.oceanParticle around based on player's movement. // Move G.oceanParticle around based on player's movement.
G.oceanParticle.CheckPosition(G.player.x, G.player.y, G.player.direction); if (G.oceanParticle.CheckPosition) G.oceanParticle.CheckPosition(G.player.x, G.player.y, G.player.direction);
this.waveTimer--; this.waveTimer--;
if (this.waveTimer <= 0) { if (this.waveTimer <= 0) {
@ -50,13 +50,15 @@ rm_Ocean.Do = function () {
this.waveTimer = Math.round(Math.randomRange(30, 150)); this.waveTimer = Math.round(Math.randomRange(30, 150));
} }
if (!guiControl.inventory.show && !guiControl.trade.show) { if (guiControl && guiControl.inventory && guiControl.trade) { // Force it to wait until loaded.
if (ct_cancel().down) { if (!guiControl.inventory.show && !guiControl.trade.show) {
guiControl.inventory.show = true; if (ct_cancel().down) {
} guiControl.inventory.show = true;
if (ct_esc.down) { }
guiControl.trade.show = true; if (ct_esc.down) {
G.player.speed = 0; guiControl.trade.show = true;
G.player.speed = 0;
}
} }
} }
} }

View file

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