2016-04-05 01:10:40 +02:00
|
|
|
function oceanRoom () {
|
2016-04-06 22:36:51 +02:00
|
|
|
// Create objects on room creation for persistence.
|
|
|
|
G.player = rm_Ocean.AddObject(OS.P["Ship"]);
|
2016-04-13 02:14:09 +02:00
|
|
|
G.player.x = pixel((rm_Ocean.width / OS.S.pixelScale) / 2);
|
|
|
|
G.player.y = pixel((rm_Ocean.height / OS.S.pixelScale) / 2);
|
2016-04-06 22:36:51 +02:00
|
|
|
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();
|
2016-04-13 02:14:09 +02:00
|
|
|
|
|
|
|
var island1 = rm_Ocean.AddObject(OS.P["Island"]);
|
|
|
|
island1.x = pixel((rm_Ocean.width / OS.S.pixelScale) / 2) + island1.xBound + G.player.xBound;
|
|
|
|
island1.y = pixel((rm_Ocean.height / OS.S.pixelScale) / 2);
|
|
|
|
console.log(island1.name + " created at " + island1.x + ", " + island1.y);
|
2016-04-06 22:36:51 +02:00
|
|
|
|
2016-04-05 01:10:40 +02:00
|
|
|
// When room is loaded, explicitly set room to rm_Ocean, just in case "Default" doesn't work/is loaded too slowly
|
2016-04-06 22:36:51 +02:00
|
|
|
// to make sure DoFirst runs.
|
2016-04-05 01:10:40 +02:00
|
|
|
OS.SetRoom(rm_Ocean);
|
|
|
|
}
|
|
|
|
|
2016-04-06 16:01:52 +02:00
|
|
|
rm_Ocean.waveTimer = Math.round(Math.randomRange(30, 150));
|
|
|
|
rm_Ocean.speedGaugeImg = new Image();
|
|
|
|
rm_Ocean.speedGaugeImg.src = "images/speed_gauge_sheet.png";
|
|
|
|
|
2016-04-07 21:19:22 +02:00
|
|
|
|
2016-04-05 01:10:40 +02:00
|
|
|
rm_Ocean.DoFirst = function () {
|
2016-04-06 22:36:51 +02:00
|
|
|
// Reset camera whenever room starts
|
|
|
|
OS.SetCamera({
|
|
|
|
x: G.player.x - (OS.camera.width / 2),
|
|
|
|
y: G.player.y - (OS.camera.height / 2),
|
|
|
|
objectToFollow: G.player
|
|
|
|
});
|
2016-04-07 20:26:36 +02:00
|
|
|
|
|
|
|
this.mapLeftTrigger = OS.camera.hBorder;
|
|
|
|
this.mapLeftTriggerTarget = this.width - (OS.camera.width - OS.camera.hBorder);
|
|
|
|
this.mapRightTrigger = this.width - OS.camera.hBorder;
|
|
|
|
this.mapRightTriggerTarget = OS.camera.width - OS.camera.hBorder;
|
|
|
|
this.mapUpTrigger = OS.camera.vBorder;
|
|
|
|
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;
|
2016-04-05 01:10:40 +02:00
|
|
|
}
|
|
|
|
rm_Ocean.Do = function () {
|
2016-04-06 01:33:38 +02:00
|
|
|
// Move G.oceanParticle around based on player's movement.
|
2016-04-06 16:01:52 +02:00
|
|
|
G.oceanParticle.CheckPosition(G.player.x, G.player.y, G.player.direction);
|
|
|
|
|
|
|
|
this.waveTimer--;
|
|
|
|
if (this.waveTimer <= 0) {
|
|
|
|
var wave = this.AddObject(OS.P["Wave Particle"]);
|
|
|
|
wave.x = G.player.x + (randomSmidge() * 4);
|
|
|
|
wave.y = G.player.y + (randomSmidge() * 4);
|
|
|
|
|
|
|
|
this.waveTimer = Math.round(Math.randomRange(30, 150));
|
|
|
|
}
|
2016-04-12 00:22:56 +02:00
|
|
|
|
2016-04-12 06:47:01 +02:00
|
|
|
if (!guiControl.inventory.show && !guiControl.trade.show) {
|
|
|
|
if (ct_cancel().down) {
|
|
|
|
guiControl.inventory.show = true;
|
|
|
|
}
|
|
|
|
if (ct_esc.down) {
|
|
|
|
guiControl.trade.show = true;
|
|
|
|
G.player.speed = 0;
|
|
|
|
}
|
2016-04-12 02:06:06 +02:00
|
|
|
}
|
2016-04-05 01:10:40 +02:00
|
|
|
}
|
2016-04-06 01:33:38 +02:00
|
|
|
|
2016-04-05 01:10:40 +02:00
|
|
|
rm_Ocean.DrawAbove = function () {
|
2016-04-06 01:33:38 +02:00
|
|
|
// Draw the speed indicator in Bottom Left corner.
|
2016-04-06 16:01:52 +02:00
|
|
|
OS.context.drawImage(rm_Ocean.speedGaugeImg, G.player.currentSpeed * 32, 0, 32, 32, 16, OS.camera.height - 32 - 16, 32, 32);
|
2016-04-06 22:52:02 +02:00
|
|
|
|
2016-04-08 02:20:23 +02:00
|
|
|
// Draw Energy Bar
|
|
|
|
this.DrawEnergyBar();
|
|
|
|
|
2016-04-07 21:19:22 +02:00
|
|
|
// drawPixelText("Testing 1 2 3!", 0, 0, 0, "white", 4);
|
|
|
|
// drawPixelText("Testing 1 2 3!", 0, 64, 0, "white", 6);
|
2016-04-12 00:22:56 +02:00
|
|
|
drawInventoryGUI();
|
2016-04-12 06:47:01 +02:00
|
|
|
drawTradeGUI();
|
2016-04-05 01:10:40 +02:00
|
|
|
}
|
2016-04-06 01:33:38 +02:00
|
|
|
|
2016-04-05 01:10:40 +02:00
|
|
|
rm_Ocean.DoLast = function () {
|
|
|
|
// Clear Objects on room exit. This is best practice unless you need persistent objects.
|
2016-04-06 22:52:02 +02:00
|
|
|
//rm_Ocean.objects = {};
|
|
|
|
}
|
2016-04-08 02:20:23 +02:00
|
|
|
|
|
|
|
rm_Ocean.DrawEnergyBar = function () {
|
|
|
|
var percentage = G.stats.energy / G.stats.maxEnergy;
|
2016-04-13 02:14:09 +02:00
|
|
|
var barHeight = pixel(2);
|
2016-04-08 02:20:23 +02:00
|
|
|
var maxBarWidth = 32;
|
2016-04-13 02:14:09 +02:00
|
|
|
var barWidth = pixel(Math.round(maxBarWidth * percentage));
|
2016-04-08 02:20:23 +02:00
|
|
|
|
|
|
|
var saveFillStyle = OS.context.fillStyle;
|
|
|
|
OS.context.fillStyle = "#0055FF";
|
|
|
|
OS.context.fillRect(64, OS.camera.height - barHeight - 16, barWidth, barHeight);
|
|
|
|
OS.context.fillStyle = saveFillStyle;
|
|
|
|
}
|