-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathloading_screen.py
More file actions
75 lines (60 loc) · 2.07 KB
/
loading_screen.py
File metadata and controls
75 lines (60 loc) · 2.07 KB
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
import pygame as pg
import sys
import os
from random import choice
def terminate():
pg.quit()
def load_image(name, colorkey=None):
path = os.path.join('data', name)
if not os.path.isfile(path):
terminate()
image = pg.image.load(path)
if colorkey is not None:
image = image.convert()
if colorkey == -1:
colorkey = image.get_at((0, 0))
image.set_colorkey(colorkey)
else:
image = image.convert_alpha()
return image
class AnimatedSprite(pg.sprite.Sprite):
def __init__(self, right, top, image, *group):
super().__init__(*group)
self.image = image
self.rect = self.image.get_rect(right=right, top=top)
def movement(self):
self.rect = self.rect.move(5, 0)
def play_intro(width, height, sprite_width, sprite_height):
pg.init()
size = width, height = width, height
screen = pg.display.set_mode(size)
clock = pg.time.Clock()
all_sprites = pg.sprite.Group()
sprite_image = pg.transform.scale(load_image('logo.png'), (sprite_width, sprite_height))
sprite = AnimatedSprite(0, height // 2, sprite_image, all_sprites)
# self.sprite = AnimatedSprite(0, height // 2, sprite_width, sprite_height,
# 'logo.png', self.all_sprites)
FPS = 75
cur_frame = 0
running = True
while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
sys.exit(0)
clock.tick(FPS)
screen.fill((255, 255, 255))
if cur_frame > 59:
all_sprites.update()
all_sprites.draw(screen)
if sprite.rect.centerx < width // 2:
sprite.movement()
if cur_frame > 250:
running = False
break
cur_frame += 1
pg.display.flip()
pg.quit()
# class Intro:
# def __init__(self, width, height, sprite_width, sprite_height, particle_width, paticle_height):
play_intro(800, 700, 300, 50)