-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main_Menu.js
102 lines (83 loc) · 2.75 KB
/
Main_Menu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function drawBtn(button) {
drawRect(vec2(button.x, button.y), vec2(button.w, button.h), button.bgColor, 0, 0)
drawText(`${button.label}`, overlayCanvas.width/2 + button.x, overlayCanvas.height/2 - 12 + (button.y*15)*-1, 30)
}
addGameScope(new GameScope({
name: 'Main Menu',
type: SCOPES.MENU,
subType: 'MENU',
scopedUpdate: true,
scopedRender: true,
scopedKeboard: true,
scopedMouse: true,
scopedGamepad: true,
vars: {
buttons: []
},
gameInit: function () {
if (debug) console.debug(`${this._name} initialized.`)
this._vars.buttons.push({
x: 0,
y: 5,
w: 10,
h: 2,
label: 'Play',
bgColor: new Color(.7, .7, .7),
})
this._vars.buttons.push({
x: 0,
y: 0,
w: 10,
h: 2,
label: 'Settings',
bgColor: new Color(.7, .7, .9),
})
this._vars.buttons.push({
x: 0,
y: -5,
w: 10,
h: 2,
label: 'Exit',
bgColor: new Color(.7, .7, .9),
})
},
gameUpdate: function () {
if (!this._scopedMouse || (this._scopedMouse && this._name === currentScope)) {
if (mouseWasPressed(0)) {
let clickPos = mousePos.floor()
this._vars.buttons.forEach((button, btnIdx) => {
let bounds = {
x1: button.x - button.w/2,
x2: button.x + button.w/2,
y1: button.y - button.h/2,
y2: button.y + button.h/2,
}
if (clickPos.x >= bounds.x1 && clickPos.x <= bounds.x2) {
if (clickPos.y >= bounds.y1 && clickPos.y <= bounds.y2) {
new Sound([.5,.5]).play(mousePos)
if (btnIdx === 0) {
setGameScope('Overworld')
} else if (btnIdx === 1) {
setGameScope('Settings')
} else if (btnIdx === 2) {
setGameScope('Start')
}
}
}
})
}
}
},
gameUpdatePost: function () {},
gameRender: function () {
drawRect(cameraPos, tileCollisionSize.add(vec2(50,40)), new Color(.2, .2, .2), 0, 0)
this._vars.buttons.forEach((button) => {
drawBtn(button)
})
},
gameRenderPost: function () {
drawText(`${this._name}`, overlayCanvas.width/2, 80, 70)
},
onEnter: function() {},
onExit: function() {},
}))