Last active
December 14, 2015 22:19
-
-
Save AlphaGit/5158029 to your computer and use it in GitHub Desktop.
Arkanoid.js, first steps
(Taken from https://github.com/AlphaGit/random-javascript/commit/90e6540100631e1a3ae590c3bde4a21b74f7abd9)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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