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 of the player
Current HP, usually set to the same value of the
maxhp (for debug purposes)
Player's minimum attack damage
Player's maximum attack damage
player = TARBSengine.Player("Steve", 20, 5, 10)# A player with the name "Steve". Has 20 HP currently, 20 HP max,# minimum attack damage of 5 and maximum attack damage of 10
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.
The item to give the player
The amount of items to add to the players inventory.
player.add_item(sword, 1)## Debugger: item given Sharp Sword x 1
player.add_item(sword, 2)## Debugger: item given sword x 2## This will set the number of swords that the player has to 2## regardless of how many they currently have in their inventory.
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.
player.remove_item(sword, 1)## Debugger: removed Sharp Sword x 1 from player
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.)
player.atk(zombie)## Damage done: 7## Enemy HP: 13
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.equip_weapon(sword)# Equipped weapon: Sharp Sword, Damage: 5
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.
player.equip_shield(super_shield)# Equipped shield: Super Shield, Damage reduction: 5
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.
player.unequip_weapon(sword)# Debugger: Sharp Sword unequipped.
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.
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.
player.use_hp_potion(hp_potion)## 5 health restored, current health: 12# Or if HP is already at maxplayer.use_hp_potion(hp_potion)## HP already at max!
Player.say is used for dialogue. It outputs the text along with the player's name.
player.say("I think this engine is neat!")## Steve: I think this engine is neat!
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.
loot = [sword, hp_potion, super_shield]player.open_chest(loot)## Reward from chest: Sharp Sword
It kills the player and displays a death message. The optional
endgame argument decides if the game should exit it set to
player.kill("Steve fell off a cliff", True)## Steve fell off a cliff## *Game Exits*
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.
player.think("Hmm, I could really use a new sword")# +----------------------------+# | Hmm, I could really use a |# | new sword |# +----------------------------+
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.
player.equip_armor(helmet)# Debugger: equipped Protective Helmet head slot# DEBUG:root: 01:00:26: Debugger: equipped Protective Helmet head slot
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.
player.unequip_armor(helmet)# Debugger: unequipped Protective Helmet head slot# DEBUG:root: 01:00:26: Debugger: unequipped Protective Helmet head slot
When calling this function, the
Player.level var is incremented by one.
player.levelup()# Level Up! Current Level: 2# Debugger: Player leveled up to 2# DEBUG:root: 09:46:51: Debugger: Player leveled up to 2
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.
player.lowerlevel(2)# Debugger: Player leveled lowered 2 levels to 3# DEBUG:root: 09:46:51: Debugger: Player leveled lowered 2 levels to 3