//engine var Engine = { x: 0, y: 0, w: 0, h: 0,//stored for window-building } // category Game var Game = { stepPrevious: 0, // Game.activeScene.activeObjects

array containing all existing objects. activeScene: new Scene(), userUpdateCallback: null, // Game.stepsSinceStart

Total amount of update steps since the start of the game. stepsSinceStart: 0, // Game.initialize(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback)

Starts the game, and creates a window at ('windowX', 'windowY'), using 'windowWidth' and 'windowHeight' as sizes for the game window in pixels. 'fps' controls the game's frames-per-second'. As soon as the game is loaded up, it'll call the function 'loadedCallback', so you can properly start the game. initialize: function(windowX, windowY, windowWidth, windowHeight, fps, loadedCallback) { console.log("GAME: Initializing. Loading dependencies..."); Engine.x = windowX; Engine.y = windowY; Engine.w = windowWidth; Engine.h = windowHeight; GameWindow.init(Engine.x, Engine.y, Engine.w, Engine.h); GameInput.g_init(); window.setInterval(Game.gameStep, 1000 / fps); loadedCallback(); }, loadScene: function(newScene, preserveOld = false) { if(!preserveOld) { Game.activeScene.destroy(); } Game.activeScene = newScene; }, // Game.setUpdateFunction(callback)

Assigns a function 'callback(deltaTime)' to be called every frame of the game. You can use this to run global code for your game. setUpdateFunction: function(callback) { Game.userUpdateCallback = callback; }, // Game.clearScene()

destroys every object in the scene. clearScene: function() { Game.activeScene.destroy(); }, gameStep: function() { var stepTime = Date.now(); var stepTimeCurr = (stepTime - this.stepPrevious) * 0.001; stepTimeCurr = Math.min(stepTimeCurr, 0.1); if(isNaN(stepTimeCurr)) stepTimeCurr = 0; Game.stepsSinceStart++; GameInput.g_updateKeys(); var toUpdate = Game.activeScene.activeObjects.slice(); for(var i = 0; i < toUpdate.length; i++) { if(toUpdate[i].active || toUpdate[i].destroyed) toUpdate[i].g_updateStep(stepTimeCurr); } if (typeof Game.userUpdateCallback == 'function') { Game.userUpdateCallback(stepTimeCurr); } GameWindow.redraw(); this.stepPrevious = stepTime; }, reorderObjects: function() { this.activeScene.activeObjects.sort(function(a, b) { return a.renderer.layerDepth - b.renderer.layerDepth; }) } };