Added documentation
This commit is contained in:
parent
0eea13331f
commit
f104e90a0f
@ -1,26 +1,46 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pygame
|
||||
|
||||
|
||||
# TODO: Add getters to retrieve relative coords
|
||||
class Entity(pygame.sprite.Sprite):
|
||||
# Static ID counter - increments with each constructor call
|
||||
nextId = 1
|
||||
|
||||
def __init__(self, texture, size, pos):
|
||||
"""
|
||||
Create an entity.
|
||||
:param texture: Path to a file with texture
|
||||
:param size: Size in px
|
||||
:param pos: Position tuple
|
||||
"""
|
||||
super().__init__()
|
||||
self.image, self.rect = self.getTexture(texture, size)
|
||||
self.image.set_colorkey((255, 255, 255))
|
||||
self.rect.x = pos[0]
|
||||
self.rect.y = pos[1]
|
||||
self.id = self.getId()
|
||||
self.id = self.setNewId()
|
||||
|
||||
# A method to return auto-incremented ID
|
||||
def getId(self):
|
||||
@staticmethod
|
||||
def setNewId():
|
||||
"""
|
||||
Returns auto-incremented unique ID
|
||||
:return: ID Int
|
||||
"""
|
||||
id = Entity.nextId
|
||||
Entity.nextId += 1
|
||||
return id
|
||||
|
||||
# A method that returns image and rect from a file
|
||||
def getTexture(self, textureName, tileSize):
|
||||
@staticmethod
|
||||
def getTexture(textureName, tileSize):
|
||||
"""
|
||||
Get the texture from a file. Texture path is pre-set to data/images/entities.
|
||||
:param textureName: Filename
|
||||
:param tileSize: Texture size (to scale to map size)
|
||||
:return: image, rect
|
||||
:rtype: pygame.image, pygame.rect
|
||||
"""
|
||||
texturesFolder = ""
|
||||
textureFile = ""
|
||||
try:
|
||||
@ -33,5 +53,3 @@ class Entity(pygame.sprite.Sprite):
|
||||
image = pygame.transform.scale(image, (tileSize, tileSize))
|
||||
rect = image.get_rect()
|
||||
return image, rect
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user