From bcbfac8502fa1f274be3674e99e46ab3e36c47c9 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Fri, 15 Jul 2011 20:57:55 +0200 Subject: [PATCH] I reorganize and it's my joy --- star.js/js/star.js | 75 +++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/star.js/js/star.js b/star.js/js/star.js index a5af1fa..cd4e224 100644 --- a/star.js/js/star.js +++ b/star.js/js/star.js @@ -32,43 +32,6 @@ function initialize_a_star( dom_container, level_index ) { "################# # ## x ##x x ## #x x ## ## x ## #x ## #x x# x ## ##x #@ H ################# " ] }; - // First of all, setup our little DOM branch - var starhtml = '
'; - starhtml += ''; - starhtml += ''; - starhtml += ''; - starhtml += '
'; - jQuery( dom_container ).html( starhtml ); - - // Now we can collect some informations about this DOM branch we have - var DOM_infos = { - container: dom_container, - canvas: { - //jQuery() returns a jquery object, [0] to get the canvas itself - context: jQuery( dom_container + " #starboard" )[ 0 ].getContext( '2d' ), - offset: jQuery( dom_container + " #starboard" ).offset(), - width: jQuery( dom_container + " #starboard" ).width(), - height: jQuery( dom_container + " #starboard" ).height() - } - }; - - var level_infos = { - height: 9, - width: 16, - cell: { - width: DOM_infos.canvas.width / 16, - height: DOM_infos.canvas.height / 9 - } - }; - - var state = { - moving: cell.BALL, - distance_travelled: 0, - level: 0, - board: "", - it_s_over: false - }; - ////// FUNCTIONS ////// function load_sprites( theme ) { var sprites = { }; @@ -324,6 +287,44 @@ function initialize_a_star( dom_container, level_index ) { } ////// MAIN (so to speak) ////// + + // First of all, setup our little DOM branch + var starhtml = '
'; + starhtml += ''; + starhtml += ''; + starhtml += ''; + starhtml += '
'; + jQuery( dom_container ).html( starhtml ); + + // Now we can collect some informations about this DOM branch we have + var DOM_infos = { + container: dom_container, + canvas: { + //jQuery() returns a jquery object, [0] to get the canvas itself + context: jQuery( dom_container + " #starboard" )[ 0 ].getContext( '2d' ), + offset: jQuery( dom_container + " #starboard" ).offset(), + width: jQuery( dom_container + " #starboard" ).width(), + height: jQuery( dom_container + " #starboard" ).height() + } + }; + + var level_infos = { + height: 9, + width: 16, + cell: { + width: DOM_infos.canvas.width / 16, + height: DOM_infos.canvas.height / 9 + } + }; + + var state = { + moving: cell.BALL, + distance_travelled: 0, + level: 0, + board: "", + it_s_over: false + }; + state = load_level( ( level_index === undefined ) ? 0 : ( level_index >= assets.levels.length ) ? assets.levels.length - 1 : ( level_index < 0 ) ? 0 : level_index