Skip to content

Tairitsu.Tile

Tile in the game.

Tile

Classes

Tile

Tile(image: pygame.Surface, x: int = 0, y: int = 0, width: int = SceneSettings.tileWidth, height: int = SceneSettings.tileHeight)

Bases: pygame.sprite.Sprite

Initializes a Tile object.

PARAMETER DESCRIPTION
image

The image to be displayed on the tile.

TYPE: pygame.Surface

x

The x-coordinate of the top-left corner of the tile. Defaults to 0.

TYPE: int DEFAULT: 0

y

The y-coordinate of the top-left corner of the tile. Defaults to 0.

TYPE: int DEFAULT: 0

width

The width of the tile. Defaults to SceneSettings.tileWidth.

TYPE: int DEFAULT: SceneSettings.tileWidth

height

The height of the tile. Defaults to SceneSettings.tileHeight.

TYPE: int DEFAULT: SceneSettings.tileHeight

Source code in Tairitsu/Tile.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def __init__(self, image: pygame.Surface, x: int = 0, y: int = 0, width: int = SceneSettings.tileWidth, 
             height : int = SceneSettings.tileHeight):
    """
    Initializes a Tile object.

    Args:
        image (pygame.Surface): The image to be displayed on the tile.
        x (int, optional): The x-coordinate of the top-left corner of the tile. Defaults to 0.
        y (int, optional): The y-coordinate of the top-left corner of the tile. Defaults to 0.
        width (int, optional): The width of the tile. Defaults to SceneSettings.tileWidth.
        height (int, optional): The height of the tile. Defaults to SceneSettings.tileHeight.
    """
    super().__init__()
    self.image = pygame.transform.scale(image, (width, height))
    self.rect = self.image.get_rect()
    self.rect.topleft = (x, y)
Attributes
image instance-attribute
image = pygame.transform.scale(image, (width, height))
rect instance-attribute
rect = self.image.get_rect()
Functions
draw
draw(window: pygame.surface.Surface, dx: int = 0, dy: int = 0)

Draws the tile on the specified window at the given position.

PARAMETER DESCRIPTION
window

The window surface to draw on.

TYPE: pygame.surface.Surface

dx

The x-coordinate offset for positioning the tile.

TYPE: int DEFAULT: 0

dy

The y-coordinate offset for positioning the tile.

TYPE: int DEFAULT: 0

Source code in Tairitsu/Tile.py
25
26
27
28
29
30
31
32
33
34
35
36
def draw(self, window: pygame.surface.Surface, dx: int = 0, dy: int = 0):
    """
    Draws the tile on the specified window at the given position.

    Args:
        window (pygame.surface.Surface): The window surface to draw on.
        dx (int, optional): The x-coordinate offset for positioning the tile.
        dy (int, optional): The y-coordinate offset for positioning the tile.
    """
    rect = self.rect
    rect = rect.move(dx, dy)
    window.blit(self.image, rect)