1. Player
1. The Player Class
1.1 Player Initialization
For every project, there should only be one player class. The player class is the main class that the user controls. This class is the object that contains the users inventory, equipped weapons and shield, as well as attack enemies and interacts with NPCs. Setting up a player class goes as follows:
You must supply 4 parameters when creating an instance of the player class:
name
Name of the player
hp
Current HP, usually set to the same value of the
maxhp
(for debug purposes)
minatk
Player's minimum attack damage
maxatk
Player's maximum attack damage
Create a player like this:
1.2 add_item
add_item(item, amnt)
Add new items to the players inventory and change amount of items that already exist in the players inventory. If debugging is enabled, (learn how to enable debugging here), outputs the item give and the amount.
This function no longer belongs to the Player
class. It is only kept here because it only deals with the player's inventory.
Required parameters:
item
The item to give the player
amnt
The amount of items to add to the players inventory.
The item parameter must be a class instance.
Add an item to the players inventory like this:
Edit the amount of items that are already in the players inventory:
Changing the amount of items a player has will have its own function in Beta 1.0
1.3 remove_item
Player.remove_item(item, amnt)
Player.remove_item
is used to negate the amount of items the player has based on the parameters given. This function is a replacement for Player.add_item
. This is because the Player.add_item
would not accept negative values. Player.remove_item
subtracts the amount of a specific items the player has by a set value.
This function no longer belongs to the Player
class. It is only kept here because it only deals with the player's inventory.
Player.remove_item() usage example:
1.4 Player.atk
Player.atk(opponent)
Preform a basic attack on the opponent. Attack automatically factors in the extra damage from the current weapon the player is holding. If debugging is enabled, the function outputs the total damage done and how much HP the opponent has left. Function will also automatically delete the instance of opponent if the opponent HP reaches 0. (This feature is subject to change and mostly for debugging purposes at the moment.)
The opponent argument must be a class instance
Usage example:
1.5 Player.equip_weapon
Player.equip_weapon(weapon)
Adds the weapon to the Player.weapon_one
var. The name of the weapon can also be referenced by referring to Weapon.name
for dialogue when equipping the weapon. When equipping the weapon, the Weapon.atk
var is also stored in the Player.weapon_one_atk
for adding the amount of extra damage that the weapon provides when calling Player.atk()
.
The weapon argument must be a class instance.
Usage:
1.6 Player.equip_shield
Player.equip_shield(shield)
Player.equip_shield
essentially does the opposite that Player.equip_weapon
does. The shield reduces the amount of damage taken from an opposing attack by a set value. This value is stored in the Player.shield_protect
. The shield's name is stored in Player.shield
for reference in dialogue such as when equipping the shield or having an NPC or the player speak about it.
Usage:
1.7 Player.unequip_weapon
Player.unequip_weapon(weapon)
This function does the opposite of Player.equip_weapon
. If the player has a weapon equipped, calling Player.unequip_weapon
would remove the weapon from the player's weapon slot, as well as add the weapon back to the inventory.
Usage:
1.8 Player.unequip_shield
Player.unequip_shield(shield)
This function does the opposite of Player.equip_shield
. If the player has a shield equipped, calling Player.unequip_shield
would remove the shield from the player's shield slot, as well as add the shield back to the inventory.
1.9 Player.use_hp_potion
Player.use_hp_potion(potion)
This function takes potion class instances as perimeters. It consumes the potion, restores the hp to the player (set by the Potion.hp
var) and removes the 1 potion of that type from the players inventory. Checking if the player's hp is already at max happens automatically. If the player is at max hp, the potion is not consumed and the function ends.
Usage:
1.10 Player.say
Player.say(text)
Player.say
is used for dialogue. It outputs the text along with the player's name.
Usage:
1.11 Player.open_chest
Player.open_chest(loot)
Delivers randomly chosen loot from a set list of possible options. Adds the chosen loot to the player's inventory. The chance of gaining one item over the other are completely random. One item doesn't have a greater chance to drop over another item. (This functionality may be added in a later version, currently no plans) Debug output returns the item that was chosen.
The loot argument must be a list.
Usage:
1.12 Player.kill
Player.kill(deathmessage, *endgame)
It kills the player and displays a death message. The optional endgame
argument decides if the game should exit it set to True
.
Usage:
1.13 Player.think
Player.think(thought)
Player.think
is used mainly for games with a story line. You can communicate the players thoughts directly to the user. Player.think
is distinguished from regular speech because it has a border around it.
Further configuration of the border is a planned feature.
Usage:
1.14 Player.equip_armor
Player.equip_armor(armor)
Calling this function with an instance of the Armor
class equips that piece of armor into the appropriate slot and adds some damage reduction when taking hits from opponents.
Usage:
1.15 Player.unequip_armor
Player.unequip_armor(armor)
This function to used to do the opposite of Player.equip_armor
. Calling this function with the parameter armor
removes the armor from the proper player slot and removes the damage protection that it offers.
Usage:
1.16 Player.levelup
Player.levelup()
When calling this function, the Player.level
var is incremented by one.
Usage:
1.17 Player.lowerlevel
Player.lowerlevel(amnt)
This function is used as the opposite of Player.levelup()
. Usually, in RPG games, the player's level doesn't go down. Player.lowerlevel()
is used in special circumstances. The amnt
parameter is the amount of levels that the player's level goes down.
Usage:
Last updated