forked from Carouan/Game_Sebilias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
65 lines (51 loc) · 1.86 KB
/
game.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
import pygame
import pygame.mixer
from map import MapManager
from player import Player
from src.dialog import DialogBox
class Game:
def __init__(self):
self.map = "world"
# cree la fenetre
kingdom = pygame.image.load("../kingdom hearts.jpg")
pygame.display.set_icon(kingdom)
self.screen = pygame.display.set_mode((800, 600), pygame.RESIZABLE)
pygame.display.set_caption("Tales of test")
# generer un joueur
self.player = Player()
self.map_manager = MapManager(self.screen, self.player)
self.dialog_box = DialogBox()
# gerer son
pygame.mixer.music.load("../sounds/zelda.ogg")
pygame.mixer.music.play(-1)
def handle_input(self):
pressed = pygame.key.get_pressed()
if pressed[pygame.K_UP]:
self.player.move_up()
elif pressed[pygame.K_DOWN]:
self.player.move_down()
elif pressed[pygame.K_LEFT]:
self.player.move_left()
elif pressed[pygame.K_RIGHT]:
self.player.move_right()
def update(self):
self.map_manager.update()
def run(self):
clock = pygame.time.Clock()
# boucle du jeux
running = True
while running:
self.player.save_location()
self.handle_input()
self.update()
self.map_manager.draw()
self.dialog_box.render(self.screen)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
self.map_manager.check_npc_collisions(self.dialog_box)
clock.tick(60)
pygame.quit()