entity module

Entity package.

For now, there’s only one: the player. I know, it’s quite lonely. Like me.

entity.player

Module name: player

This module defines the player entity and its behaviour and interactions with other game objects.

class game.entity.player.Player(x: int = 0, y: int = 0, speed: int = 50)

Bases: object

Class for creating a player.

DAMAGE_TIMER: int = 1
MINING_TIMER: int = 0
TIMERS_COUNT: int = 2
break_tile(game) None

Break a map tile and update map surfaces.

can_break_breakable(map_obj: Map) bool

Returns True if the player is able to access and break a breakable tile.

draw(game) None

Draw the player to the screen.

draw_gun_pointer(game) None

Draw the gun pointer to the screen.

draw_selection_grid(game) None

Draw the player tile selection grid to the screen.

events(game, map_obj, e: pygame.event.Event) None

Handle the player events.

get_absolute_x(map_obj: Map) int

Return the player’s x position as if the map’s top-left corner were to be positioned at the origin (0, 0). This signifies that the returned value will always be positive.

get_absolute_y(map_obj: Map) int

Return the player’s y position as if the map’s top-left corner were to be positioned at the origin (0, 0). This signifies that the returned value will always be positive.

get_coefficient_from_center_x(parent_width: int) float

Return the coefficient indicating how far the player is away from the horizontal center of the screen.

get_coefficient_from_center_y(parent_height: int) float

Return the coefficient indicating how far the player is away from the vertical center of the screen.

get_health() int

Return the player’s health.

get_held_item() bool

Returns item held by player.

get_player_name()

Return the player’s in-game name.

get_selected_tile_x() int

Return the selected tile’s x position.

get_selected_tile_y() int

Return the selected tile’s y position.

get_walls(map_obj: Map) list[bool]

Return the tiles of type BREAKABLE surrounding the player. This is used for determining what tiles the player could potentially collide with. The order of the tiles are MOVE_LEFT, MOVE_RIGHT, MOVE_UP, MOVE_DOWN, UPPER MOVE_LEFT, UPPER MOVE_RIGHT, LOWER MOVE_LEFT, LOWER MOVE_RIGHT.

get_x() int

Return the player’s x position.

get_y() int

Return the player’s y position.

has_selected_breakable(map_obj: Map) bool

Returns True if the player has selected a breakable tile.

init(game) None

Define the player attributes that depend on the given game object.

is_dead() bool

Returns True if the player is dead.

is_in_lava(map_obj: Map) bool

Returns True if the player is in lava.

is_in_lethal_tile(map_obj: Map) bool

Returns True if the player is touching a lethal tile.

is_in_wall(map_obj: Map) bool

Returns True if the player is surrounded by tiles with collision.

is_in_water(map_obj: Map) bool

Returns True if the player is in water.

is_moving_down() bool

Return True if the player is moving down.

is_moving_left() bool

Return True if the player is moving left.

is_moving_right() bool

Return True if the player is moving right.

is_moving_up() bool

Return True if the player is moving up.

is_near_bottom_edge() bool

Return True if the player is to the bottom-center of the screen.

is_near_left_edge() bool

Return True if the player is at the left-center of the screen.

is_near_right_edge() bool

Return True if the player is to the right-center of the screen.

is_near_top_edge() bool

Return True if the player is at the top-center of the screen.

is_selected_breakable_obstructed(map_obj: Map) bool

Returns True if the selected breakable tile is obstructed by other tiles with collision.

reset() None

Reset the player’s general attributes.

set_health(health: int) Self

Set the player’s health, then return the player itself.

set_ideal_spawn_point(map_obj: Map, camera_obj: Camera, nb_attempts: int = 5) None

Find the ideal starting position for the player when creating a new map. By default, five consecutive attempts will be made to place the player in a safe randomised location. If this fails, the player will be placed at the center of the map where safety is guaranteed. Setting the number of attempts to anything less than 1 will raise an exception.

set_player_name(player_name: str)

Set the player’s in-game name, then return the player itself.

set_x(x: int) Self

Set the player’s x position, then return the player itself.

set_y(y: int) Self

Set the player’s y position, then return the player itself.

update(game, map_obj: Map) None

Update the player.