Characters

This module contains the base classes for both playable and non playable characters.

Character(**kwargs) A base class for a character (playable or not)
NPC(**kwargs) A class that represent a non playable character controlled by the computer.
Player(**kwargs) A class that represent a player controlled by a human.
class gamelib.Characters.Character(**kwargs)

Bases: object

A base class for a character (playable or not)

Parameters:
  • agility (int) – Represent the agility of the character
  • attack_power (int) – Represent the attack power of the character.
  • defense_power (int) – Represent the defense_power of the character
  • hp (int) – Represent the hp (Health Point) of the character
  • intelligence (int) – Represent the intelligence of the character
  • max_hp (int) – Represent the max_hp of the character
  • max_mp (int) – Represent the max_mp of the character
  • mp (int) – Represent the mp (Mana/Magic Point) of the character
  • remaining_lives (int) – Represent the remaining_lives of the character. For a NPC it is generally a good idea to set that to 1. Unless the NPC is a multi phased boss.
  • strength (int) – Represent the strength of the character

These characteristics are here to be used by the game logic but very few of them are actually used by the Game (gamelib.Game) engine.

class gamelib.Characters.NPC(**kwargs)

Bases: gamelib.Movable.Movable, gamelib.Characters.Character

A class that represent a non playable character controlled by the computer. For the NPC to be successfully managed by the Game, you need to set an actuator.

None of the parameters are mandatory, however it is advised to make good use of some of them (like type or name) for game design purpose.

In addition to its own member variables, this class inherits all members from:
Parameters:actuator (gamelib.Actuators.Actuator) – An actuator, it can be any class but it need to implement gamelib.Actuator.Actuator.

Example:

mynpc = NPC(name='Idiot McStupid', type='dumb_enemy')
mynpc.step = 1
mynpc.actuator = RandomActuator()
can_move()

Movable implements can_move().

Returns:True
Return type:Boolean
debug_info()

Return a string with the list of the attributes and their current value.

Return type:str
display()

Print the model WITHOUT carriage return.

has_inventory()

Define if the NPC has an inventory.

This method returns false because the game engine doesn’t manage NPC inventory yet but it could be in the future. It’s a good habit to check the value returned by this function.

Returns:False
Return type:Boolean

Example:

if mynpc.has_inventory():
    print("Cool: we can pickpocket that NPC!")
else:
    print("No pickpocketing XP for us today :(")
overlappable()

Define if the NPC is overlappable.

Obviously this method also always return False.

Returns:False
Return type:Boolean

Example:

if mynpc.overlappable():
    Utils.warn("Something is fishy, that NPC is overlappable but"
        "is not a Ghost...")
pickable()

Define if the NPC is pickable.

Obviously this method always return False.

Returns:False
Return type:Boolean

Example:

if mynpc.pickable():
    Utils.warn("Something is fishy, that NPC is pickable"
        "but is not a Pokemon...")
size()

This is a virtual method that must be implemented in deriving class. This method has to return an integer. This represent the size of the BoardItem. It is used for example to evaluate the space taken in the inventory.

store_position(row, column)

Store the BoardItem position for self access.

The stored position is used for consistency and quick access to the self postion. It is a redundant information and might not be synchronized.

Parameters:
  • row (int) – the row of the item in the Board.
  • column (int) – the column of the item in the Board.

Example:

item.store_position(3,4)
class gamelib.Characters.Player(**kwargs)

Bases: gamelib.Movable.Movable, gamelib.Characters.Character

A class that represent a player controlled by a human. It accepts all the parameters from Character and is a Movable.

Note

If no inventory is passed as parameter a default one is created.

can_move()

Movable implements can_move().

Returns:True
Return type:Boolean
debug_info()

Return a string with the list of the attributes and their current value.

Return type:str
display()

Print the model WITHOUT carriage return.

has_inventory()

This method returns True (a player has an inventory).

overlappable()

This method returns false (a player cannot be overlapped).

Note

If you wish your player to be overlappable, you need to inherit from that class and re-implement overlappable().

pickable()

This method returns False (a player is obviously not pickable).

size()

This is a virtual method that must be implemented in deriving class. This method has to return an integer. This represent the size of the BoardItem. It is used for example to evaluate the space taken in the inventory.

store_position(row, column)

Store the BoardItem position for self access.

The stored position is used for consistency and quick access to the self postion. It is a redundant information and might not be synchronized.

Parameters:
  • row (int) – the row of the item in the Board.
  • column (int) – the column of the item in the Board.

Example:

item.store_position(3,4)