-
Notifications
You must be signed in to change notification settings - Fork 1
/
utebo_1.py
305 lines (300 loc) · 11.9 KB
/
utebo_1.py
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import pygame
from math import ceil
from math import pi
import time
# Feito por Magnus, Rudigus e Caius e Luanus
placarJ1 = 0
placarJ2 = 0
def main():
global placarJ1
global placarJ2
digitos = 1
auxPlacarJ1 = placarJ1
while (auxPlacarJ1 >= 10):
auxPlacarJ1 = auxPlacarJ1 / 10
digitos += 1
print(digitos)
pygame.init()
tempo = 0
tempo1 = 0
tempoInicial = 0
tempoFinal = 0
p = False
o = True
chute = False
chuteAcabou = False
infoTela = pygame.display.Info()
largura = infoTela.current_w
altura = infoTela.current_h
#screen = pygame.display.set_mode((800, 600))
screen = pygame.display.set_mode((largura, altura), pygame.FULLSCREEN)
fontePlacar = pygame.font.SysFont("monospace", 90, 1)
espacos = ""
for i in range(digitos):
espacos += " "
textoPlacar = str(placarJ1) + espacos + str(placarJ2)
placar = fontePlacar.render(textoPlacar, 0, (0, 0, 0))
pygame.display.set_caption("UTEBO - %d X %d" % (placarJ1, placarJ2))
done = True
is_blue = True
t=largura//2 # X do centro do círculo
k=altura//2 # Y do centro do círculo
tj = 20 # Tamanho do Jogador
x = [largura - largura//15 - tj, largura//15]
y = [altura / 2 - tj//2 , altura / 2 - tj//2]
vel1 = 4
vel2 = 4
multEnergia = 1.5
r = 14
tb = r * 2
energiaJ1 = 100
energiaJ2 = 100
custoEnergia = 1
clock = pygame.time.Clock()
corrida1 = False
corrida2 = False
while done:
for event in pygame.event.get():
if (event.type == pygame.QUIT):
done = False
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
is_blue = not is_blue
if (event.type == pygame.KEYDOWN and event.key == pygame.K_p):
chute = True
if (event.type == pygame.KEYUP and event.key == pygame.K_p):
chuteAcabou = True
if (event.type == pygame.KEYDOWN and event.key == pygame.K_l and energiaJ1 >= custoEnergia):
vel1 = vel1 * multEnergia
corrida1 = True
if (event.type == pygame.KEYUP and event.key == pygame.K_l and corrida1):
vel1 = vel1 / multEnergia
corrida1 = False
if (event.type == pygame.KEYDOWN and event.key == pygame.K_g and energiaJ2 >= custoEnergia):
vel2 = vel2 * multEnergia
corrida2 = True
#if(hasattr(event, "key")):
# print(event.type == pygame.KEYUP, event.key == pygame.K_g, corrida2, energiaJ2 < custoEnergia, corrida2)
if (event.type == pygame.KEYUP and event.key == pygame.K_g and corrida2):
vel2 = vel2 / multEnergia
corrida2 = False
if(energiaJ1 < custoEnergia and corrida1):
vel1 = vel1 / multEnergia
corrida1 = False
if(energiaJ2 < custoEnergia and corrida2):
vel2 = vel2 / multEnergia
corrida2 = False
# Bola enconsta no lado esquerdo
if(t - r < 0):
if(not(t - r < 0 and k > altura//4 and k < 3 * altura//4)):
t = r
# Bola encosta no lado direito
if(t + r > largura):
if(not(t + r > largura and k > altura//4 and k < 3 * altura // 4)):
t = largura - (r * 3) // 2
# Bola encosta no teto
if(k - r < 0):
k = r
# Bola encosta no chão
if(k + r > altura):
k = altura - (r * 3) // 2
distX = abs(x[0] - x[1])
distY = abs(y[0] - y[1])
if(x[0] < t):
distTX = (t - r) - (x[0] + tj)
else:
distTX = x[0] - (t + r)
if(x[1] < t):
distTX1 = (t - r) - (x[1] + tj)
else:
distTX1 = x[1] - (t + r)
if(y[0] > k):
distTY = y[0] - (k + r)
else:
distTY = (k - r) - (y[0] + tj)
if(y[1] > k):
distTY1 = y[1] - (k + r)
else:
distTY1 = (k - r) - (y[1] + tj)
pressed = pygame.key.get_pressed()
# Energia / Stamina
if (pressed[pygame.K_l] and energiaJ1 >= custoEnergia):
energiaJ1 -= custoEnergia
if(pressed[pygame.K_g] and energiaJ2 >= custoEnergia):
energiaJ2 -= custoEnergia
# Movimento dos Jogadores (J1 e J2)
if pressed[pygame.K_ESCAPE]:
done = False
if pressed[pygame.K_UP]:
if(not(distX <= tj and abs(y[0] - vel1 - y[1]) <= tj and y[0] > y[1]) and (not(y[0] <= 0))):
y[0] -= vel1
if pressed[pygame.K_DOWN]:
if(not(distX <= tj and abs(y[0] + vel1 - y[1]) <= tj and y[0] < y[1]) and (not(y[0]+tj >= altura))):
y[0] += vel1
if pressed[pygame.K_LEFT]:
if(not(abs(x[0] - vel1 - x[1]) <= tj and distY <= tj and x[0] > x[1]) and (not(x[0] <= 0))):
x[0] -= vel1
if pressed[pygame.K_RIGHT]:
if(not(abs(x[0] + vel1 - x[1]) <= tj and distY <= tj and x[0] < x[1]) and (not(x[0] + tj >= largura))):
x[0] += vel1
if pressed[pygame.K_w]:
if(not(distX <= tj and abs(y[0] - (y[1] - vel2)) <= tj and y[1] > y[0]) and (not(y[1] <= 0))):
y[1] -= vel2
if pressed[pygame.K_s]:
if(not(distX <= tj and abs(y[0] - (y[1] + vel2)) <= tj and y[1] < y[0]) and (not(y[1]+tj >= altura))):
y[1] += vel2
if pressed[pygame.K_a]:
if(not(abs(x[0] - (x[1] - vel2)) <= tj and distY <= tj and x[1] > x[0]) and (not(x[1] <= 0))):
x[1] -= vel2
if pressed[pygame.K_d]:
if(not(abs(x[0] - (x[1] + vel2)) <= tj and distY <= tj and x[1] < x[0]) and (not(x[1]+tj >= largura))):
x[1] += vel2
# Movimento da Bola
velBola1 = ceil(vel1)
velBola2 = ceil(vel2)
# Movimento da Bola pra Direita (J1)
if(distTX<=0 and x[0]<t and distTY <= -4):
t += velBola1
if pressed[pygame.K_RCTRL]:
## clock = pygame.time.Clock()
## clock.tick()
## clock.tick()
## clock.get_time()
velchute = 0
tempo1 = int(time.time())
while(o):
clock = pygame.time.Clock()
clock.tick()
if(not(event.type == pygame.KEYUP and event.type == pygame.K_RCTRL)):
o = False
clock.tick()
clock.get_time()
velchute = 0
else:
tempo2 = clock.get_time()
velchute = 16 + tempo2
print(tempo2 - tempo1)
p = True
# Movimento da Bola pra Esquerda (J1)
if(distTX<=0 and x[0]>t and distTY <= -(velBola1)):
t -= velBola1
## if pressed[pygame.K_RCTRL]:
#### clock = pygame.time.Clock()
#### clock.tick()
#### clock.tick()
#### clock.get_time()
## velchute = 0
## clock = pygame.time.Clock()
## tempo = int(time.time())
if(chute):
tempoInicial = time.time()
print("EITAAA")
chute = False
if(chuteAcabou):
print("OITTTTEEE")
if(tempoFinal ==1):
tempoFinal =0
tempoInicial =0
chuteAcabou = False
velchute = 8
else:
tempoFinal = time.time()
tempoPercorrido = int(round((tempoFinal - tempoInicial), 3) * 1000)
print(tempoPercorrido)
chuteAcabou = False
velchute = tempoPercorrido // 30
p = True
elif(distTX>= 50):
tempoInicial = 0
tempoFinal = 1
# Movimento da Bola pra Direita (J2)
if(distTX1<=0 and x[1]<t and distTY1 <= -(velBola2)):
t += velBola2
# Movimento da Bola pra Esquerda (J2)
if(distTX1<=0 and x[1]>t and distTY1 <= -(velBola2)):
t -= velBola2
# Movimento da Bola pra Baixo (J1)
if(distTY<=0 and y[0]<k and distTX <= -(velBola1)):
k += velBola1
# Movimento da Bola pra Cima (J1)
if(distTY<=0 and y[0]>k and distTX <= -(velBola1)):
k -= velBola1
# Movimento da Bola pra Baixo (J2)
if(distTY1 <= 0 and y[1]<k and distTX1 <= -(velBola2)):
k += velBola2
# Movimento da Bola pra Cima (J2)
if(distTY1 <= 0 and y[1]>k and distTX1 <= -(velBola2)):
k -= velBola2
# Gol do J2
if(t + r > largura and k > altura//4 and k < 3 * altura // 4):
print("GOL DO CAIO") # colocar isso no display, ou apagar
placarJ1 += 1
return main()
# Gol do J1
if(t - r < 0 and k > altura//4 and k < 3 * altura // 4):
print("GOL DO MAGNUS") # colocar isso no display, ou apagar
placarJ2 += 1
return main()
# Ferramenta de Debug
if pressed[pygame.K_o]:
print("jogador 1: ", distTX, distTY, "jogador 2: ", distTX1, distTY1 , t , k)
screen.fill((0, 0, 0))
if(p):
if(x[0]<t):
t += velchute
velchute -= 1
if(velchute<=0):
p = False
velchute = 0
else:
t -= velchute
velchute -=1
if(velchute<=0):
p = False
velchute = 0
if is_blue:
blue = (0, 0, 255)
black = (0,0,0)
orange = (255, 100, 0)
white = (255,255,255)
darkGreen = (0,100,0)
cinza = (100, 100, 100)
yellow = (255, 255, 0)
# Gramado
pygame.draw.rect(screen,darkGreen,pygame.Rect(0,0,largura,altura))
# Círcunferência Central
pygame.draw.circle(screen,white,[largura//2,altura//2],70,1)
# Linha Central
pygame.draw.rect(screen,white,pygame.Rect(largura//2,0,1,altura))
# Área Esquerda
pygame.draw.rect(screen,white,pygame.Rect(0,altura//4,170,1))
pygame.draw.rect(screen,white,pygame.Rect(0,3 * altura//4,170,1))
pygame.draw.rect(screen,white,pygame.Rect(170,altura//4,1,altura//2))
# Área Direita
pygame.draw.rect(screen,white,pygame.Rect(largura - 170,altura//4,170,1))
pygame.draw.rect(screen,white,pygame.Rect(largura - 170,3 * altura//4,170,1))
pygame.draw.rect(screen,white,pygame.Rect(largura - 170,altura//4,1,altura//2))
# Jogadores de Futebol
pygame.draw.rect(screen, blue, pygame.Rect(x[0], y[0], tj, tj))
pygame.draw.rect(screen, orange, pygame.Rect(x[1], y[1], tj, tj))
# Bola
pygame.draw.circle(screen, cinza, [t,k], r)
pygame.draw.circle(screen, cinza, [t,k], r)
# Barra de Energia Direita
pygame.draw.rect(screen, yellow, pygame.Rect(largura - 50 - energiaJ1 * 2, 50, energiaJ1 * 2, 50))
# Barra de Energia Esquerda
pygame.draw.rect(screen, yellow, pygame.Rect(50, 50, energiaJ2 * 2, 50))
# Placar
screen.blit(placar, (largura//2 - 80 * digitos, 60))
pygame.display.flip()
# Energia / Stamina
if(energiaJ1 < 100):
energiaJ1 += custoEnergia / 7
else:
energiaJ1 = 100
if(energiaJ2 < 100):
energiaJ2 += custoEnergia / 7
else:
energiaJ2 = 100
clock.tick(60)
main()
pygame.quit()