Added documentation

This commit is contained in:
Marcin Kostrzewski 2020-05-10 13:27:06 +02:00
parent 0eea13331f
commit f104e90a0f

View File

@ -1,26 +1,46 @@
from pathlib import Path from pathlib import Path
import pygame import pygame
# TODO: Add getters to retrieve relative coords # TODO: Add getters to retrieve relative coords
class Entity(pygame.sprite.Sprite): class Entity(pygame.sprite.Sprite):
# Static ID counter - increments with each constructor call
nextId = 1 nextId = 1
def __init__(self, texture, size, pos): 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__() super().__init__()
self.image, self.rect = self.getTexture(texture, size) self.image, self.rect = self.getTexture(texture, size)
self.image.set_colorkey((255, 255, 255)) self.image.set_colorkey((255, 255, 255))
self.rect.x = pos[0] self.rect.x = pos[0]
self.rect.y = pos[1] self.rect.y = pos[1]
self.id = self.getId() self.id = self.setNewId()
# A method to return auto-incremented ID @staticmethod
def getId(self): def setNewId():
"""
Returns auto-incremented unique ID
:return: ID Int
"""
id = Entity.nextId id = Entity.nextId
Entity.nextId += 1 Entity.nextId += 1
return id return id
# A method that returns image and rect from a file @staticmethod
def getTexture(self, textureName, tileSize): 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 = "" texturesFolder = ""
textureFile = "" textureFile = ""
try: try:
@ -33,5 +53,3 @@ class Entity(pygame.sprite.Sprite):
image = pygame.transform.scale(image, (tileSize, tileSize)) image = pygame.transform.scale(image, (tileSize, tileSize))
rect = image.get_rect() rect = image.get_rect()
return image, rect return image, rect