-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·103 lines (90 loc) · 3 KB
/
test.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
#!/usr/bin/env python3
import pygame
from random import *
from pygame.locals import *
pygame.mixer.init()
pygame.mixer.music.load("./assets/John.wav")
pygame.mixer.music.play()
pygame.init()
fenetre = pygame.display.set_mode((700,400))
background = pygame.image.load("./assets/fond1.png").convert()
raquette1 = pygame.image.load("./assets/bat2.png").convert()
raquette2 = pygame.image.load("./assets/bat3.png").convert()
balle = pygame.image.load("./assets/ball2.png").convert()
rand = int(random() * 400)
pos_balle = balle.get_rect(topleft =(15, rand))
pos_raquette1 = raquette1.get_rect(topleft =(10, 150))
pos_raquette2 = raquette2.get_rect(topleft =(680, 150))
xr1 = 150
yr1 = 250
xr2 = 150
yr2 = 250
xb = 15
yb = rand
test = 0
test2 = 0
v = 250
compteur = 1
pygame.display.flip()
continuer = 1
clock = pygame.time.Clock()
def my_display() :
fenetre.blit(background, (0,0))
fenetre.blit(balle, (pos_balle))
fenetre.blit(raquette1, (pos_raquette1))
fenetre.blit(raquette2, (pos_raquette2))
pygame.display.flip()
my_display()
while continuer :
for event in pygame.event.get():
if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE :
continuer = 0
k = pygame.key.get_pressed()
if k[K_DOWN] and pos_raquette2 != (680, 300, 10, 100):
pos_raquette2 = pos_raquette2.move(0, 1)
xr2 = xr2 + 1
yr2 = yr2 + 1
if k[K_UP] and pos_raquette2 != (680, 0, 10, 100):
pos_raquette2 = pos_raquette2.move(0, -1)
xr2 = xr2 - 1
yr2 = yr2 - 1
if k[K_z] and pos_raquette1 != (10, 0, 10, 100):
pos_raquette1 = pos_raquette1.move(0, -1)
xr1 = xr1 - 1
yr1 = yr1 - 1
if k[K_s] and pos_raquette1 != (10, 300, 10, 100):
pos_raquette1 = pos_raquette1.move(0, 1)
xr1 = xr1 + 1
yr1 = yr1 + 1
if xb == 673 and xr2 <= yb and yb <= yr2:
test = 1
compteur = compteur + 1
if xb == 20 and xr1 <= yb and yb <= yr1:
test = 0
if yb == 390:
test2 = 1
if yb == 0:
test2 = 0
if xb == 693 or xb == 0:
exit(82)
if test == 1 and test2 == 0:
pos_balle = pos_balle.move(-1, 1)
xb = xb - 1
yb = yb + 1
elif test == 0 and test2 == 0:
pos_balle = pos_balle.move(1, 1)
xb = xb + 1
yb = yb + 1
elif test == 1 and test2 == 1:
pos_balle = pos_balle.move(-1, -1)
xb = xb - 1
yb = yb - 1
elif test == 0 and test2 == 1:
pos_balle = pos_balle.move(1, -1)
xb = xb + 1
yb = yb - 1
if compteur % 3 == 0:
compteur = 1
v = v + 40
my_display()
clock.tick(v)