/*jslint plusplus: true, white: true, indent: 2, maxlen: 90 */
/**
* @module $wk$
* @author Wolfgang Kowarschick
* @copyright 2013, Wolfgang Kowarschick
* <br/>
* Redistribution and use in source and binary forms, with or without
* modification, are permitted under the terms of the
* Creative Commons License Attribution-NonCommercial-ShareAlike 3.0 Unported
* (CC BY-NC-SA 3.0: http://creativecommons.org/licenses/by-nc-sa/3.0/).
*/
(function($wk$, window, document)
{ "use strict";
////////////////////////////////////////////////////////////////////////////////
// "Main"
////////////////////////////////////////////////////////////////////////////////
function Main()
{ var Ball = $wk$.Ball, // Import
Collision = $wk$.Collision, // Import
i,
l_init = INIT,
l_init_canvas = l_init.canvas,
l_init_ball = l_init.ball,
l_init_game = l_init.game,
l_fps = l_init_game.fps,
l_canvas = document.getElementById("d_canvas"),
l_context = l_canvas.getContext("2d"),
l_balls = [],
l_balls_length = l_init_game.ballsNr,
l_collision;
// Initialize the canvas.
l_canvas.width = l_init_canvas.width;
l_canvas.height = l_init_canvas.height;
// Initialize the ball objects.
for (i = 0; i < l_balls_length; i++)
{ l_balls[i] = new Ball(l_context, l_init_ball); }
// Initialize the collision object.
l_collision = new Collision({left: 0,
right: l_init_canvas.width,
top: 0,
bottom: l_init_canvas.height
},
l_balls
);
// An event observer:
// It is called every 1000/FPS milliseconds, but only when the game has been started.
function o_redraw()
{ var i = null;
// collision detection and handling
l_collision.handleCollision();
// Move the sprites.
for (i in l_balls)
{ l_balls[i].move(1000/l_fps); }
// Clear the canvas and draw all sprites.
l_context.clearRect(0, 0, l_init_canvas.width, l_init_canvas.height);
for (i in l_balls)
{ l_balls[i].draw(); }
}
// Start the timer for redrawing the canvas every 1000/FPS milliseconds.
window.setInterval(o_redraw, 1000/l_fps);
}
// Execute the main function, after the HTML page has been loaded.
window.onload = Main;
////////////////////////////////////////////////////////////////////////////////
// End of "Main"
////////////////////////////////////////////////////////////////////////////////
}(this.$wk$, this.window, this.document));