-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
99 lines (75 loc) · 2.6 KB
/
main.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
import pygame as pg
from screen import Screen
from items import player
from map import map_from_file
from button import Button
import os
WIDTH = 1200
HEIGHT = 700
FPS_MAX = 60
TILES_SIZE = 32
def replay():
return False,True
def do_not_replay():
return False,False
def main():
pg.init()
run = True
screen = Screen(WIDTH, HEIGHT, TILES_SIZE)
clock = pg.time.Clock()
pg.display.set_caption("Adledofeu")
pg.display.set_icon(pg.image.load(os.path.join("res","ico.png")))
background = pg.Surface([WIDTH, HEIGHT])
background.fill((135,206,235))
screen.background = background
screen.blit(background, (0,0))
map = map_from_file(os.path.join("niveaux", "lvl4.csv"), tile_size=TILES_SIZE)
screen.set_size_tile(map.width_tile, map.height_tile)
#Boucle du jeu
while run:
dt = clock.tick(FPS_MAX) / 1000 # connait le delta time entre les iterations
fps = round(dt*(FPS_MAX**2),2) # connait les fps
for event in pg.event.get(): # Recupere les events
if event.type == pg.QUIT: # Ferme le jeu quand on quitte
run = False
if event.type == pg.MOUSEBUTTONDOWN:
pass
pg.display.set_caption(str(round(map.countdown, 3)))
# pg.display.set_caption(str(fps))
#update
map.update(screen, dt)
#draw
# pg.display.update(map.draw(screen))
screen.blit(background, (0,0))
map.draw(screen, dt)
# screen.draw_grid()
if map.countdown < 0:
run = False
#update screen
pg.display.flip()
# Boucle de
screen.blit(background, (0,0))
is_in_menu = True
new_game_wanted = False
play_again = Button("Rejouer")
play_again.move_to(200,200)
play_again.change_action(replay)
quit_game = Button("Quitter")
quit_game.change_action(do_not_replay)
quit_game.move_to(100,100)
while is_in_menu:
play_again.draw(screen.surface)
quit_game.draw(screen.surface)
pg.display.flip()
for event in pg.event.get(): # Recupere les events
if event.type == pg.QUIT: # Ferme le jeu quand on quitte
is_in_menu = False
if event.type == pg.MOUSEBUTTONDOWN:
mouse_pos = pg.mouse.get_pos()
if(play_again.is_pos_in(mouse_pos)):
is_in_menu,new_game_wanted = play_again.get_pressed()
if(quit_game.is_pos_in(mouse_pos)):
is_in_menu,new_game_wanted = quit_game.get_pressed()
pg.quit() #quit le module pygame
print(f"Ton score était {map.score}")
main()