-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
105 lines (80 loc) · 3.15 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
100
101
102
103
104
105
import pygame, os, random, time as tim
from pygame.locals import *
from src.helpers import *
from src.parameters import *
from src.game import Game
class Director:
"""Representa el objeto principal del juego.
El objeto Director mantiene en funcionamiento el juego, se
encarga de actualizar, dibuja y propagar eventos.
Tiene que utilizar este objeto en conjunto con objetos
derivados de Scene."""
def __init__(self, scenes, data):
# Display
self.screen = pygame.display.set_mode([WIDTH, HEIGHT])
#self.screen = pygame.display.set_mode([WIDTH, HEIGHT], flags = pygame.FULLSCREEN)
# Screen name
pygame.display.set_caption("Global")
# Icon
#icon = load_image("assets/images/bobi_icon.png")
#pygame.display.set_icon(icon)
# Variables
self.clock = pygame.time.Clock()
self.quit_flag = False
#Options
pygame.key.set_repeat(10)
# pygame.mixer.music.set_volume(MASTER_VOLUMEN)
self.scenes = scenes
self.current_scene = self.scenes["init"]
self.data = data
def presentation_screen(self, path):
screen_image = load_image(path)
self.screen.blit(screen_image, screen_image.get_rect())
pygame.display.flip()
def run(self):
self.current_scene = self.scenes["init"]
self.current_scene.load(self.data) # Se le manda el diccionario de datos para que se configure.
while not self.quit_flag:
time = self.clock.tick(60) # Must be in loop
# Eventos de Salida
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
self.quit()
# detecta eventos
self.current_scene.on_event(time, event)
# actualiza la escena
self.current_scene.on_update(time)
# dibuja la pantalla
self.current_scene.on_draw(self.screen)
pygame.display.flip()
if self.current_scene.next:
self.change_scene()
def change_scene(self):
self.current_scene.finish(self.data) # Se le manda el diccionario de datos para que lo actualice.
self.current_scene = self.scenes[self.current_scene.next]
self.current_scene.load(self.data) # Se le manda el diccionario de datos para que se configure.
def quit(self):
self.quit_flag = True
#s = pygame.Surface((1000,750)) # the size of your rect
#s.set_alpha(128) # alpha level
#s.fill((255,255,255)) # this fills the entire surface
#screen.blit(s, (0,0))
if __name__ == '__main__':
#pygame.mixer.pre_init(44100, -16, 2, 2048)
#pygame.mixer.init()
pygame.init()
scenes = {"init" : None}
data = {}
director = Director(scenes, data)
#director.presentation_screen("assets/images/presentation_screen.png")
data = {
}
scenes = {
"init" : Game(MINIGAMES_DATA["5"])
}
director.data = data
director.scenes = scenes
director.run()