DSZI_Survival/src/game/TerrainTile.py

27 lines
875 B
Python
Raw Normal View History

from pathlib import Path
import pygame
2020-05-09 22:30:21 +02:00
# TODO: Relative coords
class TerrainTile(pygame.sprite.Sprite):
2020-04-25 23:33:55 +02:00
def __init__(self, x, y, texture, tileSize, cost):
2020-05-14 16:16:19 +02:00
"""
Create a tile object.
:param x: Absolute X coord
:param y: Absolute Y coord
:param texture: Texture name found in data/images/terrain
:param tileSize: Size in px
:param cost: Cost of getting into this tile
"""
2020-04-03 23:07:12 +02:00
super().__init__()
terrainTexturesPath = Path("./data/images/terrain").resolve()
self.image = pygame.image.load(str(terrainTexturesPath / texture)).convert()
2020-04-03 23:07:12 +02:00
self.image = pygame.transform.scale(self.image, (tileSize, tileSize))
self.rect = self.image.get_rect()
self.x = x
self.y = y
self.rect.x = x * tileSize
self.rect.y = y * tileSize
2020-04-25 23:33:55 +02:00
self.cost = cost