-
Notifications
You must be signed in to change notification settings - Fork 0
/
Donkey Kong Labyrinthus.py
114 lines (89 loc) · 3.48 KB
/
Donkey Kong Labyrinthus.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
104
105
106
107
108
109
110
111
112
113
114
"""
Jeu Donkey Kong Labyrinthe
Jeu dans lequel on doit déplacer DK jusqu'aux bananes à travers un labyrinthe.
Script Python
Fichiers : dklabyrinthe.py, classes.py, constantes.py, sprites, levels
"""
import pygame
from os.path import exists
from classes import *
from constantes import *
# initialize window
pygame.init()
window = pygame.display.set_mode((WIDTH_WINDOW, WIDTH_WINDOW))
pygame.display.set_caption(TITLE_WINDOW)
background = pygame.image.load(BG_LEVEL).convert()
icone = pygame.image.load(DK_DOWN)
pygame.display.set_icon(icone)
# initialize sounds
WIN_SOUND = pygame.mixer.Sound(WIN_SOUND_FILE)
LEVEL_SOUND = pygame.mixer.Sound(LEVEL_SOUND_FILE)
######################################################################
def open_level(number):
file = "levels/level %s.txt" % number
if exists(file):
window.blit(background, (0,0))
level = Level.openFile(file)
level.display(window)
perso = Donkey(DK_UP, DK_DOWN, DK_LEFT, DK_RIGHT, level)
window.blit(perso.direction, (0, 0))
pygame.display.flip()
return perso
else:
raise FileNotFoundError
def menu():
background = pygame.image.load(HOME_SCREEN).convert()
window.blit(background, (0,0))
pygame.display.flip()
######################################################################
menu()
while playing:
while state_of_game == "menu":
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key in LIST_OF_F_KEYS:
number_of_level = LIST_OF_F_KEYS.index(event.key) + 1
try:
donkey = open_level(number_of_level)
except FileNotFoundError:
pass
else:
LEVEL_SOUND.play()
state_of_game = "playing"
if event.key == K_ESCAPE:
playing = False
state_of_game = "quit"
pygame.time.Clock().tick(30)
while state_of_game == "playing":
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
menu()
state_of_game = "menu"
win = None
if event.key == K_UP:
window.blit(background, (0,0))
win = donkey.move('up', window)
if event.key == K_DOWN:
window.blit(background, (0,0))
win = donkey.move('down', window)
if event.key == K_LEFT:
window.blit(background, (0,0))
win = donkey.move('left', window)
if event.key == K_RIGHT:
window.blit(background, (0,0))
win = donkey.move('right', window)
pygame.display.flip()
if win is True:
WIN_SOUND.play()
# waiting for menu
not_escape_pressed = True
while not_escape_pressed:
for event in pygame.event.get():
if event.type == KEYDOWN \
and event.key == K_ESCAPE:
not_escape_pressed = False
pygame.mixer.fadeout(300)
menu()
state_of_game = "menu"
pygame.time.Clock().tick(30)