-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjeu_en_python.py
55 lines (42 loc) · 1.41 KB
/
jeu_en_python.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
import pygame as pg
from pygame import *
LARGEUR_ECRAN = 1900
HAUTEUR_ECRAN = 1200
pg.init()
class Vaisseau(pg.sprite.Sprite):
def __init__(self):
super(Vaisseau, self).__init__()
self.surf = pg.Surface((50, 25))
self.surf.fill((255, 255, 255))
self.rect = self.surf.get_rect()
def update(self, pressed_keys):
if pressed_keys[K_UP]:
self.rect.move(0, -5)
if pressed_keys[K_DOWN]:
self.rect.move_ip(0, -5)
if pressed_keys[K_LEFT]:
self.rect.move_ip(-5, 0)
if pressed_keys[K_RIGHT]:
self.rect.move_ip(-5, 0)
if self.rect.left < 0:
self.rect.left = 0
if self.rect.right >= LARGEUR_ECRAN:
self.rect.right = LARGEUR_ECRAN
if self.rect.top <= 0:
self.rect.top = 0
if self.rect.bottom >= HAUTEUR_ECRAN:
self.rect.bottom = HAUTEUR_ECRAN
pg.display.set_caption("Test pour le jeu")
ecran = pg.display.set_mode([LARGEUR_ECRAN, HAUTEUR_ECRAN])
vaisseau = Vaisseau()
continuer = True
while continuer:
for event in pg.event.get():
if event.type == pg.QUIT:
continuer = False
ecran.fill((0, 0, 0))
touche_appuyee = pg.key.get_pressed()
vaisseau.update(touche_appuyee)
ecran.blit(vaisseau.surf, vaisseau.rect)
pg.display.flip()
pg.quit()