-
Notifications
You must be signed in to change notification settings - Fork 1
/
utebo_2.py
260 lines (254 loc) · 10.3 KB
/
utebo_2.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
import pygame
from math import ceil
# Feito por Magnus, Rudigus e Caius e Luanus
placarJ1 = 0
placarJ2 = 0
pygame.init()
vel_img = 0
Acel_img = 0
white = (255,255,255)
darkGreen = (0,100,0)
tela = pygame.display.set_mode((600, 600))
pygame.display.set_caption("UTEBO")
fim = True
TextoMenu = "UTEBO"
FonteMenu = pygame.font.SysFont("monospace", 90, 1)
TextoRegras = "Pressione Espaço para continuar"
FonteRegras = pygame.font.SysFont("monospace", 30, 1)
Menu = FonteMenu.render(TextoMenu, 0, (0, 0, 0))
Regras = FonteRegras.render(TextoRegras, 0, (0, 0, 0))
image = pygame.image.load("boladoluan.png")
while(fim):
pressed = pygame.key.get_pressed()
for event in pygame.event.get():
if(event.type == pygame.QUIT):
fim = False
if(pressed[pygame.K_SPACE]):
vel_img+=0.5
Acel_img += vel_img
tela.fill(darkGreen)
tela.blit(image, (150+Acel_img, 350 - Acel_img))
tela.blit(Menu, (150, 0))
tela.blit(Regras, (25, 200))
if(350-Acel_img == 0):
fim = False
pygame.display.flip()
pygame.quit()
def main():
global placarJ1
global placarJ2
digitos = 1 # Auxilia no placar
auxPlacarJ1 = placarJ1
while (auxPlacarJ1 >= 10):
auxPlacarJ1 = auxPlacarJ1 / 10
digitos += 1
print(digitos)
pygame.init()
infoTela = pygame.display.Info()
largura = infoTela.current_w
altura = infoTela.current_h
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))
done = True # Varíável que controla o fluxo do jogo
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] ## coordenada na linha x dos jogadores
y = [altura / 2 - tj//2 , altura / 2 - tj//2] ## coordenada na linha y dos jogadores
vel1 = 4 ##velocidade do jogador 1
vel2 = 4 ##velocidade do jogador 2
multEnergia = 1.5 ## a velocidade aumenta em 50%
r = 14 ##raio da bola
energiaJ1 = 100 ##stamina
energiaJ2 = 100 ##stamina
custoEnergia = 1
clock = pygame.time.Clock()
corrida1 = False
corrida2 = False
while done:
for event in pygame.event.get():
if (event.type == pygame.KEYDOWN and event.key == pygame.K_F1):
placarJ1 = 0
placarJ2 = 0
main()
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_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 (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 + 1
# 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 * 2)
# Bola encosta no teto
if(k - r < 0):
k = r+1
# Bola encosta no chão
if(k + r > altura):
k = altura - (r * 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
# Movimento da Bola pra Esquerda (J1)
if(distTX<=0 and x[0]>t and distTY <= -(velBola1)):
t -= velBola1
# 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 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()