-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite_handler.py
71 lines (56 loc) · 2.86 KB
/
sprite_handler.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
from __future__ import annotations
import numpy as np
import os
from PIL import Image
from typing import List
def load_sprite(filename: str) -> np.array:
image = Image.open(filename)
image_array = np.array(image)
image_array = np.where(image_array == 255, 0, 1)
return image_array
def load_animation_sprites(sprite_folder: str, num_frames: int) -> List[np.array]:
sprite_images = []
for frame in range(num_frames):
filename = os.path.join(sprite_folder, f"{frame}.png")
sprite_image = load_sprite(filename)
sprite_images.append(sprite_image)
return sprite_images
# SPRITES
# Animations
sprite_folder = "sprites"
# Eggs
egg_folder = os.path.join(sprite_folder, "eggs", "0") # TODO: Add more variants.
IDLE_EGG = load_animation_sprites(egg_folder, 2)
# Babies
baby_folder = os.path.join(sprite_folder, "babies", "0")
IDLE_BABY = load_animation_sprites(os.path.join(baby_folder, "idle"), 2)
SLEEP_BABY = load_animation_sprites(os.path.join(baby_folder, "sleep"), 2)
# Children
child_folder = os.path.join(sprite_folder, "children", "0")
IDLE_CHILD = load_animation_sprites(os.path.join(child_folder, "idle"), 2)
SLEEP_CHILD = load_animation_sprites(os.path.join(child_folder, "sleep"), 2)
# Teen
teen_folder = os.path.join(sprite_folder, "teens", "0")
# Adult
adult_folder = os.path.join(sprite_folder, "adult", "0")
# Special
special_folder = os.path.join(sprite_folder, "specials", "0")
# Overlays
overlay_folder = os.path.join(sprite_folder, "overlay")
OVERLAY_ZZZ = load_animation_sprites(os.path.join(overlay_folder, "OVERLAY_ZZZ"), 2)
OVERLAY_EAT = load_animation_sprites(os.path.join(overlay_folder, "EAT", "apple"), 6) # TODO: Add more foods
OVERLAY_STINK = load_animation_sprites(os.path.join(overlay_folder, "OVERLAY_STINK"), 2)
OVERLAY_DEAD = load_animation_sprites(os.path.join(overlay_folder, "OVERLAY_DEAD"), 2)
OVERLAY_EXCLAIM = load_animation_sprites(os.path.join(overlay_folder, "OVERLAY_EXCLAIM"), 2)
OVERLAY_CLEAN = load_sprite(os.path.join(sprite_folder, "OVERLAY", "OVERLAY_CLEAN.png"))
# Components
SELECTOR = load_sprite(os.path.join(sprite_folder, "components", "SELECTOR.png"))
FEED = load_sprite(os.path.join(sprite_folder, "components", "FEED.png"))
FLUSH = load_sprite(os.path.join(sprite_folder, "components", "FLUSH.png"))
HEALTH = load_sprite(os.path.join(sprite_folder, "components", "HEALTH.png"))
ZZZ = load_sprite(os.path.join(sprite_folder, "components", "ZZZ.png"))
DISPLAY_HUNGER = load_sprite(os.path.join(sprite_folder, "components", "DISPLAY_HUNGER.png"))
DISPLAY_ENERGY = load_sprite(os.path.join(sprite_folder, "components", "DISPLAY_ENERGY.png"))
DISPLAY_WASTE = load_sprite(os.path.join(sprite_folder, "components", "DISPLAY_WASTE.png"))
DISPLAY_AGE = load_sprite(os.path.join(sprite_folder, "components", "DISPLAY_AGE.png"))
DISPLAY_BACK = load_sprite(os.path.join(sprite_folder, "components", "DISPLAY_BACK.png"))