Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/algaes-escapade/js/lib/menu.js
1036 views
1
2
include_once(['lib/menuItem.js'])
3
function menu()
4
{
5
var _items = [];
6
var _currentActive = 0;
7
var _x = 0;
8
var _y = 0;
9
10
this.setPosition = function(x, y)
11
{
12
if ( typeof(x) != 'number' )
13
{
14
throw 'X position must be a number';
15
}
16
17
if ( typeof(y) != 'number' )
18
{
19
throw 'Y position must be a number';
20
}
21
22
_x = x;
23
_y = y;
24
return this;
25
}
26
27
this.addItem = function( mItem ){
28
if ( !(mItem instanceof menuItem) )
29
{
30
throw 'Argument must be of type menuItem';
31
}
32
33
if ( _items.length === 0 )
34
{
35
mItem.setActive(true);
36
}
37
38
_items.push(mItem);
39
return this;
40
}
41
42
this.activate = function(index){
43
for( var i = 0; i < _items; i++ )
44
{
45
if ( i != index )
46
{
47
_items[i].setActive(false);
48
}
49
else
50
{
51
_items[i].setActive(true);
52
}
53
}
54
}
55
56
this.activateNext = function(){
57
_currentActive++;
58
59
if ( _currentActive >= _items.length )
60
{
61
_currentActive = 0;
62
}
63
64
return this.activate(_currentActive);
65
}
66
67
this.draw = function( surface ){
68
var dest = new gamejs.Rect([_x, _y]);
69
70
for( var i = 0; i < _items.length; i++ )
71
{
72
surface.blit( _items[i].getCanvas(), dest );
73
dest.y += 30;
74
}
75
}
76
}
77