-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
62 lines (46 loc) · 1.82 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
import pygame
from game import Game
pygame.init()
pygame.display.set_caption("Test")
screen = pygame.display.set_mode((1080, 720))
background = pygame.image.load('assets/bg.jpg')
game = Game()
running = True
while running:
screen.blit(background, (0, -200))
screen.blit(game.player.image, game.player.rect)
for projectil in game.player.all_projectiles:
projectil.move()
for monster in game.all_monsters:
monster.forward()
game.all_monsters.draw(screen)
game.player.all_projectiles.draw(screen)
# vérifier si le joueur souhaite aller à gauche ou à droite
if game.pressed.get(pygame.K_RIGHT) and game.player.rect.x + game.player.rect.width < screen.get_width():
game.player.move_right()
elif game.pressed.get(pygame.K_LEFT) and game.player.rect.x > 0:
game.player.move_left()
# mettre à jour la fenetre
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
elif event.type == pygame.KEYDOWN:
game.pressed[event.key] = True
if event.key == pygame.K_SPACE:
game.player.launch_projectile()
elif event.type == pygame.KEYUP:
game.pressed[event.key] = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
print('left')
if event.key == pygame.K_RIGHT:
print('right')
if event.key == pygame.K_UP:
print('jump')
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
print('left stop')
if event.key == pygame.K_RIGHT:
print('right stop')