-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplash.py
49 lines (42 loc) · 1.6 KB
/
splash.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
# Scripts:
from constants import *
from base_state import BaseState
from sound import menu_bg
# Modules:
import pygame
class Splash(BaseState):
def __init__(self):
super().__init__()
# Next State:
self.next_state = "MENU"
# Screen Text:
self.image = pygame.image.load(f'{SPLASH_PATH}').convert_alpha()
self.rect = self.image.get_rect()
self.rect.center = [WIDTH/2 - 180, HEIGHT/4]
self.pos_y = 2/5 * HEIGHT
# Empty Surface:
self.empty_surface = pygame.Surface(self.image.get_size(), pygame.SRCALPHA)
# Time on Screen:
self.time_text = 0
self.time_render = 40 # 40 ms
self.time_on_screen = self.time_render + 130 # 130 ms
self.time_start_fadeout = self.time_on_screen + 160 # 160 ms
self.time_next_screen = self.time_start_fadeout + 140 # 140 ms
def render_image(self):
if self.time_render <= self.time_text < self.time_on_screen:
self.set_opacity()
self.alpha += 2
elif self.time_on_screen <= self.time_text < self.time_start_fadeout:
SCREEN.blit(self.empty_surface, self.rect.center)
elif self.time_start_fadeout <= self.time_text < self.time_next_screen:
self.set_opacity()
self.alpha -= 2
elif self.time_text >= self.time_next_screen:
self.screen_done = True
menu_bg.play_bg_music(-1)
self.time_text += 1
def draw(self, surface):
# Draw Background:
surface.fill(pygame.Color("black"))
# Render Text:
self.render_image()