-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolsAndInput.js
92 lines (65 loc) · 2.17 KB
/
controlsAndInput.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
//Constructor function to handle the onscreen menu, keyboard and mouse controls
function ControlsAndInput(){
this.menuDisplayed = true;
//playback button displayed in the top left of the screen
this.playbackButton = new PlaybackButton();
//if mousePressed is not on the playback button, the window will toggle between fullscreen or revert to windowed.
//if mousePressed is on the playback button, the music will start but the window will stay in the selected window mode.
this.mousePressed = function(){
if(this.playbackButton.hitCheck()){
playing = true;
}
else{
var fs = fullscreen();
fullscreen(!fs);
}
};
//responds to keyboard presses
//@param keycode the ascii code of the keypressed
this.keyPressed = function(keycode){
console.log(keycode);
if(keycode == 32){
this.menuDisplayed = !this.menuDisplayed;
}
if(keycode > 48 && keycode < 58){
var visNumber = keycode - 49;
vis.selectVisual(vis.visuals[visNumber].name);
}
//change select visual color
else if(keycode == 13){
if (state < 3){
state +=1;
}
else{
state = 0;
}
}
colorPalette = palettes[state];
};
//draws the playback button and potentially the menu
this.draw = function(){
push();
fill("white");
stroke("black");
strokeWeight(2);
textSize(34);
//playback button
this.playbackButton.draw();
//only draw the menu if menu displayed is set to true.
if(this.menuDisplayed){
text("Select a visualisation by pressing 1, 2, 3, 4:", 100, 35);
this.menu();
text("Press space to hide/ unhide menu. Click onscreen to enter/exit fullscreen.", 100, 250);
text("Click play to start sound", 100, 290);
}
pop();
};
this.menu = function(){
//draw out menu items for each visualisation
//???
for(var i = 0; i < vis.visuals.length; i++){
text(vis.visuals[i].name, 100, 70+(i*40));
Visualisations();
}
};
}