-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvariables.py
195 lines (182 loc) · 6.12 KB
/
variables.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
"""variables init"""
from random import randint
from time import time
import pygame
from environment import Environment
from register import BESTSCORE, NAMEID, height, width
from sonic import Sonic
############
#LES TIMERS#
############
# init du delais d'affichage du gif
time_gif = time()
time_gif_duck = time()
time_gif_charac = time()
# init du départ du saut
start_jump = time()
TIMEJUMP = 0.4
# init du temps de spawn des mobs
time_spawn = time()
# init temps d'effet de fond
effect_time = time()
time_score_sound = time()
# timer pour obtenir les ticks
timer = pygame.time.Clock()
end_time = time() - 3
best_score_time = time()
##############
#LES BOOLEENS#
##############
# état de saut
JUMPING = False
FALLING = False
# variable qui maintient le while du jeu
# état de dégat pour effet visuel (fond rouge) ou heal (fond vert)
DAMAGE = False
HEALING = False
BESTSCOREBEATEN = False
# état qui définit si on a perdu ou non
LOST = True
HIGHSCORES = True
# état qui définie quel image du gif on affiche
SONICSTATE = 0
SONICSTANDINGSTATE = 0
# état qui définie quel image du gif on affiche
DUCKSTATE = 0
############
#LES IMAGES#
############
# personnage en gif
# tableau des états de sonic : tab[0][i] -> état de saut, tab[1][i] -> état de standing
states_sonic = [[], []]
states_sonic[0].append(pygame.image.load("images/sonic1.gif").convert_alpha())
states_sonic[0].append(pygame.image.load("images/sonic2.gif").convert_alpha())
states_sonic[0].append(pygame.image.load("images/sonic3.gif").convert_alpha())
states_sonic[0].append(pygame.image.load("images/sonic4.gif").convert_alpha())
states_sonic[1].append(pygame.image.load(
"images/sonicStanding1.gif").convert_alpha())
states_sonic[1].append(pygame.image.load(
"images/sonicStanding2.gif").convert_alpha())
# le canard en gif
states_duck = []
states_duck.append(pygame.image.load("images/duck1.png").convert_alpha())
states_duck.append(pygame.image.load("images/duck2.png").convert_alpha())
# init des enemies
enemy_spike_surface = pygame.image.load("images/spike.png").convert_alpha()
enemy_bird_surface = pygame.image.load("images/bird.png").convert_alpha()
rock_surface = pygame.image.load("images/rock.png").convert_alpha()
enemies = []
# sonic en saut
sonic_jump_surface = pygame.image.load("images/sonicJump.png").convert_alpha()
# le coeur
heart_surface = pygame.image.load("images/heart.png").convert_alpha()
grass_surface = pygame.image.load("images/grass.png").convert_alpha()
grass_rect = Environment(grass_surface.get_rect(
topleft=(0, height)), grass_surface, "grass")
grass_2_rect = Environment(grass_surface.get_rect(
topleft=(width, height)), grass_surface, "grass")
grass_3_rect = Environment(grass_surface.get_rect(
topleft=(width / 2, height)), grass_surface, "grass")
cloud_surface = pygame.image.load("images/cloud.png").convert_alpha()
cloud_rect = Environment(cloud_surface.get_rect(
topleft=(
width + randint(0, 500),
randint(200, height / 2)
)
),
cloud_surface, "cloud1"
)
cloud_2_rect = Environment(cloud_surface.get_rect(
topleft=(
width + randint(0, 500),
randint(200, height / 2)
)
),
cloud_surface, "cloud2"
)
cloud_rect.speed = (620, 0)
cloud_2_rect.speed = (550, 0)
palm_surface = pygame.image.load("images/palm-min.png").convert_alpha()
palm_2_surface = pygame.image.load("images/palm2-min.png").convert_alpha()
palm_rect = Environment(palm_surface.get_rect(
topleft=(
width+randint(0, 500),
height - 200
)
),
palm_surface, "palm1"
)
palm_2_rect = Environment(palm_2_surface.get_rect(
topleft=(
width + randint(1000, 2500),
height - 200
)
),
palm_2_surface, "palm2"
)
palm_2_rect.speed = (475, 0)
palm_rect.speed = (475, 0)
######################
#LES TYPES DE CLASSES#
######################
sonic_jump_rect = Sonic(sonic_jump_surface.get_rect(
topleft=(100, height - 200 - 144*4)))
sonic_1_rect = Sonic(states_sonic[0][0].get_rect(
topleft=(100, height - 200 - 144)))
################
#LES TYPES RECT#
################
heart_rect = heart_surface.get_rect(topleft=(65, 65))
# rect qui restreint le personnage
sonic_rect = pygame.Rect((100, 200), (128, height - 400))
##########
#LES SONS#
##########
HEALINGPATH = "sounds/healing.wav"
JUMPPATH = "sounds/jump.mp3"
DAMAGEPATH = "sounds/damage.wav"
LOSTPATH = "sounds/lost.wav"
SCOREPATH = "sounds/score.wav"
SCORE1000PATH = "sounds/best_score.wav"
BESTSCOREPATH = "sounds/best_score.wav"
MAINMUSIC = "sounds/mainMusic.wav"
####################
#TEXTES SUR L'ECRAN#
####################
scoreTimer = time()
FONTPATH = "font/BACKTO1982.TTF"
score_font = pygame.font.Font(FONTPATH, 40)
big_font = pygame.font.Font(FONTPATH, width // 30)
score_live_font = pygame.font.Font(FONTPATH, 150)
score_surface = score_live_font.render("0", True, (0, 0, 0))
last_score_surface = score_font.render(f"Last score : {0}", True, (0, 0, 0))
last_score_rect = last_score_surface.get_rect(midtop=(width/2, 100))
best_score_surface = score_font.render(
f"Best score : {BESTSCORE}", True, (0, 0, 0))
best_score_rect = best_score_surface.get_rect(midtop=(width/2, 25))
restart_surface = big_font.render("PRESS SPACE TO START", True, (255, 10, 10))
restart_rect = restart_surface.get_rect(midtop=(width/2, height/2))
# bouton pour fermer la fenetre
end_font = pygame.font.Font(FONTPATH, 50)
end_surface = end_font.render("CLOSE", True, (0, 0, 0))
end_rect = end_surface.get_rect(topright=(width - 10, 10))
# bouton best_scores screen
scores_screen_surface = end_font.render("HIGHSCORES", True, (0, 0, 0))
scores_screen_rect = scores_screen_surface.get_rect(topright=(width - 10, 75))
# écran de fin
game_over_surface = score_live_font.render("GAME OVER", True, (0, 0, 0))
game_over_rect = game_over_surface.get_rect(
midtop=(
width / 2,
height / 2 - game_over_surface.get_size()[1] / 2
)
)
# pseudo
pseudo_font = pygame.font.Font(FONTPATH, int(width // 3 // len(NAMEID)))
pseudo_surface = pseudo_font.render(f"{NAMEID}", True, (0, 0, 0))
pseudo_rect = pseudo_surface.get_rect(topleft=(30, 30))
# background music
pygame.mixer.init()
pygame.mixer.music.load("sounds/mainMusic.wav")
pygame.mixer.music.play(-1)
pygame.mixer.music.set_volume(0.18)