Dia 27/2019 - Jogo de matar moscas

Desafio #92daysofcode que fiz no final de 2019. Nesse artigo temos o dia 27, mostrando o uso do seletor de irmãos seletor ~ seletor, com a pseudo-classe CSS de negação :not() e a pseudo-classe :checked.

Pré-visualização

Código

Começamos com a estrutura do HTML.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Day 27</title>
<style>
*, *:before, *:after { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing:border-box; }
html { -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing:border-box; }
* { margin: 0; padding: 0; list-style: none; outline: none; }
body { background: #4b1f71; font-family: Arial, Helvetica, sans-serif; }
</style>
<link rel="stylesheet" type="text/css" href="./day-27.css">
</head>
<body>
<div class="container">
<!-- game -->
</div>
</body>
</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
<div class="main">
<input type="checkbox" id="fly-1" class="input input-1">
<input type="checkbox" id="fly-2" class="input input-2">
<input type="checkbox" id="fly-3" class="input input-3">
<input type="checkbox" id="fly-4" class="input input-4">
<input type="checkbox" id="fly-5" class="input input-5">
<input type="checkbox" id="fly-6" class="input input-6">

<label for="fly-1" class="bug fly-1">
<div class="fly">
<div class="fly-wings"></div>
<div class="fly-head">
<div class="fly-head-leftEye"></div>
<div class="fly-head-rightEye"></div>
</div>
</div>
</label>
<label for="fly-2" class="bug fly-2">
<div class="fly">
<div class="fly-wings"></div>
<div class="fly-head">
<div class="fly-head-leftEye"></div>
<div class="fly-head-rightEye"></div>
</div>
</div>
</label>
<label for="fly-3" class="bug fly-3">
<div class="fly">
<div class="fly-wings"></div>
<div class="fly-head">
<div class="fly-head-leftEye"></div>
<div class="fly-head-rightEye"></div>
</div>
</div>
</label>
<label for="fly-4" class="bug fly-4">
<div class="fly">
<div class="fly-wings"></div>
<div class="fly-head">
<div class="fly-head-leftEye"></div>
<div class="fly-head-rightEye"></div>
</div>
</div>
</label>
<label for="fly-5" class="bug fly-5">
<div class="fly">
<div class="fly-wings"></div>
<div class="fly-head">
<div class="fly-head-leftEye"></div>
<div class="fly-head-rightEye"></div>
</div>
</div>
</label>
</div>

<div class="timer"></div>
<div class="endScreen"><span class="endScreen-text">Fim de Jogo</span></div>
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
body { counter-reset: count; }

.input { position:fixed; left: -50%; bottom: -50%; }
.input:checked { counter-increment: count; }

.main {
border: 4px solid #fff;
height: 70%;
width: 60%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-55%);
cursor: url(./cursor.png), auto;
background: #eee;
overflow: hidden;
}

.timer {
border: 5px solid #eee;
height: 5%;
width: 60%;
position: absolute;
top: 80%;
left: 50%;
display: inline-block;
margin-top: 5%;
border-radius: 4px;
transform: translate(-50%,-50%);
background-color: #fff;
}

.timer:before {
content: "";
display: inline-block;
background: repeating-linear-gradient(-90deg, #438600, #8fd747);
border-radius: 4px;
transition: 0.2s linear;
animation: timer 10s ;
position: inherit;
height: 100%;
}

.fly { height: 80px; margin: 0 auto; width: 100px; }

.fly-head {
background: #000;
border-radius: 50%;
height: 50%;
position: relative;
width: 50%;
}

.fly-head-leftEye,
.fly-head-rightEye {
background: #fff;
border: 1px solid #000;
border-radius: 50%;
height: 60%;
position: absolute;
width: 60%;
}

.fly-head-leftEye:before,
.fly-head-rightEye:before {
background: #000;
border-radius: 50%;
content: "";
display: inline-block;
height: 60%;
margin-left: -30%;
margin-top: -30%;
position: absolute;
left: 50%;
top: 50%;
width: 60%;
}

.fly-head-leftEye:after,
.fly-head-rightEye:after {
background: #fff;
border-radius: 50%;
content: "";
display: inline-block;
height: 30%;
margin-left: -15%;
margin-top: -15%;
position: absolute;
left: 38%;
top: 40%;
width: 30%;
}

.fly-head-leftEye { left: -10px; }
.fly-head-rightEye { right: -10px; }

.fly-wings {
background: #333;
border-radius: 50%;
height: 50%;
margin-bottom: -10%;
margin-left: 5%;
position: relative;
width: 40%;
}

.fly-wings:before,
.fly-wings:after {
border-top: 60px solid rgba(255, 255, 255, 0.8);
border-left: 30px solid transparent;
border-right: 30px solid transparent;
border-radius: 50% 50% 0 0;
content: "";
display: inline-block;
height: 0;
position: absolute;
bottom: -50%;
width: 0;
}

.fly-wings:before { left: 30%; transform: rotate(40deg); }
.fly-wings:after { right: 30%; transform: rotate(-40deg); }

.bug {
animation: move 7s infinite alternate;
cursor: url(./cursor.png), auto;
height: 40px;
opacity:0;
position:absolute;
left:0;
transition: 0.2s cubic-bezier(.01,-0.57,1,.82);
width:40px;
}

.input-1:not(:checked) ~ .fly-1,
.input-2:not(:checked) ~ .fly-2,
.input-3:not(:checked) ~ .fly-3,
.input-4:not(:checked) ~ .fly-4,
.input-5:not(:checked) ~ .fly-5 { opacity:1; }

.input-1:checked ~ .fly-1,
.input-2:checked ~ .fly-2,
.input-3:checked ~ .fly-3,
.input-4:checked ~ .fly-4,
.input-5:checked ~ .fly-5 { display: none; }

.fly-1 { animation-delay: -1s; top:50px; }
.fly-2 { animation-delay: -2.5s; top:100px; transform:scale(0.7); }
.fly-3 { animation-delay: -3s; top: 200px; transform: scale(1.4); }
.fly-4 { animation-delay: -0.5s; top:50px; transform:scale(1.9); }
.fly-5 { animation-delay: -5s; top:100px; transform:scale(1.3);}

.endScreen {
animation: end 10s linear;
background-color: rgb(0, 0, 0, 0.8);
height: 100vh;
position: fixed;
top: 0;
left: 0;
width: 100vw;
z-index: 999;
}

.endScreen-text {
color: #fff;
display: block;
font-size: 4rem;
position: absolute;
top: 50%;
left: 50%;
text-align: center;
transform: translate(-50%,-50%);
}

.endScreen-text:after {
font-size: 2rem;
display: block;
content: "Pontuação: " counter(count);
}

@keyframes move {
0% { left : 0% ; }
15% { top : 20% ; left : 20%; }
30% { top : 60% ; left : 15%; }
45% { top : 15% ; left : 80%; }
60% { top : 75% ; left : 45%; }
75% { top : 35% ; left : 85%; }
90% { top : 30% ; left : 15%; }
100% { top : 85% ; left : 75%; }
}

@keyframes timer {
0% { width: 0% ; }
100% { width: 100% ;}
}

@keyframes end {
0% { top: -5000px;}
90% { top: -5000px;}
97% { top: 0;}
}

Conclusão

A postagem original pode ser vista no meu Instagram e o código está acessível no meu Github.

Ao fechar este aviso ou continuar navegando no site Nerd Calistênico, você aceita o uso de cookies.

Este site usa cookies para assegurar a melhor experiência para os nossos usuários. Consulte nossa política de privacidade.

Uma nova versão está disponível. Clique aqui para atualizar.