-
Notifications
You must be signed in to change notification settings - Fork 0
/
titleScreen.py
546 lines (370 loc) · 15.3 KB
/
titleScreen.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
import sys
from glyphRings import GlyphRings
from panda3d.core import (
TransparencyAttrib,
CardMaker,
NodePath,
Vec4,
Vec3,
Point3,
LVector3,
)
from direct.gui.OnscreenImage import OnscreenImage
from direct.interval.LerpInterval import (
LerpColorInterval,
LerpScaleInterval,
LerpPosInterval,
)
from direct.interval.IntervalGlobal import Sequence, Wait, Parallel
from direct.particles.ParticleEffect import ParticleEffect
from direct.particles.Particles import Particles, BaseParticleEmitter
import math
from stageflow import Stage
from motionBlur import MotionBlur
class TitleScreen(Stage):
def __init__(self, exit_stage="worldcage"):
self.exit_stage = exit_stage
self.colors = [
Vec4(1, 0, 0, 1), # Red
Vec4(1, 0.5, 0, 1), # Orange
Vec4(1, 1, 0, 1), # Yellow
Vec4(0, 1, 0, 1), # Green
Vec4(0, 0, 1, 1), # Blue
Vec4(0.29, 0, 0.51, 1), # Indigo
Vec4(0.56, 0, 1, 1), # Violet
]
self.rotation_speed = 60 # Degrees per second
self.globalClock = globalClock # Assuming globalClock is defined elsewhere
self.wave_amplitude = 0.125 # Amplitude of the wave effect
self.wave_frequency = 5.0
def enter(self, exit_stage="worldcage"):
self.motion_blur = MotionBlur()
base.accept("enter", base.flow.transition, ["worldcage", base.lvl])
base.accept("gamepad-start", base.flow.transition, ["worldcage", base.lvl])
base.enableParticles()
base.cam.set_z(32)
base.cam.look_at(render)
print(self)
self.glyph_font = base.loader.load_font("fonts/konnarian/Daemon.otf")
self.glyph_rings = GlyphRings(self.glyph_font, 16, 16)
self.star_and_logo()
self.current_color_index = 0
# Define the stars' base radius from the center of the galaxy
self.base_radius = 10.0
# Variables to control time and direction
self.time = 0.0
self.spin_speed = 1.0 # Speed of the spinning
self.scale_speed = 1.0 # Speed of the inward/outward scaling
self.inward = True # To track whether we're moving inward or outward
base.bgm.playMusic("灵林 - 灵魂交响乐 - 标题画面", True, 1)
base.bgm.playSfx("soul-symphony")
self.update_task = base.task_mgr.add(self.update, "update")
base.accept("escape", sys.exit)
def cycle_colors(self, task):
# Set the color of the object to the current color in the array
self.imageObject.setColor(self.colors[self.current_color_index])
# Move to the next color in the array
self.current_color_index = (self.current_color_index + 1) % len(self.colors)
# Continue the task on the next frame
return task.cont
def transition(self, exit_stage):
print(exit_stage)
base.flow.transition(exit_stage=exit_stage)
def create_logo_wave(self):
# Define the wave parameters
wave_scale_min = (1.45, 1, 0.65) # Minimum scale values
wave_scale_max = (1.55, 1, 0.55) # Maximum scale values
wave_duration = 1 # Total duration for one complete wave cycle
y_offset_amplitude = 0.005 # Max offset in the y direction
frequency = 2 # Frequency of the sine wave
def update_wave(task):
# Calculate the current time in the wave cycle
current_time = (task.time % wave_duration) / wave_duration
scale_factor = wave_scale_min[0] + (
wave_scale_max[0] - wave_scale_min[0]
) * 0.5 * (1 + math.sin(2 * math.pi * frequency * current_time))
y_offset = y_offset_amplitude * math.sin(
2 * math.pi * frequency * current_time
)
# Update the object's scale and position
self.imageObject.setScale(
scale_factor, 1, 0.65
) # Assuming you want to keep y constant
self.imageObject.setZ(self.imageObject.getZ() + y_offset)
return task.cont # Continue the task
# Add the update_wave function to the task manager
base.taskMgr.add(update_wave, "logo_wave_task")
def star_and_logo(self):
# Load the star image
self.star_node = NodePath("star_node")
self.star_card = CardMaker("star_card")
self.star_card.set_frame(0, 0, 1, 1)
self.imageObject2 = OnscreenImage(
image="graphics/star.png", pos=(0.0, 0.0, 0.0), scale=(1, 1, 1)
)
self.imageObject2.setTransparency(TransparencyAttrib.MAlpha)
self.imageObject3 = OnscreenImage(
image="graphics/star2.png", pos=(0.0, 0.0, 0.0), scale=(1, 1, 1)
)
self.imageObject3.setTransparency(TransparencyAttrib.MAlpha)
# Correctly attach the generated node
self.star_spinner = self.star_node.attach_new_node(self.star_card.generate())
self.star_spinner.setPos(0, 0, 0) # Center it at the origin
self.star_decal = self.centerPivot(self.star_spinner)
self.star_decal.setScale(1.0, 1.0, 1.0)
self.logo_card = CardMaker("logo_card")
self.logo_card.set_frame(0, 0, 1, 1)
self.imageObject = OnscreenImage(
image="graphics/SoulSymphonyLogoCN.png",
pos=(-0.0, -0.0, 0.0),
scale=(1, 1, 1),
)
self.imageObject.setTransparency(TransparencyAttrib.MAlpha)
self.bg2 = render.attach_new_node(self.logo_card.generate())
# Start the color cycling task
self.cycle_task = base.taskMgr.add(self.cycle_colors, "cycleColors")
# Create the waving effect using scaling and position intervals
self.create_logo_wave()
# Attach particles to effect and star decal
# Initialize color intervals for cycling through colors
self.star_color_cycle = Sequence(
# ROYGBIV Color Interpolation with staggered time for interference pattern
LerpColorInterval(
self.imageObject2,
0.04,
Vec4(1, 0, 0, 0.15),
startColor=Vec4(1, 0.5, 0, 0),
blendType="easeInOut",
), # Red to Orange
LerpColorInterval(
self.imageObject2,
0.05,
Vec4(1, 1, 0, 0.15),
startColor=Vec4(1, 0, 0, 0),
blendType="easeInOut",
), # Orange to Yellow
LerpColorInterval(
self.imageObject2,
0.06,
Vec4(0, 1, 0, 0.15),
startColor=Vec4(1, 1, 0, 0),
blendType="easeInOut",
), # Yellow to Green
LerpColorInterval(
self.imageObject2,
0.07,
Vec4(0, 0, 1, 0.15),
startColor=Vec4(0, 1, 0, 0),
blendType="easeInOut",
), # Green to Blue
LerpColorInterval(
self.imageObject2,
0.08,
Vec4(0.29, 0, 0.51, 0.15),
startColor=Vec4(0, 0, 1, 0),
blendType="easeInOut",
), # Blue to Indigo
LerpColorInterval(
self.imageObject2,
0.09,
Vec4(0.56, 0, 1, 0.15),
startColor=Vec4(0.29, 0, 0.51, 0),
blendType="easeInOut",
), # Indigo to Violet
LerpColorInterval(
self.imageObject2,
0.1,
Vec4(1, 0, 0, 0.15),
startColor=Vec4(0.56, 0, 1, 0),
blendType="easeInOut",
), # Violet to Red (loop)
)
# Loop the color sequence indefinitely
self.star_color_cycle.loop()
# Initialize color intervals for cycling through colors
self.star_color_cycle2 = Sequence(
# ROYGBIV Color Interpolation
# ROYGBIV Color Interpolation with staggered time for interference pattern
# Mirrored ROYGBIV Color Interpolation with staggered time for interference pattern
LerpColorInterval(
self.imageObject3,
0.1,
Vec4(0.56, 0, 1, 0.15),
startColor=Vec4(1, 0, 0, 0),
blendType="easeInOut",
), # Red to Violet
LerpColorInterval(
self.imageObject3,
0.09,
Vec4(0.29, 0, 0.51, 0.15),
startColor=Vec4(0.56, 0, 1, 0),
blendType="easeInOut",
), # Violet to Indigo
LerpColorInterval(
self.imageObject3,
0.08,
Vec4(0, 0, 1, 0.15),
startColor=Vec4(0.29, 0, 0.51, 0),
blendType="easeInOut",
), # Indigo to Blue
LerpColorInterval(
self.imageObject3,
0.07,
Vec4(0, 1, 0, 0.15),
startColor=Vec4(0, 0, 1, 0),
blendType="easeInOut",
), # Blue to Green
LerpColorInterval(
self.imageObject3,
0.06,
Vec4(1, 1, 0, 0.15),
startColor=Vec4(0, 1, 0, 0),
blendType="easeInOut",
), # Green to Yellow
LerpColorInterval(
self.imageObject3,
0.05,
Vec4(1, 0.5, 0, 0.15),
startColor=Vec4(1, 1, 0, 0),
blendType="easeInOut",
), # Yellow to Orange
LerpColorInterval(
self.imageObject3,
0.04,
Vec4(1, 0, 0, 0.15),
startColor=Vec4(1, 0.5, 0, 0),
blendType="easeInOut",
), # Orange to Red (loop)
)
self.star_color_cycle2.loop()
# Loop the color sequence indefinitely
self.star_color_cycle3 = Sequence(
LerpColorInterval(self.imageObject, 1, Vec4(1, 0, 0, 1)), # Red
Wait(1),
LerpColorInterval(self.imageObject, 1, Vec4(1, 0.5, 0, 1)), # Orange
Wait(1),
LerpColorInterval(self.imageObject, 1, Vec4(1, 1, 0, 1)), # Yellow
Wait(1),
LerpColorInterval(self.imageObject, 1, Vec4(0, 1, 0, 1)), # Green
Wait(1),
LerpColorInterval(self.imageObject, 1, Vec4(0, 0, 1, 1)), # Blue
Wait(1),
LerpColorInterval(self.imageObject, 1, Vec4(0.29, 0, 0.51, 1)), # Indigo
Wait(1),
LerpColorInterval(self.imageObject, 1, Vec4(0.56, 0, 1, 1)), # Violet
Wait(1),
)
self.star_color_cycle3.loop()
# Loop the color sequence indefinitely
# Pulsing effect
# Call the method to create the pulsing effect
self.create_star_pulse()
# Initialize a task to continuously rotate the star
self.rotate_task = base.task_mgr.add(self.rotate_star, "rotate_star")
def load_textures(self):
"""Load textures from the directory and store them in a list."""
for filename in os.listdir(self.textures_path):
if filename.endswith(
(".png", ".jpg", ".jpeg")
): # Adjust for texture formats
texture_path = os.path.join(self.textures_path, filename)
texture = loader.loadTexture(texture_path)
self.textures.append(texture)
if not self.textures:
print("No textures found in ./graphics/stars. Please check the directory.")
def set_star_texture(self, texture_index):
"""Set the texture from the loaded list based on index."""
if self.textures:
texture_stage = TextureStage("starTexture")
self.star_placeholder.setTexture(
texture_stage, self.textures[texture_index]
)
def cycle_textures(self, task):
"""Cycle to the next texture and update the placeholder."""
self.current_texture = (self.current_texture + 1) % len(self.textures)
self.set_star_texture(self.current_texture)
# Schedule next cycle
return task.again
def create_star_pulse(self):
# Star 1 pulsing effect
self.star_pulse = Sequence(
LerpScaleInterval(
self.imageObject2, 1, scale=(0, 0, 0), startScale=(4, 4, 4)
), # Scale up
Wait(0.5), # Wait for half a second
LerpScaleInterval(
self.imageObject2, 1, scale=(4, 4, 4), startScale=(0, 0, 0)
), # Scale down
Wait(0.5), # Wait for half a second before looping
)
self.star_pulse.loop()
# Star 2 pulsing effect
self.star_pulse2 = Sequence(
LerpScaleInterval(
self.imageObject3, 1, scale=(4, 4, 4), startScale=(0, 0, 0)
), # Scale up
Wait(0.5), # Wait for half a second
LerpScaleInterval(
self.imageObject3, 1, scale=(0, 0, 0), startScale=(4, 4, 4)
), # Scale down
Wait(0.5), # Wait for half a second before looping
)
self.star_pulse2.loop()
def rotate_star(self, task):
dt = self.globalClock.get_dt()
new_hpr = self.imageObject2.getHpr() + LVector3(0, 0, self.rotation_speed * dt)
new_hpr2 = self.imageObject3.getHpr() + LVector3(
0, 0, -self.rotation_speed * dt
)
self.imageObject2.setHpr(new_hpr) # Set the new HPR
self.imageObject3.setHpr(new_hpr2)
return task.cont # Continue the task
def centerPivot(self, NP):
pivot = NP.getBounds().getCenter()
parent = NP.getParent()
newNP = parent.attachNewNode("StarSpinner")
newNP.setPos(pivot)
NP.wrtReparentTo(newNP)
return newNP
def press_start(self):
press_start = base.loader.loadModel("models/press_start.bam")
press_start.setP(90)
press_start.setX(-0.5)
press_start.setY(-3.25)
press_start.setZ(-0.7)
press_start.setScale(0.15, 0.15, 0.75)
press_start.reparentTo(base.cam2d)
self.subtitle = press_start
def update(self, task):
dt = self.globalClock.get_dt()
if self.glyph_rings:
self.glyph_rings.update(dt)
self.time += dt
base.camera.setHpr(base.camera, (0.05, 0.05, 0.05))
base.cam.look_at(render)
base.cam.set_z((128 + dt + (math.sin(dt * 10))))
return task.cont
def exit(self, data=None):
if hasattr(self, "cycle_task"):
base.taskMgr.remove(self.cycle_task)
pass
if hasattr(self, "rotate_task"):
base.taskMgr.remove(self.rotate_task)
pass
if hasattr(self, "update"):
base.taskMgr.remove(self.update_task)
self.imageObject.removeNode()
self.imageObject2.removeNode()
self.imageObject3.removeNode()
self.bg2.removeNode()
self.star_spinner.removeNode()
#self.particle.cleanup()
self.glyph_rings.center.detachNode()
base.cam.reparentTo(render)
base.camera.detachNode()
base.bgm.stopMusic()
base.ignore("enter")
base.ignore("gamepad-start")
base.taskMgr.remove("update")
base.taskMgr.remove("logo_wave_task")
return data