-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
195 lines (143 loc) · 6.41 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
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
from scenes.doorScene import *
from scenes.logScene import LogScene
from scenes.mainMenuScene import *
from sceneManager import *
from DialogManager import DialogManager
from log_manager import Typewriter
from scenes.openDoorScene import OpenDoorScene
from sounds_manager import SoundManager
import random
import config
from storyManager import StoryManager
from log_manager import Typewriter
class SceneNames:
DOOR = "doorScene"
OPEN_DOOR = "openDoorScene"
LOG_SCENE = "logScene"
MAIN_MENU = "mainMenuScene"
# to check if a scene is a doorScene, just use `if SceneManager.getCurrentSceneName()[:-1] == SceneNames.DOOR`4
# you can also check for currentScene == -1
currentDoor = 0
DOOR_COUNT = 0
SOUND_FREQ = 20 * 1000 # random sound approx each X sec.
random_sound_wait = 0
def init_dialog(window, initial_text, background_img, fontUsed, Location=(-1,-1)):
return DialogManager(background_img, 20, initial_text, fontUsed, Location)
def mainSceneUpdate():
return
def load_sprite(path):
return pg.image.load(path)
def load_sprite(path):
return pg.image.load(path)
def changeCurrentDoor(goLeft: bool) -> int:
global currentDoor
global DOOR_COUNT
if goLeft and currentDoor > 0:
currentDoor -= 1
elif not goLeft and currentDoor < DOOR_COUNT - 1:
currentDoor += 1
SceneManager.setCurrentScene(f"{SceneNames.DOOR}{currentDoor}")
def main():
global currentDoor
global DOOR_COUNT
global typewriters_screamer
pg.font.init()
font = pg.font.Font("assets/fonts/CourierPrime-Regular.ttf", 24)
StoryManager.setup()
doorScenes = [
DoorScene([load_sprite("assets/images/scenes/Scene01Close Full_2k_1k.png")], changeCurrentDoor, False, True),
DoorScene([load_sprite("assets/images/scenes/Scene02Close Full_2k_1k.png")], changeCurrentDoor, True, True),
DoorScene([load_sprite("assets/images/scenes/Scene03Close Full_2k_1k.png")], changeCurrentDoor, True, True),
DoorScene([load_sprite("assets/images/scenes/Scene04Close Full_2k_1k.png")], changeCurrentDoor, True, True),
DoorScene([load_sprite("assets/images/scenes/Scene05Close Full_2k_1k.png")], changeCurrentDoor, True, False),
]
openDoorScenes = [
OpenDoorScene(pg.image.load("assets/images/scenes/Scene01Open Full_2k_1k.png"), "103"),
OpenDoorScene(pg.image.load("assets/images/scenes/Scene02Open Full_2k_1k.png"), "104"),
OpenDoorScene(pg.image.load("assets/images/scenes/Scene03Open Full_2k_1k.png"), "105"),
OpenDoorScene(pg.image.load("assets/images/scenes/Scene04Close Full_2k_1k.png"), "106"),
]
logScenes = [
LogScene(pg.image.load("assets/images/scenes/log.png"), "103", font, 1),
LogScene(pg.image.load("assets/images/scenes/log.png"), "104", font, 1),
LogScene(pg.image.load("assets/images/scenes/log.png"), "105", font, 1),
LogScene(pg.image.load("assets/images/scenes/log.png"), "106", font, 1),
]
DOOR_COUNT = len(doorScenes)
for i in range(0, len(doorScenes)):
SceneManager.addScene(f"{SceneNames.DOOR}{i}", doorScenes[i])
for i in range(0, len(openDoorScenes)):
SceneManager.addScene(f"{SceneNames.OPEN_DOOR}{i}", openDoorScenes[i])
for i in range(0, len(logScenes)):
SceneManager.addScene(f"{SceneNames.LOG_SCENE}{i}", logScenes[i])
SceneManager.addScene(SceneNames.MAIN_MENU, MainMenuScene())
# SceneManager.setCurrentScene(f"{SceneNames.DOOR}{currentDoor}")
SceneManager.setCurrentScene(f"{SceneNames.DOOR}0")
fpsClock = pg.time.Clock()
window = pg.display.set_mode((config.WINDOW_WIDTH, config.WINDOW_HEIGHT))
pg.display.set_caption("BigBrother")
# Fonts
fontForNPC = pg.font.Font("assets/fonts/CourierPrime-Regular.ttf", 20)
NPCDialogBackground_img = pg.image.load(
'assets/images/utils/backgroundDialogBottom.png') # Remplacez par le chemin de votre image
testText = """Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi archonsectetur,re magnam aliqutationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur"""
typewriters = []
# Sound
SoundManager.load_all()
SoundManager.play_ambient('outdoor_suburb_birds', 4)
last_update_sound = pg.time.get_ticks()
random_sound_wait = SOUND_FREQ * (1 + random.random())
typewriters = []
with open('text_mysterious.txt') as f:
texts_myst = f.read().split('\n')
bottomDialogBox = init_dialog(window, testText, NPCDialogBackground_img, fontForNPC )
EventManager.addEventType("key_h", lambda event: event.type == pg.KEYDOWN and event.key == pg.K_h)
callbackHandlerH = EventManager.registerCallback("key_h",
lambda: displayAllLogs(typewriters, texts, font, 100))
# Story
while True:
if not EventManager.update():
return
# update section
if SceneManager.currentScene != "":
if isinstance(SceneManager.scenes[SceneManager.currentScene], OpenDoorScene):
if StoryManager.currentPerson != "":
text = "..."
if "text" in StoryManager.getCurrentDialog():
text = StoryManager.getCurrentDialog()["text"]
SceneManager.scenes[SceneManager.currentScene].update(fpsClock.get_time(), text)
elif isinstance(SceneManager.scenes[SceneManager.currentScene], LogScene):
if StoryManager.currentPerson != "":
logs = []
for log in StoryManager.getLog():
logs.append(f"{log['start']} - {log['end']} : {log['text']}")
SceneManager.scenes[SceneManager.currentScene].update(fpsClock.get_time(), logs)
else:
SceneManager.scenes[SceneManager.currentScene].update(fpsClock.get_time())
SceneManager.update(fpsClock.get_time())
# draw section
window.fill((0, 0, 0))
SceneManager.render(window)
# render text
for typewriter_screamer in typewriters_screamer:
typewriter_screamer.update()
typewriter_screamer.draw(window)
now = pg.time.get_ticks()
if now - last_update_sound > random_sound_wait:
SoundManager.play_ambient_small(0.1)
random_sound_wait = SOUND_FREQ * (1 + random.random())
last_update_sound = now
# darken for transition
blackScreenSurface = pg.Surface((window.get_rect().w, window.get_rect().h))
blackScreenSurface.fill((0, 0, 0))
blackScreenSurface.set_alpha(SceneManager.blackScreenOpacity)
window.blit(blackScreenSurface, blackScreenSurface.get_rect())
bottomDialogBox.display(window)
#render text
for typewriter in typewriters:
typewriter.update()
typewriter.draw(window)
pg.display.update()
fpsClock.tick(60)
if __name__ == "__main__":
main()