Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
48 lines (39 loc) · 1.35 KB
/
Copy pathutils.js
File metadata and controls
48 lines (39 loc) · 1.35 KB
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
function rectangularCollision({ rectangle1, rectangle2 }) {
return (
rectangle1.attackBox.position.x + rectangle1.attackBox.width >=
rectangle2.position.x &&
rectangle1.attackBox.position.x <=
rectangle2.position.x + rectangle2.width &&
rectangle1.attackBox.position.y + rectangle1.attackBox.height >=
rectangle2.position.y &&
rectangle1.attackBox.position.y <= rectangle2.position.y + rectangle2.height
)
}
function determineWinner({player,enemy,timerId}){
clearTimeout(timerId)
document.querySelector('#displayText').style.display = 'flex'
if(player.health === enemy.health){
document.querySelector('#displayText').innerHTML = 'Tie'
} else if (player.health>enemy.health){
document.querySelector('#displayText').innerHTML = 'Player 1 Win'
}
else if (player.health<enemy.health){
document.querySelector('#displayText').innerHTML = 'Player 2 Win'
}
}
let timer = 61
let timerId
function decreaseTimer() {
if(timer > 0){
timerId = setTimeout(decreaseTimer, 1000)
timer--
document.querySelector('#timer').innerHTML = timer
}
if(timer === 0){
determineWinner({player,enemy,timerId})
}
}
const playAgin = document.getElementById('playAgin')
playAgin.addEventListener('click', ()=>{
window.location.reload()
})