-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.py
86 lines (72 loc) · 2.64 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import pygame
import math
from pygame.locals import *
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))
exec(open('lib/pygame_functions.py').read())
exec(open('lib/Entity.py').read())
exec(open('lib/Perso.py').read())
exec(open('lib/Event.py').read())
exec(open('lib/Map.py').read())
exec(open('lib/Dialogue.py').read())
exec(open('lib/Menu.py').read())
window_dimensions = [800, 600]
pygame.init()
fenetre = pygame.display.set_mode((window_dimensions[0], window_dimensions[1]), pygame.RESIZABLE)
pygame.display.set_caption("Telegame")
perso = Perso(fenetre)
map = Map(fenetre)
map.initFromFile("./res/maps/map_outside")
perso.position = [80, 46]
entities = []
map.refresh(perso.getPosition(), window_dimensions)
perso.afficher(window_dimensions)
pygame.display.flip()
pygame.key.set_repeat(400, 60)
# son = pygame.mixer.Sound("pomme.wav")
# mort = pygame.mixer.Sound("game-over.wav")
# pygame.time.delay(3720)
continuer = 1
while continuer == 1:
needRefresh = False
# pygame.event.wait()
event = pygame.event.wait()
if event.type == QUIT:
continuer = 0
needRefresh = True
if event.type == VIDEORESIZE:
window_dimensions = [event.w, event.h]
fenetre = pygame.display.set_mode((event.w, event.h),
pygame.RESIZABLE)
needRefresh = True
if event.type == KEYDOWN:
if event.key == K_RIGHT:
if map.canWalk(perso.getPosition()[0] + 1, perso.getPosition()[1]):
perso.move(1, 0)
needRefresh = True
if event.key == K_LEFT:
if map.canWalk(perso.getPosition()[0] - 1, perso.getPosition()[1]):
perso.move(-1, 0)
needRefresh = True
if event.key == K_UP:
if map.canWalk(perso.getPosition()[0], perso.getPosition()[1] - 1):
perso.move(0, -1)
needRefresh = True
if event.key == K_DOWN:
if map.canWalk(perso.getPosition()[0], perso.getPosition()[1] + 1):
perso.move(0, 1)
needRefresh = True
if event.key == K_e:
for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
if map.checkEntity((perso.getPosition()[0] + dx, perso.getPosition()[1] + dy)):
map.getEntity((perso.getPosition()[0] + dx, perso.getPosition()[1] + dy)).runScenario()
break
# Gestion des evenements de map
if map.checkEvent(perso.getPosition()):
ev = map.getEvent(perso.getPosition())
ev.act()
needRefresh = True
if needRefresh:
visual_refresh()
pygame.display.quit()
pygame.quit()