add optional level_index parameter

This commit is contained in:
Gwenhael Le Moine 2011-07-14 13:10:52 +02:00
parent b810ee1687
commit e4c429209c
2 changed files with 6 additions and 3 deletions

View file

@ -51,7 +51,7 @@
<script src="js/star.js"></script>
<script>
$(document).ready(function() {
initialize_a_star( "#main" );
initialize_a_star( "#main", 0 );
});
</script>
</body>

View file

@ -1,4 +1,4 @@
function initialize_a_star( dom_container ) {
function initialize_a_star( dom_container, level_index ) {
// kinda enums
var cell= { WALL: '#', BALL: '@', CUBE: 'H', VOID: ' ', GIFT: 'x' };
var direction = { UP: 'u', DOWN: 'd', LEFT: 'l', RIGHT: 'r' };
@ -329,7 +329,10 @@ function initialize_a_star( dom_container ) {
}
////// MAIN (so to speak) //////
state = load_level( 0 );
state = load_level( ( level_index === undefined ) ? 0 :
( level_index >= assets.levels.length ) ? assets.levels.length - 1 :
( level_index < 0 ) ? 0 : level_index
);
start_loop( );