Debian Codegraph @

scripts/modules/intro.py

raw symbols SCIP
1 #
2 # (C) Copyright 2001 Alexandre Courbot <[email protected]>
3 # Part of the Adonthell Project http://adonthell.linuxgames.com
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License.
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY.
9 #
10 # See the COPYING file for more details
11 #
12
13 # -- Introduction sequence for Waste's Edge.
14 #
15 # Dirty, ugly, quickly made, random programmed.
16
17 from adonthell import *
18
19 # -- pygettext support
20 def _(message): return nls_translate (message)
21
22 def update_im (im, x):
23 if x <= -im.length (): x = x + im.length ()
24 else: x = x - 1
25 return x
26
27 def draw_im (im, x):
28 im.draw (x, 0, da)
29 if x < screen_length () - im.length (): im.draw (im.length () + x, 0, da)
30
31 # Our drawing area for the scrolling forest.
32 da = drawing_area ()
33 da.resize (screen_length (), screen_height ())
34 da.move (0, 0)
35
36 # The images...
37 im1 = image ()
38 im2 = image ()
39 im3 = image ()
40 bg = image ()
41 inn_close = image ()
42 talan = image ()
43 player = image ()
44
45 im1.load_raw ("gfx/cutscene/forest3.img")
46 im2.load_raw ("gfx/cutscene/forest2.img")
47 im2.set_mask (True)
48 im3.load_raw ("gfx/cutscene/forest1.img")
49 im3.set_mask (True)
50 bg.load_raw ("gfx/cutscene/intro_bg.img")
51 bg.set_alpha (0)
52 inn_close.load_raw ("gfx/cutscene/intro_inn.img")
53 inn_close.set_mask (True)
54 talan.load_raw ("gfx/cutscene/intro_talan.img")
55 talan.set_mask (True)
56 player.load_raw ("gfx/cutscene/player.img")
57 player.set_mask (True)
58
59 imblack = image ()
60 imblack.resize (screen_length (), screen_height ())
61 imblack.fillrect (0, 0, imblack.length (), imblack.height (), 0)
62
63 # ...their x coordinate...
64 x1 = 0
65 x2 = 0
66 x3 = 0
67
68 # ...and their delay time.
69 o1 = 0
70 o2 = 0
71 o3 = 0
72
73 # The text window.
74 theme = win_manager_get_theme ("original")
75 font = win_manager_get_font ("white")
76 cont = win_container ()
77 cont.resize (250, 100)
78 cont.move ((screen_length () - cont.length ())//2,
79 (screen_height () - cont.height ())//4)
80
81 cont.set_border (theme)
82 cont.set_background (theme)
83 cont.set_trans_background (True)
84
85 lab = win_label ()
86 lab.move (5, 5)
87 lab.resize (cont.length () - 10, cont.height () - 10)
88 lab.fillrect(0, 0, cont.length () - 10, cont.height () - 10, 0)
89 lab.set_font (font)
90 lab.pack ()
91
92 cont.add (lab)
93
94 wintext = (_("One week out of Cirdanth, the trail had\nbecome hard. I had begun to wonder\ndays ago whether \
95 it could still be called\na trail, but it was the only way the\ncaravans had."),
96 _("There were no caravans now, only me,\nand I had seen few others on the road.\nEven those had \
97 become more scarce\nthe further I went."),
98 _("It was easy to see why."),
99 _("The Lady Silverhair, intent on her\nmission, had gone on ahead while I was\nleft to complete \
100 business in her name,\ntrusting me to follow in good speed."),
101 _("A lone Half-Elf may travel with much\nmore speed than an Elven lady and her\nservants, so she \
102 was now only a day\nahead. The thought nearly caused me\nto forget \
103 the harshness of the road."),
104 _("Still, Waste's Edge was a welcome sight."),
105 _("As you approach the trading post, there\nseems to be little sign of life. \
106 \n \nEventually you find the Redwyne Inn,\nwhich seems to be the main building\nhere."),
107 _("The heavy wooden doors are closed,\nand no one is there \
108 to let you in. As you\napproach the gate, you suddenly hear\na voice from within."),
109 _(" \nSuddenly, it looked like the day would\nbe harder than I thought ..."))
110
111 cont.set_visible_background (False);
112 cont.set_visible_border (False);
113 cont.set_visible_all (True);
114 cont.set_activate (True)
115
116 # Images for the speech
117 bubbg = (0, image(), image())
118 bubbg[1].load_raw ("gfx/cutscene/intro_guard.img")
119 bubbg[2].load_raw ("gfx/cutscene/intro_player.img")
120
121 # Text for the speech
122 if gamedata_player () != None: myname = gamedata_player ().get_name ()
123 else: myname = "Banec"
124
125 bubtext = ((_("Halt! Stand and declare yourself, stranger!"), "red", 25, 5, 350, 1),
126 (_("I am ") + myname + _(", come as an agent for my employer. Tell me, is this the trading \
127 post of Waste's Edge?"), "yellow", 130, 5, 500, 2),
128 (_("That it is, but this is all you'll see of it."), "red", 25, 5, 300, 1),
129 (_("If you turn now and make haste, you should be able to make safe camping \
130 before dark."), "red", 25, 5, 400, 1),
131 (_("Turn back? Whatever for? And why is the gate of a free Inn locked \
132 against a footsore traveller?"), "yellow", 140, 20, 500, 0),
133 (_("I am sorry, traveller, but the Inn is barred and you must be off."), "red", 25, 5, 300, 0),
134 (_("There has been trouble inside and I have instructions to turn away all who \
135 need not be here."), "red", 25, 5, 400, 0),
136 (_("Trouble? Why then, I must get inside. My employer will need me close at \
137 hand!"), "yellow", 140, 30, 500, 0))
138
139 # The audio
140 audio_load_background (0, "audio/at-demo-2.ogg");
141 audio_load_background (1, "audio/at-demo-3.ogg");
142 audio_load_background (2, "audio/at-demo-4.ogg");
143
144 wintextocc = 0
145 wincpt = 0
146 windelay = 0
147 bgcpt = 0
148
149 bgy = 0
150 bgvelocity = 0.18
151
152 inny = 510
153 innvelocity = 0.4
154
155 ply = 843
156 plvelocity = 0.5
157
158 status = -1
159
160 letsexit = 0
161
162 screen_clear ()
163
164 gametime_start_action ()
165 audio_play_background (0)
166
167 while not input_has_been_pushed (SDLK_ESCAPE) and not input_has_been_pushed (SDLK_SPACE) and not letsexit:
168 # Update the stuff
169 input_update ()
170 for i in range (0, gametime_frames_to_skip ()):
171
172 # 1st part: forest scrolling and fade to the inn, with
173 #the text appearing letter-by-letter
174 if status < 4:
175 # Magic number
176 if o1 >= 4:
177 x1 = update_im (im1, x1)
178 o1 = 0
179 else: o1 = o1 + 1
180
181 # Magic number
182 if o2 >= 2:
183 x2 = update_im (im2, x2)
184 o2 = 0
185 else: o2 = o2 + 1
186
187 # Magic number
188 if o3 >= 1:
189 x3 = update_im (im3, x3)
190 o3 = 0
191 else: o3 = o3 + 1
192
193 # Update the label text
194 if wintextocc < len (wintext) - 1:
195 if wincpt < len (wintext[wintextocc]):
196 windelay = windelay + 1
197 if windelay >= 10:
198 if wincpt == 0:
199 lab.set_text ("")
200 if wintextocc == 6:
201 cont.move((screen_length () - cont.length ())//2,
202 (screen_height () - cont.height ()))
203
204 lab.add_text (wintext[wintextocc][wincpt])
205 if wintext[wintextocc][wincpt] == '.': windelay = -50
206 else: windelay = 0
207 wincpt = wincpt + 1
208 else:
209 windelay = windelay + 1
210 # Shall we fade to the Inn view?
211 if status == 0 and wintextocc == 5 and windelay == - 250:
212 audio_fade_out_background (1500)
213 status = 1
214 else:
215 wintextocc = wintextocc + 1
216 wincpt = 0
217 windelay = -500
218 else:
219 # Switch to close inn view?
220 if windelay == -300:
221 audio_play_background (2)
222 status = 4
223 windelay = 0
224 wintextocc = 0
225 else: windelay = windelay + 1
226
227 cont.update ()
228
229 # Fade to the forest
230 if status == -1:
231 if (imblack.alpha ()) > 0:
232 imblack.set_alpha (imblack.alpha () - 1)
233 else: status = 0
234
235 # Fade to the Inn view.
236 if status == 1:
237 bga = bg.alpha ()
238 if bga < 255:
239 if bga == 128:
240 audio_play_background (1)
241 bg.set_alpha (bga + 1)
242 if bg.alpha () == 255:
243 # Start scrolling
244 status = 2
245
246 if status == 2:
247 if inny > - (inn_close.height () - screen_height ()):
248 bgy = bgy + bgvelocity
249 inny = inny - innvelocity
250 ply = ply - plvelocity
251 else: status = 3
252
253 # 2nd part: speech between Talan and the player.
254 if status == 4:
255 if windelay >= 0 and wintextocc < len (bubtext):
256 windelay = -bubtext[wintextocc][4]
257 bub = text_bubble (bubtext[wintextocc][0], bubtext[wintextocc][1], "original")
258 bub.move (bubtext[wintextocc][2], bubtext[wintextocc][3])
259 windelay = windelay + 1
260 currentbg = bubtext[wintextocc][5]
261 else:
262 windelay = windelay + 1
263 if windelay >= 0:
264 wintextocc = wintextocc + 1
265 if wintextocc == len (bubtext):
266 status = 5
267 wintextocc = len (wintext) - 1
268 wincpt = 0
269 windelay = 0
270 lab.set_text ("")
271
272 if status == 5:
273 if wincpt < len (wintext[wintextocc]):
274 windelay = windelay + 2
275 if windelay >= 10:
276 lab.add_text (wintext[wintextocc][wincpt])
277 wincpt = wincpt + 1
278 windelay = 0
279 else:
280 windelay = windelay + 1
281 # Shall we fade to the Inn view?
282 if windelay == 500: letsexit = 1
283
284
285 # Draw the entire scene
286 if status < 2:
287 draw_im (im1, x1)
288 draw_im (im2, x2)
289 draw_im (im3, x3)
290
291 if status > 0 and status < 4:
292 bg.draw (0, int(-bgy), da)
293 inn_close.draw (0, int(inny), da)
294 player.draw (167, int(ply), da)
295
296 if status == -1:
297 imblack.draw (0, 0)
298
299 if status >= 4:
300 if currentbg == 0:
301 bg.draw (0, int(-bgy), da)
302 inn_close.draw (0, int(inny), da)
303 player.draw (167, int(ply), da)
304 talan.draw (51, 39)
305 else: bubbg[currentbg].draw (0, 0)
306
307 if status == 4: bub.draw ()
308
309 if status != 4:
310 cont.draw ()
311
312 screen_show ()
313 gametime_update ()
314
315 audio_unload_background (0)
316 audio_unload_background (1)
317 audio_unload_background (2)
318
319 # Avoid a bad crash...
320 cont.remove (lab)