add Image cls, change IMAGES const to hold Image objects

This commit is contained in:
matixezor 2021-03-30 18:44:16 +02:00
parent f5cd0670cc
commit 9fd954c79b
2 changed files with 41 additions and 20 deletions

View File

@ -1,5 +1,7 @@
import os
from pygame import image
import pygame as pg
from image import Image
main_path = os.path.dirname(os.getcwd())
@ -7,33 +9,42 @@ main_path = os.path.dirname(os.getcwd())
WIDTH = 800
HEIGHT = 800
IMAGES = []
for img in [
'grass_01',
'grass_02',
'grass_rock_01',
'grass_rock_02',
'grass_01_mine_01',
'grass_01_mine_02',
'grass_01_mine_03',
'grass_01_mine_04',
'grass_02_mine_01',
'grass_02_mine_02',
'grass_02_mine_03',
]:
IMAGES.append(image.load(main_path + '/images/Tiles/' + img + ".png"))
IMAGES_MAPPING = tuple([0 for _ in range(8)] + [1 for _ in range(3)])
IMAGES = []
for name, val in {
'grass_01': 0,
'grass_02': 1,
'grass_rock_01': 0,
'grass_rock_02': 1,
'grass_01_mineAT_01': 0,
'grass_01_mineAP_02': 0,
'grass_01_mineAP_03': 0,
'grass_01_mineAT_04': 0,
'grass_02_mineAT_01': 1,
'grass_02_mineAP_02': 1,
'grass_02_mineAP_03': 1,
}.items():
IMAGES.append(
Image(
val,
pg.image.load(
main_path + '/images/Tiles/' + name + ".png"
),
None if 'mine' not in name else (
'AP' if 'AP' in name else 'AT'
)
)
)
ICON = main_path + '/images/mine_icon.png'
SAPPER_IDLE = image.load(main_path + '/images/sapper_idle/cpt_bomba.png')
SAPPER_IDLE = pg.image.load(main_path + '/images/sapper_idle/cpt_bomba.png')
SAPPER_RUNNING = []
for img in [
for name in [
'cpt_bomba_left',
'cpt_bomba_right',
]:
SAPPER_RUNNING.append(image.load(main_path + '/images/sapper_idle/' + img + ".png"))
SAPPER_RUNNING.append(pg.image.load(main_path + '/images/sapper_idle/' + name + ".png"))
DEFAULT_FIELD = [
[1, 3, 4, 5, 0, 1, 2, 3, 2, 0],

10
src/image.py Normal file
View File

@ -0,0 +1,10 @@
from typing import Union
from pygame import image
class Image:
def __init__(self, parent: int, img: image, mine_type: Union[str, None]):
self.parent = parent
self.img = img
self.mine_type = mine_type