-
Notifications
You must be signed in to change notification settings - Fork 1
/
AMORE_PSICHE.py
326 lines (260 loc) · 9.8 KB
/
AMORE_PSICHE.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# IMPORT LIBRARIES
import pygame as pg
import sys
from utils import *
# GENERAL SETUP
pg.init()
clock = pg.time.Clock()
font = "./font/diogenes/DIOGENES.ttf"
# SCREEN SETUP
display = {
'width': 1280,
'height': 720,
'caption': "AMORE ~ PSICHE",
"color": "white",
"background": pg.image.load("./assets/bg_menu.jpg")
}
# set surfice
pg.display.set_caption(display['caption'])
surface = pg.display.set_mode((display['width'], display['height']), pg.SCALED + pg.RESIZABLE)
# background
surface.fill(display["color"])
display["background"] = pg.transform.scale(display["background"], (1280, 720))
surface.blit(display["background"], (0,0))
# ------------------------------------- MENU ------------------------------------- #
# BUTTON SETUP
play = Button((0,0)).B_text(
" Play ", [font, 65],
bg= (124, 99, 156), color="White", radius=20
)
audio = Button((295, 420)).B_text(
" Audio ON ", [font, 25],
bg = (255, 174, 0), color="white", radius = 15
)
column = pg.sprite.Sprite()
column.image = pg.image.load("./assets/Colonna.png")
column.rect = column.image.get_rect()
column.image = pg.transform.scale(column.image, [200, 210])
column.rect.topleft = (900,510) # width = 200, height = 210
# SET BUTTONS COORDS
play.rect.center = [surface.get_rect().centerx, surface.get_rect().centery]
audio.rect.centerx = surface.get_rect().centerx
menu = pg.sprite.Group()
menu.add(column)
menu.add(audio)
menu.add(play)
# CREDITS SETUP
text_credits = """
DEVELOPER: Marco Mazzeo
GRAPHICS: Mia Masetti
SOUNDS: Luca Pasqualetti & Cosimo Losurdo
DOPPIAGGIO: Tiago Pisanti Vieira
MAPPA ESPOLORAZIONE: Milo Binetti
"""
credits = sprite_font(
surface,
text_credits, (10, 0),
15, font = font,
bg=(62, 62, 62),
txt_color="White"
)
credits.rect.bottom = surface.get_rect().bottom - 10
credits.image.set_alpha(157)
credits.image = credits.image.convert_alpha()
menu.add(credits)
# SKIN SETUP
skin = {
"button": Button((0, 590), colorkey=("white")).B_text(
" SKIN ", [font, 25],
bg = (227, 219, 182), color=(0,0,0), radius= 15
),
"image": Button((865, 100), path = "./assets/pg_pattuglie/pg_tigre.png"),
"menu": Button(
(0, 0), # POS
size = [752, 641] # SIZE
)
}
skin["image"].image = pg.transform.scale(skin["image"].image, (300, 400))
# set button coords
skin["button"].rect.centerx = 1000
# Animation variables
class skin_animation(Button):
def __init__(self, pos, image = "", path = "", vel = 1):
super().__init__(pos)
# sprite variables
if path != "":
self.image = pg.image.load(path)
self.rect = self.image.get_rect()
self.rect.topleft = pos
if image != "":
self.image = image
self.rect = self.image.get_rect()
self.rect.topleft = pos
if path == "" and image == "":
print("Error: make sure to set a path or an image")
# animation variables
self.vel = vel
self.move = True
self.center = self.rect.centery
return
def update(self):
# SET ANIMATION VARIABLES
Ypoint = self.rect.centery
distance = Ypoint - self.center -20
#pg.time.delay(25)
# GO DOWN
if Ypoint >= self.center -31 and self.move == True:
self.rect.centery += self.vel
if Ypoint == self.center +20:
self.move = False
# GO UP
if Ypoint <= self.center +20 and self.move == False:
self.rect.centery -= self.vel
if Ypoint == self.center-20:
self.move = True
return
skin["asset"] = skin_animation(skin["image"].pos, skin["image"].image)
# SKIN MENU
# draw rect menu
pg.draw.rect(skin["menu"].image, (128, 95, 67), skin["menu"].rect, border_radius= 30)
pg.draw.rect(skin["menu"].image, (205, 153, 108), (5, 5, skin["menu"].rect.width -10, skin["menu"].rect.height -10), border_radius= 30)
pg.draw.rect(skin["menu"].image, (0,0,0), (skin["menu"].rect.right -120, 120, 130, 370), border_bottom_left_radius=30, border_top_left_radius=30)
text = pg.font.Font(font, 35)
text.set_bold(True)
skin["menu"].image.blit(
source=text.render("Coming Soon", 1, (128, 95, 67)),
dest=[
surface.get_rect().centerx - skin["menu"].rect.centerx - (pg.font.Font(font, 15).size("Coming Soon")[0]/2),
surface.get_rect().centerx - skin["menu"].rect.centery - (pg.font.Font(font, 15).size("Coming Soon")[1]/2)
]
)
# hide surface background
skin["menu"].image = skin["menu"].image.convert()
skin["menu"].image.set_colorkey((0, 0, 0))
# pos
skin["menu"].rect.center = surface.get_rect().center
skin["menu"].rect.top = surface.get_rect().bottom
# animation variable
def restart_animation():
global exit_SkinMenu, open_SkinMenu, click
global vel, a
exit_SkinMenu = False
open_SkinMenu = False
click = False
vel = 0
a = 0.5
# TODO: add select skins buttons qnd previews (347, 80)
# TODO: add exit button
menu.add(skin["asset"])
menu.add(skin["button"])
def MAIN_MANU(exit_SkinMenu = False, open_SkinMenu = False, click = False, vel = 0, a = 0.5):
while True:
mouse = pg.mouse
mx, my = mouse.get_pos()
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
sys.exit()
# BUTTONS
if play.click(event) and not click:
finish = False
while True:
vel += a
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
sys.exit()
if audio.rect.bottom >=0:
audio.rect.y -= vel
play.rect.y -= vel
finish = False
else:
finish = True
if credits.rect.right >= 0:
credits.rect.x -= vel
finish = False
else:
finish = True
if skin["asset"].rect.y <= display["height"]:
skin["asset"].rect.y += vel
skin["button"].rect.y += vel
column.rect.y += vel
finish = False
else:
finish = True
if finish:
return True
surface.blit(display["background"], (0,0))
menu.draw(surface)
clock.tick(60)
pg.display.update()
return True
if audio.click(event) and not click:
if audio.content.lower().strip() == "audio on":
audio.change_text(" Audio OFF ", bg=(255, 174, 0), txt_color="white", radius=15)
audio.image.set_alpha(157)
audio.image = audio.image.convert_alpha()
audio.rect.centerx = surface.get_rect().centerx
else:
audio.change_text(" Audio ON ", bg=(255, 174, 0), txt_color= pg.Color("white"), radius=15)
audio.rect.centerx = surface.get_rect().centerx
if skin["button"].click(event) and not click:
open_SkinMenu = True
menu.add(skin["menu"])
# EXIT SKIN MENU
if event.type == pg.MOUSEBUTTONDOWN and not skin["menu"].rect.collidepoint(mx, my) and click:
exit_SkinMenu = True
if exit_SkinMenu:
if skin["menu"].rect.y >= surface.get_rect().bottom:
menu.remove(skin["menu"])
exit_SkinMenu = False
open_SkinMenu = False
click = False
vel = 0
a = 0.5
else:
vel += a
skin["menu"].rect.y += vel
if open_SkinMenu:
if skin["menu"].rect.center >= surface.get_rect().center:
vel += a
skin["menu"].rect.y -= vel
# FIXME: controllare se l'utente clicca durante l'animazione
else:
exit_SkinMenu = False
open_SkinMenu = False
vel = 0
a = 0.5
click = True
surface.blit(display["background"], (0,0))
menu.draw(surface)
menu.update()
clock.tick(60)
pg.display.update()
# ------------------------------------- PLAY ------------------------------------- #
play_clicked = False
def start():
actors = pg.sprite.Group()
heros_image = pg.image.load("./assets/actors/heros.jpeg")
heros_image = pg.transform.scale(heros_image, (300, 400))
heros_image = heros_image.convert()
heros_image.set_colorkey((255, 255, 255))
heros = skin_animation((268, 116), image= heros_image)
actors.add(heros)
while True:
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
sys.exit()
if event.type == pg.MOUSEBUTTONDOWN:
print(pg.mouse.get_pos())
heros.update()
surface.blit(display["background"], (0,0))
actors.draw(surface)
clock.tick(60)
pg.display.update()
return
if __name__ == "__main__":
play_clicked = MAIN_MANU()
if play_clicked:
start()