-
Notifications
You must be signed in to change notification settings - Fork 1
/
imageloader.py
44 lines (31 loc) · 1.31 KB
/
imageloader.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
import os
import pygame
from pygame.locals import *
from globals import DELTAX, DELTAY
main_dir = os.path.split(os.path.abspath(__file__))[0]
data_dir = os.path.join(main_dir, 'data')
def load_image(name, colorkey=None):
fullname = os.path.join(data_dir, name)
try:
image = pygame.image.load(fullname)
except pygame.error:
print('Cannot load image:', fullname)
image = image.convert()
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0, 0))
image.set_colorkey(colorkey, RLEACCEL)
return image, image.get_rect()
class Imageloader():
def __init__(self):
tilenames = ['blocks/ore'+str(i)+'.png' for i in range(1, 15)] + \
['blocks/rock'+str(i)+'.png' for i in range(1, 19)]
exanames = ['exa'+str(i)+'.png' for i in range(1, 10)]
firenames = ['fire'+str(i)+'.png' for i in range(1, 5)]
heronames = ['hero'+str(i)+'.png' for i in range(1, 8)]
lumina = ['lumina.png']
self.blocks_loaded = [load_image(i) for i in tilenames]
self.anim_loaded = [load_image(i, -1) for i in exanames]
self.fire_loaded = [load_image(i, -1) for i in firenames]
self.hero_loaded = [load_image(i, -1) for i in heronames]
self.lumina_loaded = [load_image('lumina.png', -1)]