From 127218e20a987665d1f2c098c762d279ae955333 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Fri, 15 Jul 2011 21:26:08 +0200 Subject: [PATCH] get rid of start_loop; refactor load_level --- star.js/js/star.js | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/star.js/js/star.js b/star.js/js/star.js index cd4e224..b194ccf 100644 --- a/star.js/js/star.js +++ b/star.js/js/star.js @@ -148,11 +148,11 @@ function initialize_a_star( dom_container, level_index ) { } function load_level( index ) { - state.level = index; - state.board = assets.levels[ state.level ]; - state.distance_travelled = 0; - state.moving = cell.BALL; - return state; + return( { moving: cell.BALL, + distance_travelled: 0, + level: index, + board: assets.levels[ index ], + it_s_over: false } ); } function make_a_move( where ) { @@ -279,13 +279,6 @@ function initialize_a_star( dom_container, level_index ) { } } - - function start_loop( ) { - jQuery(document).focus( ); - jQuery(document).click( event_handler ); - jQuery(document).keydown( event_handler ); - } - ////// MAIN (so to speak) ////// // First of all, setup our little DOM branch @@ -317,22 +310,16 @@ function initialize_a_star( dom_container, level_index ) { } }; - 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 - ); - - start_loop( ); + var state = load_level( ( level_index === undefined ) ? 0 : + ( level_index >= assets.levels.length ) ? assets.levels.length - 1 : + ( level_index < 0 ) ? 0 : level_index ); // kinda ugly workaround around a mysterious bug causing the canvas // not to refresh the first time (before any event) setTimeout( function(){ display_level( ); }, 100 ); // 1/10 second + + // Start main "loop" + jQuery(document).focus( ); + jQuery(document).click( event_handler ); + jQuery(document).keydown( event_handler ); }