Source: main.js

/*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 Paddle        = $wk$.Paddle,    // Import
      Collision     = $wk$.Collision, // Import
      l_init        = INIT,
      l_init_canvas = l_init.canvas,
      l_init_paddle = l_init.paddle,
      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_paddle,
      l_collision;
      
  // Initialize the canvas.
  l_canvas.width  = l_init_canvas.width;
  l_canvas.height = l_init_canvas.height;

  // Initialize the paddle object.
  l_paddle = new Paddle(l_context, l_init_paddle);

  // Initialize the collision object.
  l_collision = new Collision({left:   0, 
                               right:  l_init_canvas.width, 
                               top:    0,
                               bottom: l_init_canvas.height
                              },
                              l_paddle
                             );

  // React to key down and key up events.
  document.onkeydown = this.o_start_paddle_moving.bind(this);
  document.onkeyup   = this.o_stop_paddle_moving.bind(this);

  // An event observer: 
  // It is called every 1000/FPS milliseconds, but only when the game has been started.
  function o_redraw() 
  { // collision detection and handling
    l_collision.handleCollision();

    // Move the ball.
    l_paddle.move(1000/l_fps);

    // Clear the canvas and draw all sprites.
    l_context.clearRect(0, 0, l_init_canvas.width, l_init_canvas.height);
    l_paddle.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));
W. Kowarschick © 2013 (CC BY-NC-SA 3.0: http://creativecommons.org/licenses/by-nc-sa/3.0/)
Documentation generated by JSDoc 3.3.0-dev on Wed Nov 13 2013 15:01:11 GMT+0100 (MEZ) using the DocStrap template.