-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbird.html
122 lines (101 loc) · 3.4 KB
/
bird.html
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
<!doctype html>
<html>
<head>
<style>
body {
background-color: rgb(255, 255, 255);
overflow: hidden;
}
@keyframes fly {
0%{
transform: translateX(100vw);
}
100%{
transform: translateX(-100vw);
}
}
@keyframes fall {
100% {
transform: translateY(25vw);
}
}
.bird {
width: 100px;
height: 100px;
position: absolute;
animation: fly linear infinite;
--friend: false;
cursor: pointer;
}
.egg {
width: 100px;
height: 100px;
position: absolute;
background-image: url("egg.png");
animation: fall 2s ease-in;
animation-fill-mode: forwards;
cursor: pointer;
}
</style>
</head>
<body>
<script>
const explosionSound = new Audio("explosion.mp3")
const numberOfBirds = 50;
const chirpSound = new Audio("birdschirp.wav")
setTimeout(function(){
chirpSound.loop = true
chirpSound.play()}, 300)
function getRandomValue(min, max) {
return Math.random() * (max - min) + min;
}
for (let i = 0; i < numberOfBirds; i++) {
const bird = document.createElement("img")
bird.src="pigeon.png"
bird.onclick = function(){
var e = window.event
bird.remove()
const explosion = document.createElement("img")
explosion.src = "kaboom.gif"
explosion.style.position = "absolute"
explosion.style.width = "100px"
explosion.style.height = "100px"
explosion.style.left = (e.x - 50)+"px"
explosion.style.top = (e.y - 50)+"px"
setTimeout(function(){explosion.remove()},800)
document.body.appendChild(explosion)
explosionSound.load()
explosionSound.play()
if (bird.friend == true) {
const egg = document.createElement("img")
egg.classList.add("egg")
egg.style.left = (e.x - 50)+"px"
egg.style.top = (e.y - 50)+"px"
egg.onclick = function(){
window.location.href = "./gambling/gambler.html"
}
document.body.appendChild(egg)
}
if (document.getElementsByClassName("bird").length < 1) {
chirpSound.pause()
}
}
bird.draggable = false
bird.style.userSelect = false
bird.classList.add("bird")
const friendChance = Math.floor(Math.random()*100)
const randomY = getRandomValue(0,20)
const randomDuration = getRandomValue(3,6)
if (friendChance == 1) {
bird.src="friend.png"
bird.style.width = "200px";
bird.style.height = "200px";
bird.friend = true
}
bird.style.animationDuration = randomDuration+"s"
bird.style.top = randomY+"vw"
document.body.appendChild(bird)
}
</script>
</body>
</html>