Path: blob/main/public/games/files/algaes-escapade/js/lib/menu.js
1036 views
1include_once(['lib/menuItem.js'])2function menu()3{4var _items = [];5var _currentActive = 0;6var _x = 0;7var _y = 0;89this.setPosition = function(x, y)10{11if ( typeof(x) != 'number' )12{13throw 'X position must be a number';14}1516if ( typeof(y) != 'number' )17{18throw 'Y position must be a number';19}2021_x = x;22_y = y;23return this;24}2526this.addItem = function( mItem ){27if ( !(mItem instanceof menuItem) )28{29throw 'Argument must be of type menuItem';30}3132if ( _items.length === 0 )33{34mItem.setActive(true);35}3637_items.push(mItem);38return this;39}4041this.activate = function(index){42for( var i = 0; i < _items; i++ )43{44if ( i != index )45{46_items[i].setActive(false);47}48else49{50_items[i].setActive(true);51}52}53}5455this.activateNext = function(){56_currentActive++;5758if ( _currentActive >= _items.length )59{60_currentActive = 0;61}6263return this.activate(_currentActive);64}6566this.draw = function( surface ){67var dest = new gamejs.Rect([_x, _y]);6869for( var i = 0; i < _items.length; i++ )70{71surface.blit( _items[i].getCanvas(), dest );72dest.y += 30;73}74}75}7677