Path: blob/main/public/games/files/algaes-escapade/js/lib/startMenu.js
1036 views
1include_once(['lib/world.js', 'lib/menu.js','lib/menuItem.js'])2function startMenu()3{4var _menu = new menu();5_menu.setPosition(260, 500)6_menu.addItem( new menuItem('img/new-game.png') );78var _bg = gamejs.image.load('img/splash-screen.png');9var _world = null;1011var _setupLevel = function( mainSurface ){12//Initiate the world amd set the level to a reset13_world = new world();14var lvlNum = 0;15var self = this;1617var nextLevel = function(event){18if ( typeof(event) !== 'undefined' )19{20event.preventDefault();21}2223if ( $('#game_scorecard .nextLevel').hasClass('disabled') )24{25return false;26}2728lvlNum++;2930resetLevel();31return false;32};3334var resetLevel = function(event){35if ( typeof(event) !== 'undefined' )36{37event.preventDefault();38}3940$('#game_scorecard_bg').hide();4142_world.init(lvlNum, mainSurface);43return false;44}4546var backToMenu = function(event){47if ( typeof(event) !== 'undefined' )48{49event.preventDefault();50}5152_world = null;53$('#game_scorecard_bg').remove();54return false;55}5657$('.nextLevel').die();58$('.resetLevel').die();59$('.mainMenu').die();6061$('.nextLevel').live('click', nextLevel);62$('.resetLevel').live('click', resetLevel);63$('.mainMenu').live('click', backToMenu);6465//Initialise the first level66nextLevel();67}6869this.handleInput = function( mainSurface ){70if ( _world === null )71{72gamejs.event.get().forEach(function(event){73if ( event.type === gamejs.event.KEY_DOWN )74{75if ( event.key == gamejs.event.K_ENTER )76{77_setupLevel( mainSurface );78}79}80});81}82else83{84_world.handleInput();85}86}8788this.update = function( msDuration ){89if ( _world !== null )90{91_world.update( msDuration );92}93}9495this.draw = function( surface ){96if ( _world === null )97{98surface.blit(_bg);99_menu.draw( surface );100}101else102{103_world.draw( surface );104}105}106}107108