Skip to content

Instantly share code, notes, and snippets.

@AlphaGit
Last active December 14, 2015 22:19
Show Gist options
  • Save AlphaGit/5158029 to your computer and use it in GitHub Desktop.
Save AlphaGit/5158029 to your computer and use it in GitHub Desktop.
window.arkanoid = (function(userOptions) {
// private fields
var canvas = null;
var ctx = null;
var options = null;
var defaultOptions = {
fullWidth: true,
fullHeight: true,
stageHeight: 600,
stageWidth: 1024
};
// private methods
function initOptions(userOptions) {
options = mergeObjects(defaultOptions, userOptions);
if (options.fullWidth) options.stageWidth = document.documentElement.clientWidth;
if (options.fullHeight) options.stageHeight = document.documentElement.clientHeight;
}
function mergeObjects(toOverride, overridingWith) {
for (var property in overridingWith) {
toOverride[property] = overridingWith[property];
}
return toOverride;
}
function initCanvas() {
var body = document.getElementsByTagName("body")[0];
var height = options.stageWidth;
var width = options.stageHeight;
canvas = document.createElement("canvas");
canvas.width = height;
canvas.height = width;
body.appendChild(canvas);
ctx = canvas.getContext("2d");
}
function initAll() {
initOptions();
initCanvas();
var stage = new ArkanoidStage(ctx, options.stageHeight, options.stageWidth);
}
// public methods
return {
init: initAll
};
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment