📄 person.h
字号:
// Description: adds an item to the inventory
// -------------------------------------------------------
void AddItem( Item* p_item )
{
// add the item
m_inventory.Append( p_item );
// if the current weapon is invalid, then set it to the
// first item.
if( m_currentweapon.Valid() == false )
{
m_currentweapon.Start();
}
}
// -------------------------------------------------------
// Name: GetItemCount
// Description: gets the number of items in the inventory
// -------------------------------------------------------
int GetItemCount()
{
return m_inventory.Size();
}
// -------------------------------------------------------
// Name: NextWeapon
// Description: moves to the next weapon in the inventory
// -------------------------------------------------------
void NextWeapon()
{
// move to the next weapon
m_currentweapon.Forth();
// if the weapon is invalid, then you moved past the end
// of the list. Move to the end again.
if( m_currentweapon.Valid() == false )
m_currentweapon.End();
}
// -------------------------------------------------------
// Name: PreviousWeapon
// Description: moves to the previous weapon in the
// inventory
// -------------------------------------------------------
void PreviousWeapon()
{
// move to the next weapon
m_currentweapon.Back();
// if the weapon is invalid, then you moved past the beginning
// of the list. Move to the front again.
if( m_currentweapon.Valid() == false )
m_currentweapon.Start();
}
// -------------------------------------------------------
// Name: GetCurrentWeapon
// Description: gets a pointer to the current weapon
// -------------------------------------------------------
Item* GetCurrentWeapon()
{
if( m_currentweapon.Valid() )
return m_currentweapon.Item();
return 0;
}
// -------------------------------------------------------
// Name: SetGraphic
// Description: sets the graphic for a given direction
// and frame
// -------------------------------------------------------
void SetGraphic( SDL_Surface* p_graphic, int p_direction, int p_frame )
{
m_graphics[p_direction][p_frame] = p_graphic;
}
// -------------------------------------------------------
// Name: SetAttackTime
// Description: Sets the time that the person last
// attacked.
// -------------------------------------------------------
void SetAttackTime( int p_time )
{
m_lastattack = p_time;
}
// -------------------------------------------------------
// Name: GetAttackTime
// Description: Gets the time that the person last attacked
// -------------------------------------------------------
int GetAttackTime()
{
// return the time, modified by the handicap
return m_lastattack - m_attackmodifier;
}
// -------------------------------------------------------
// Name: SetMoveTime
// Description: Sets the time that the person last moved
// -------------------------------------------------------
void SetMoveTime( int p_time )
{
m_lastmove = p_time;
}
// -------------------------------------------------------
// Name: GetMoveTime
// Description: Gets the time that the person last moved
// -------------------------------------------------------
int GetMoveTime()
{
return m_lastmove;
}
// -------------------------------------------------------
// Name: SetAttackModifier
// Description: sets the time handicap
// -------------------------------------------------------
void SetAttackModifier( int p_modifier )
{
m_attackmodifier = p_modifier;
}
// -------------------------------------------------------
// Name: GetAttackModifier
// Description: gets the time handicap
// -------------------------------------------------------
int GetAttackModifier()
{
return m_attackmodifier;
}
// -------------------------------------------------------
// Name: Attack
// Description: Makes the person attack another person
// -------------------------------------------------------
void Attack( Person* p_person )
{
// get the current weapon
Item* weapon = GetCurrentWeapon();
// attack the object
p_person->GetAttacked( weapon->GetStrength() );
// if your game had a reward system, where the player is rewarded
// for killing objects, you would check to see if you killed him
// here. like, if( p_person->isDead() ), etc.
}
// -------------------------------------------------------
// Name: GetGraphic
// Description: gets the current graphic for the person
// based on direction and time.
// -------------------------------------------------------
SDL_Surface* GetGraphic()
{
// calculate the index based on the current time, so that the
// animation loops through once every second.
int index = (SDL_GetTicks() % 1000) * FRAMES;
index /= 1000;
return m_graphics[m_direction][index];
}
// -------------------------------------------------------
// Name: GetAttacked
// Description: The person is attacked
// -------------------------------------------------------
void GetAttacked( int p_damage )
{
// lower the damage by the armor of the person.
// if the armor is 100, then the damage is 0,
// etc.
int newdamage = (p_damage * (100 - m_armor) ) / 100;
SetHealth( GetHealth() - newdamage );
// damage the armor by the amount of damage.
SetArmor( GetArmor() - p_damage );
}
// -------------------------------------------------------
// Name: IsDead
// Description: determines if the person is dead
// -------------------------------------------------------
bool IsDead()
{
// return true if health is 0, false otherwise.
return (m_health == 0);
}
// -------------------------------------------------------
// Name: PickUp
// Description: Makes the person pick up an item
// -------------------------------------------------------
void PickUp( Item* p_item )
{
// check to see if the item is armour
if( p_item->IsArmor() )
{
// add the armour to the person.
SetArmor( m_armor + p_item->GetStrength() );
delete p_item;
return;
}
// else add the item to the inventory
AddItem( p_item );
}
// -------------------------------------------------------
// Name: CopyInventory
// Description: This copies the inventory of one person
// into the inventory of another
// -------------------------------------------------------
void CopyInventory( Person* p_person )
{
Item* item;
DListIterator<Item*> itr = p_person->GetItemIterator();
// go through the current inventory, and delete all the items.
while( m_inventory.Size() > 0 )
{
// delete the first item
delete m_inventory.m_head->m_data;
// remove the first node.
m_inventory.RemoveHead();
}
// reset the current weapon iterator.
m_currentweapon.Start();
// loop through the inventory
for( itr.Start(); itr.Valid(); itr.Forth() )
{
// create a new item
item = new Item;
// copy the attributes of the current item
// in the parameters inventory
*item = *itr.Item();
// add the item to the current players inventory
AddItem( item );
}
}
};
Person g_persontemplates[16];
Person* MakePerson( int p_type, int p_x, int p_y, int p_cell )
{
Person* p = new Person;
*p = g_persontemplates[p_type];
p->SetX( p_x );
p->SetY( p_y );
p->SetCell( p_cell );
// give the person a knife
p->AddItem( MakeItem( 8, 0, 0, 0 ) );
return p;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -