mirror of
https://github.com/gwenhael-le-moine/c-urs_-toil-s.git
synced 2024-12-27 09:58:44 +01:00
get rid of start_loop; refactor load_level
This commit is contained in:
parent
bcbfac8502
commit
127218e20a
1 changed files with 13 additions and 26 deletions
|
@ -148,11 +148,11 @@ function initialize_a_star( dom_container, level_index ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function load_level( index ) {
|
function load_level( index ) {
|
||||||
state.level = index;
|
return( { moving: cell.BALL,
|
||||||
state.board = assets.levels[ state.level ];
|
distance_travelled: 0,
|
||||||
state.distance_travelled = 0;
|
level: index,
|
||||||
state.moving = cell.BALL;
|
board: assets.levels[ index ],
|
||||||
return state;
|
it_s_over: false } );
|
||||||
}
|
}
|
||||||
|
|
||||||
function make_a_move( where ) {
|
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) //////
|
////// MAIN (so to speak) //////
|
||||||
|
|
||||||
// First of all, setup our little DOM branch
|
// First of all, setup our little DOM branch
|
||||||
|
@ -317,22 +310,16 @@ function initialize_a_star( dom_container, level_index ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var state = {
|
var state = load_level( ( level_index === undefined ) ? 0 :
|
||||||
moving: cell.BALL,
|
( level_index >= assets.levels.length ) ? assets.levels.length - 1 :
|
||||||
distance_travelled: 0,
|
( level_index < 0 ) ? 0 : level_index );
|
||||||
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( );
|
|
||||||
|
|
||||||
// kinda ugly workaround around a mysterious bug causing the canvas
|
// kinda ugly workaround around a mysterious bug causing the canvas
|
||||||
// not to refresh the first time (before any event)
|
// not to refresh the first time (before any event)
|
||||||
setTimeout( function(){ display_level( ); }, 100 ); // 1/10 second
|
setTimeout( function(){ display_level( ); }, 100 ); // 1/10 second
|
||||||
|
|
||||||
|
// Start main "loop"
|
||||||
|
jQuery(document).focus( );
|
||||||
|
jQuery(document).click( event_handler );
|
||||||
|
jQuery(document).keydown( event_handler );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue