-
Notifications
You must be signed in to change notification settings - Fork 0
/
episode.py
138 lines (117 loc) · 5.56 KB
/
episode.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
"""
Copyright 2014, 2015 Andrew Russell
This file is part of PotionWars.
PotionWars is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PotionWars is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PotionWars. If not, see <http://www.gnu.org/licenses/>.
"""
import universal
from universal import *
import conversation
import abc
import music
import person
allEpisodes = {}
postTitleCardFunction = None
postTitleCardFuncArgs = None
def set_post_title_card(postTitleCardFunctionIn, postTitleCardFuncArgsIn=None):
global postTitleCardFunction, postTitleCardFuncArgs
postTitleCardFunction = postTitleCardFunctionIn
postTitleCardFuncArgs = postTitleCardFuncArgsIn
class Episode(universal.RPGObject):
def __init__(self, num, name, nextEpisode=None, scenes=None, currentSceneIndex=0, titleTheme=None, init=None):
self.num = num
self.name = name
self.scenes = scenes
self.currentSceneIndex = 0
self.nextEpisode = nextEpisode
self.titleTheme = titleTheme
self.init = init
allEpisodes[name] = self
def start_episode(self, *startingSceneArgs):
global postTitleCardFunction, postTitleCardFuncArgs
universal.get_screen().fill(universal.DARK_GREY)
music.play_music(self.titleTheme)
universal.state.player.clear_marks()
self.init()
universal.display_text('Episode ' + str(self.num) + ':\n' + self.name, universal.get_world_view(), universal.get_world_view().midleft, isTitle=True)
universal.acknowledge(self.initialize_episode, *startingSceneArgs)
def initialize_episode(self, *startingSceneArgs):
conversation.maxIndex = 0
if startingSceneArgs is ():
self.scenes[self.currentSceneIndex].startScene()
else:
self.scenes[self.currentSceneIndex].startScene(*startingSceneArgs)
try:
postTitleCardFunction(*postTitleCardFuncArgs)
except TypeError:
try:
postTitleCardFunction()
except TypeError:
pass
def end_episode(self, endingSceneArgs=()):
if endingSceneArgs is ():
self.scenes[self.currentSceneIndex].endScene()
else:
self.scenes[self.currentSceneIndex].endScene(*endingSceneArgs)
universal.state.player.currentEpisode = self.nextEpisode.name
#set_post_title_card(allEpisodes[universal.state.player.currentEpisode].init)
universal.state.clear_one_time_encounters()
allEpisodes[universal.state.player.currentEpisode].start_episode()
def next_scene(self, previousSceneArgs=(), startingSceneArgs=()):
if self.scenes[self.currentSceneIndex].endScene:
if previousSceneArgs is ():
self.scenes[self.currentSceneIndex].endScene()
else:
self.scenes[currentSceneIndex].endScene(*previousSceneArgs)
self.currentSceneIndex += 1
try:
if self.scenes[self.currentSceneIndex].init_scene:
self.scenes[self.currentSceneIndex].init_scene()
except IndexError:
import pwutilities
pwutilities.exitLeft(universal.state.player, universal.state.location)
end_content_mode()
else:
if startingSceneArgs is ():
self.scenes[self.currentSceneIndex].startScene()
else:
self.scenes[self.currentSceneIndex].startScene(*startingSceneArgs)
def _save(self):
raise NotImplementedError()
@staticmethod
def _load(loadData):
raise NotImplementedError()
def end_content_mode():
universal.say(universal.format_line(['''That's the end of the content, I hope you've enjoyed playing this far. If you have any comments, criticisms, questions, bug reports, or anything else, either comment on my blog''',
'''spankingrpgs.blogspot.com, or send me an e-mail at sprpgs@gmail.com (please post bug reports on the blog however, so that others can see them). Criticisms are welcome, however please keep them constructive. Saying "This game''',
'''sucks!" tells me nothing except that you didn't like it. Saying "Your combat system felt unbalanced. The magic was way too powerful." tells me much much more.''']), justification=0)
universal.set_commands(['(Esc) To exit'])
universal.set_command_interpreter(quit_interpreter)
allScenes = {}
class Scene(universal.RPGObject):
"""
A scene has a name, a startFunction, and an endFunction.
The startFunction is a function that is invoked when the scene begins.
The endFunction is a function that is invoked when the scene ends.
Note that the functions can have arbitrary arguments, however you need to make sure to pass the correct arguments to the
next_scene() method of the current episode.
"""
def __init__(self, name, startScene, endScene):
self.name = name
self.startScene = startScene
self.endScene = endScene
allScenes[name] = self
self.init_scene = None
def _save(self):
raise NotImplementedError()
@staticmethod
def _load(loadData):
raise NotImplementedError()