-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelisa_1_spritesheet.py
72 lines (53 loc) · 1.87 KB
/
elisa_1_spritesheet.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
# auth: christian bitter
# desc: starting from the pygame introduction with a simple template.
# this will not do much, other than create a window
# and load a sprite sheet
import os
import pygame
if not pygame.font:
print("Pygame - Font not loaded")
if not pygame.mixer:
print("Pygame - Mixer not loaded")
def load_image(fp, colorkey=None):
if not fp:
raise ValueError("load_image - fp not provided")
fullname = os.path.join(fp)
try:
image = pygame.image.load(fullname)
except pygame.error as message:
print("Cannot load image:", fullname)
raise SystemExit(message)
image = image.convert()
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0, 0))
image.set_colorkey(colorkey, pygame.RLEACCEL)
return image, image.get_rect()
class Elisa(pygame.sprite.Sprite):
def __init__(self, asset_base: str, *groups):
super().__init__(*groups)
self.asset_base_dir = asset_base
self.animation_assets = {
"IDLE": os.path.join(self.asset_base_dir, "elise_gun_walk@8x.png")
}
self.image, self.rect = load_image(self.animation_assets["IDLE"], -1)
self.idle = 0
pygame.init()
fps_watcher = pygame.time.Clock()
S_WIDTH, S_HEIGHT, S_TITLE = 640, 480, "Elisa1"
C_WHITE = (250, 250, 250)
screen_buffer = pygame.display.set_mode(size=(S_WIDTH, S_HEIGHT))
pygame.display.set_caption(S_TITLE)
back_buffer = pygame.Surface(screen_buffer.get_size())
back_buffer.fill(C_WHITE)
elisa = Elisa(asset_base="asset/elise_character")
allsprites = pygame.sprite.RenderPlain(elisa)
is_done = False
while not is_done:
fps_watcher.tick(60)
for e in pygame.event.get():
if e.type == pygame.QUIT:
is_done = True
screen_buffer.blit(back_buffer, (0, 0))
allsprites.draw(screen_buffer)
pygame.display.flip()