Restructured Oversimplified.Settings for better readability in code, added preventRightClick option defaulted to true, moved Oversimplified.SetCamera() out of the Oversimplified.Settings namespace because that just makes more sense, fixed SetCamera() references accordingly.

This commit is contained in:
Robbie Antenesse 2016-04-06 14:36:51 -06:00
parent 760bb5c9b1
commit b46fcf8d0f
3 changed files with 55 additions and 42 deletions

View File

@ -16,36 +16,11 @@ Oversimplified.emptyImage.width = 1;
Oversimplified.emptyImage.height = 1;
// Settings Namespace
Oversimplified.Settings = {};
Oversimplified.Settings.defaultStep = 1/30;
Oversimplified.Settings.soundVolume = 0.75;
Oversimplified.Settings.musicVolume = 0.75;
/* Set up the camera.
It is important that this is done first at the time the game is loaded because this determines the size of the HTML5 canvas.
Be sure that the objectToFollow has already been created in the current room. Can be referenced with a variable.
objectToFollow, hBorder, and vBorder are optional arguments, but if you want to set hBorder and vBorder, there must be an objectToFollow.
*/
Oversimplified.Settings.SetCamera = function (options) {
Oversimplified.camera.width = typeof options.width !== 'undefined' ? options.width : Oversimplified.camera.width;
Oversimplified.camera.height = typeof options.height !== 'undefined' ? options.height : Oversimplified.camera.height;
Oversimplified.SetCanvasToCameraSize();
Oversimplified.camera.x = typeof options.x !== 'undefined' ? options.x : Oversimplified.camera.x;
Oversimplified.camera.y = typeof options.y !== 'undefined' ? options.y : Oversimplified.camera.y;
if (typeof options.objectToFollow !== 'undefined') {
if (options.objectToFollow.name) {
Oversimplified.camera.Follow(options.objectToFollow);
} else {
if (Oversimplified.DEBUG.showMessages) console.log("Oversimplified.Settings.SetCamera()'s objectToFollow argument must be a Oversimplified.GameObject.");
}
}
Oversimplified.camera.hBorder = (typeof options.hBorder !== 'undefined') ? options.hBorder : Oversimplified.camera.hBorder;
Oversimplified.camera.vBorder = (typeof options.vBorder !== 'undefined') ? options.vBorder : Oversimplified.camera.vBorder;
Oversimplified.Settings = {
defaultStep : 1/30,
soundVolume : 0.75,
musicVolume : 0.75,
preventRightClick : true
}
// Convenient alias for Settings.
Oversimplified.S = Oversimplified.Settings;
@ -74,6 +49,33 @@ Oversimplified.camera = {
}
}
/* Set up the camera.
It is important that this is done first at the time the game is loaded because this determines the size of the HTML5 canvas.
Be sure that the objectToFollow has already been created in the current room. Can be referenced with a variable.
objectToFollow, hBorder, and vBorder are optional arguments, but if you want to set hBorder and vBorder, there must be an objectToFollow.
*/
Oversimplified.SetCamera = function (options) {
Oversimplified.camera.width = typeof options.width !== 'undefined' ? options.width : Oversimplified.camera.width;
Oversimplified.camera.height = typeof options.height !== 'undefined' ? options.height : Oversimplified.camera.height;
Oversimplified.SetCanvasToCameraSize();
Oversimplified.camera.x = typeof options.x !== 'undefined' ? options.x : Oversimplified.camera.x;
Oversimplified.camera.y = typeof options.y !== 'undefined' ? options.y : Oversimplified.camera.y;
if (typeof options.objectToFollow !== 'undefined') {
if (options.objectToFollow.name) {
Oversimplified.camera.Follow(options.objectToFollow);
} else {
if (Oversimplified.DEBUG.showMessages) console.log("Oversimplified.Settings.SetCamera()'s objectToFollow argument must be a Oversimplified.GameObject.");
}
}
Oversimplified.camera.hBorder = (typeof options.hBorder !== 'undefined') ? options.hBorder : Oversimplified.camera.hBorder;
Oversimplified.camera.vBorder = (typeof options.vBorder !== 'undefined') ? options.vBorder : Oversimplified.camera.vBorder;
}
// Mouse Object
Oversimplified.mouse = {
x: 0,
@ -1346,7 +1348,7 @@ Oversimplified.SetupCanvas = function () {
}
//Disable right click menu on canvas
Oversimplified.canvas.oncontextmenu = function() {return false;};
if (Oversimplified.Settings.preventRightClick) Oversimplified.canvas.oncontextmenu = function() {return false;};
}
Oversimplified.SetupControls = function () {

View File

@ -1,5 +1,15 @@
function oceanRoom () {
// Create objects on room creation for persistence.
G.player = rm_Ocean.AddObject(OS.P["Ship"]);
G.player.x = ((rm_Ocean.width / OS.S.pixelScale) / 2) * OS.S.pixelScale;
G.player.y = ((rm_Ocean.height / OS.S.pixelScale) / 2) * OS.S.pixelScale;
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();
// 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);
}
@ -11,16 +21,12 @@ rm_Ocean.DoFirst = function () {
//Hide cursor when playing (only use if masking the cursor with another object)
//OS.canvas.style.cursor = "none";
// Create objects on room start. This is best practice unless you need persistent objects.
G.player = this.AddObject(OS.P["Ship"]);
G.player.x = ((rm_Ocean.width / OS.S.pixelScale) / 2) * OS.S.pixelScale;
G.player.y = ((rm_Ocean.height / OS.S.pixelScale) / 2) * OS.S.pixelScale;
G.oceanParticle = this.AddObject(OS.P["Ocean Particle"]);
G.oceanParticle.x = G.player.x + randomSmidge();
G.oceanParticle.y = G.player.y + randomSmidge();
OS.S.SetCamera(64 * OS.S.pixelScale, 64 * OS.S.pixelScale, G.player, 24 * OS.S.pixelScale, 24 * OS.S.pixelScale);
// 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
});
}
rm_Ocean.Do = function () {
// Move G.oceanParticle around based on player's movement.

View File

@ -1,6 +1,11 @@
OS.S.defaultStep = 1 / 120;
OS.S.pixelScale = 4;
OS.S.SetCamera(64 * OS.S.pixelScale, 64 * OS.S.pixelScale);
OS.SetCamera({
width: 64 * OS.S.pixelScale,
height: 64 * OS.S.pixelScale,
hBorder: 24 * OS.S.pixelScale,
vBorder: 24 * OS.S.pixelScale
});
function start()
{