core.components.player module

This module contains the player and npc modules.

class core.components.player.Npc(sprite_name='maple', name='Maple')[source]

Bases: core.components.player.Player

move(tile_size, time_passed_seconds, game)[source]

Draws text to the current menu object

Parameters:
  • screen (pygame.Surface) – The pygame surface you wish to blit the player onto.
  • tile_size (List) – A list with the [width, height] of the tiles in pixels. This is used for tile-based movement.
  • time_passed_seconds (Float) – A float of the time that has passed since the last frame. This is generated by clock.tick() / 1000.0.
  • global_x/global_y (Tuple) – The global_x/y variables that we add to everything on a map to move everything around the player.
  • game (tuxemon.Game) – The Tuxemon game instance itself.
Return type:

Tuple

Returns:

The updated (global_x, global_y) coordinates after moving (or stopping due to collision)

class core.components.player.PathfindNode(value, parent=None)[source]

Used in path finding search

get_depth()[source]
get_parent()[source]
get_value()[source]
set_parent(parent)[source]
class core.components.player.Player(sprite_name='player1', name='Red')[source]

Bases: object

A class for a player object. This object can be used for NPCs as well as the player:

Example:

>>> player1 = core.components.player.Player()
>>> # Scale the sprite and its animations
>>> for key, animation in player1.sprite.items():
...     animation.scale(tuple(i * scale for i in animation.getMaxSize()))
...
>>> for key, image in player1.standing.items():
...     player1.standing[key] = pygame.transform.scale(image, (image.get_width() * scale, image.get_height() * scale))
...
>>> # Set the walking and running pixels per second based on the scale
>>> player1.walkrate *= scale
>>> player1.runrate *= scale
add_monster(monster)[source]

Adds a monster to the player’s list of monsters. If the player’s party is full, it will send the monster to PCState archive.

Parameters:monster (core.components.monster.Monster) – The core.components.monster.Monster object to add to the player’s party.
Return type:None
Returns:None
collision_check(player_tile_pos, collision_dict, collision_lines_map)[source]

Checks collision tiles around the player.

Parameters:
  • player_pos (List) – An (x, y) list of the player’s current tile position. Must be an integer.
  • collision_dict (Dictionary) – A dictionary object of (x, y) coordinates that are collidable.
Return type:

List

Returns:

A list indicating what tiles relative to the player are collision tiles. e.g. [“down”, “up”]

draw(screen, layer)[source]

Draws the player to the screen depending on whether or not they are moving or standing still.

Parameters:
  • screen (pygame.Surface) – The pygame screen to draw the player to.
  • layer (String) – Which part of the sprite to draw. Can be “top” or “bottom”
Returns:

None

get_adjacent_tiles(curr_loc, game)[source]
get_collision_dict(game)[source]

Checks for collision tiles around the player.

Parameters:game (tuxemon.Game) – The Tuxemon game instance itself.
Return type:Dictionary
Returns:A dictionary of collision tiles around the player
move(screen, tile_size, time_passed_seconds, global_xy, game)[source]

Draws text to the current menu object

Parameters:
  • screen (pygame.Surface) – The pygame surface you wish to blit the player onto.
  • tile_size (List) – A list with the [width, height] of the tiles in pixels. This is used for tile-based movement.
  • time_passed_seconds (Float) – A float of the time that has passed since the last frame. This is generated by clock.tick() / 1000.0.
  • global_x/global_y (Tuple) – The global_x/y variables that we add to everything on a map to move everything around the player.
  • game (tuxemon.Game) – The Tuxemon game instance itself.
Return type:

Tuple

Returns:

The updated (global_x, global_y) coordinates after moving (or stopping due to collision)

move_by_path()[source]

This method will ensure movement will happen until the player reaches its destination

move_one_tile(direction)[source]
moves = []
pathfind(dest, game)[source]
pathfind_r(dest, queue, visited, depth, game)[source]
remove_monster(monster)[source]

Removes a monster from this player’s party.

Parameters:monster (core.components.monster.Monster) – The core.components.monster.Monster object to remove from the player’s party.
Return type:None
Returns:None
scale_sprites(scale)[source]
speed = 100
switch_monsters(index_monster_1, index_monster_2)[source]

Swap two monsters in this player’s party

Parameters:index_monster_1/index_monster_2 (int) – The indexes of the monsters to switch in the player’s party.
Return type:None
Returns:None