-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNavBar.js
223 lines (204 loc) · 7.55 KB
/
NavBar.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
var isGameMode = false;
let mousePositionListener = null; //temporary as not sure how to remove event listener that has a binded property without this
const myIntervals = []; //for interval also not sure yet how to better handle this...just want it to work first
const collisionChecks = [];
const skillsList = [
'C#',
'.NET FRAMEWORK',
'MVC/ASP.NET',
'Entity Framework',
'HTML5',
'CSS3',
'JavaScript',
'SQL',
'OOP',
'Git',
'TFS',
'Azure Repos',
'Azure Kubernetes Service',
'Azure Pipelines',
'Azure Container Registry',
'Azure DevOps',
'Azure Boards',
'Kafka',
'Java',
'SpringBoot',
'API',
'Open API',
'Bootstrap',
'Agile',
'Scrum',
'Jira',
'Linux VMs',
'Ubuntu',
'Python',
'Bash',
'ETL',
'Tomcat',
'Webhooks',
'Jenkins',
'Docker'
];
let skillsListCopy = [...skillsList];
function OpenNavButtonMenu (circleID)
{
var circleToggle = 'toggle-secondary-circle';
var secondaryCircles = document.getElementsByClassName('secondary-circle');
for (let i = 0; i < secondaryCircles.length; i++) {
const element = secondaryCircles[i];
//closes any menu except the the menu attached to button...otherwise can't click button to close same menu
if (element.classList.contains(circleToggle) && element.id != circleID){element.classList.toggle(circleToggle);}
//if menu is closed it'll open, if open it'll close
if (element.id == circleID) {element.classList.toggle(circleToggle);}
}
}
function ToggleHideNavButtons (){
var circle = document.getElementById('main-circle-buttons');
var buttons = circle.children;
for (let x of buttons){
x.classList.toggle('transform-none');
x.style.visibility = x.style.visibility == 'hidden' ? 'visible' : 'hidden';
}
const secondaryCircles = document.getElementsByClassName('secondary-circle');
Array.from(secondaryCircles).forEach(x => {
if (x.classList.contains('toggle-secondary-circle')) x.classList.toggle('toggle-secondary-circle');
});
}
function SetupGame() {
isGameMode = true;
skillsListCopy = Shuffle([...skillsList]);
ToggleHideNavButtons();
var gunBarrel = document.getElementById('gun-barrel');
var bullet = document.getElementById('bullet');
document.getElementById('body-shirt').style.cursor = 'crosshair';
gunBarrel.classList.toggle('active');
let root = document.documentElement;
root.addEventListener('click', BulletListener);
var targets = bullet.getElementsByClassName('target');
for(let target of targets){
let id = setInterval(MoveTarget,2000,target);
myIntervals.push(id);
console.log('setting interval, id: '+id);
id = setInterval(CheckCollision,10,bullet,target);
console.log('setting collisionCheck, id: '+id);
collisionChecks.push(id);
}
let skl = document.getElementById('skills-list')
skl.innerHTML= "SKILLS:<br>";
if (!skl.classList.contains('show')) skl.classList.toggle('show');
document.getElementById('skip-game').classList.toggle('show');
Array.from(document.getElementsByClassName('background_text')).forEach(x => {x.classList.toggle('hide')});
}
function AddSkillToList(){
if(skillsListCopy.length > 0){
let el = document.getElementById('skills-list');
el.innerHTML += skillsListCopy.pop()+"<br>";
}
}
function MoveTarget(target){
if(isGameMode){
target.style.setProperty('left',Math.floor(Math.random()*100)+"%");
target.classList.toggle('move');
}
else {
console.log('clearing intervals...');
myIntervals.forEach(function(value){
console.log('clearing interval...id: '+value);
clearInterval(value)
});
myIntervals.length = 0;
}
}
function FollowMouse (id) {
el = document.getElementById(id);
const position = el.getBoundingClientRect();
el.style.transition = 'none';
mousePositionListener = MousePositionListener.bind(position);
document.addEventListener('mousemove', mousePositionListener, true);
}
function EndGame(skip) {
if(isGameMode){
ToggleHideNavButtons();
console.log('game mode deactivating...')
isGameMode = false;
document.removeEventListener('mousemove', mousePositionListener, true);
document.documentElement.removeEventListener('click', BulletListener);
document.getElementById('body-shirt').style.cursor = 'auto';
el = document.getElementById('home_button');
el.classList.remove('transition-none');
el.style.transform = 'rotate(0deg)';
el.style.transition = 'all .4s linear';
el.children[0].classList.remove('loaded'); //home-button-photo
document.getElementById('gun-barrel').classList.remove('active');
document.getElementById('skip-game').classList.toggle('show');
let skl = document.getElementById('skills-list');
if (skip) {
skl.innerHTML = "SKILLS:<br>";
skillsList.forEach(function(value){
skl.innerHTML += value+'<br>';
});
} else {
skl.classList.toggle('show');
}
Array.from(document.getElementsByClassName('background_text')).forEach(x => {x.classList.toggle('hide')});
}
}
function CheckCollision(el1, el2) {
if(isGameMode){
var el1Rect = el1.getBoundingClientRect();
var el2Rect = el2.getBoundingClientRect();
if ((el1Rect.right >= el2Rect.left && el1Rect.left <= el2Rect.right) &&
(el1Rect.bottom >= el2Rect.top && el1Rect.top <= el2Rect.bottom)){
if(!el1.children[0].classList.contains('caught')){
el1.children[0].classList.toggle('caught');
}
setTimeout(function(){
AddSkillToList();
},1000);
el2.classList.toggle('move');
}
} else {
console.log('clearing collisionChecks...');
collisionChecks.forEach(function(value){
console.log('clearing collisionCheck id: '+value);
clearInterval(value);
});
CheckCollision.length = 0;
}
}
function Shuffle(array) {
let currentIndex = array.length, randomIndex;
// While there remain elements to shuffle.
while (currentIndex != 0) {
// Pick a remaining element.
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
// And swap it with the current element.
[array[currentIndex], array[randomIndex]] = [
array[randomIndex], array[currentIndex]];
}
return array;
}
//Listener Callback Methods
function MousePositionListener(event){
const x = event.x - (this.x + this.width / 2);
const y = this.y + this.height / 2 - event.y;
const degrees = Math.atan(x / y) * (180 / Math.PI) + (y < 0 ? 180 : 0);
el.style.transform = `rotate(${degrees}deg)`;
}
function BulletListener(event){
if(!bullet.classList.contains('move') && bullet.offsetLeft == 50){ //can't shoot until it's returned to starting pos
let homeButtonPhoto = document.getElementById('home-button-photo');
homeButtonPhoto.classList.remove('loaded');
bullet.classList.toggle('move');
this.style.setProperty('--mouse-x', event.clientX + "px");
this.style.setProperty('--mouse-y', event.clientY + "px");
bullet.children[0].classList.remove('caught');
setTimeout(function(){
bullet.classList.toggle('move');
}, 1000);
setTimeout(function(){
if (isGameMode) homeButtonPhoto.classList.add('loaded');
}, 2000);
}
}