📄 person.h
字号:
// ============================================================================
// Person.h
// Contains the person class
// ============================================================================
#ifndef PERSON_H
#define PERSON_H
#include "Object.h"
#include "Item.h"
#include "DLinkedList.h"
// ============================================================================
// Person Class
// ============================================================================
class Person : public Object
{
protected:
// =======================================================
// Data
// =======================================================
// -------------------------------------------------------
// Name: m_health
// Description: the health of the person
// -------------------------------------------------------
int m_health;
// -------------------------------------------------------
// Name: m_armor
// Description: the armor of the person
// -------------------------------------------------------
int m_armor;
// -------------------------------------------------------
// Name: m_type
// Description: the type of the person
// -------------------------------------------------------
int m_type;
// -------------------------------------------------------
// Name: m_direction
// Description: the direction of the person
// -------------------------------------------------------
int m_direction;
// -------------------------------------------------------
// Name: m_inventory
// Description: the inventory of the person
// -------------------------------------------------------
DLinkedList<Item*> m_inventory;
// -------------------------------------------------------
// Name: m_currentweapon
// Description: an iterator pointing to the current weapon
// -------------------------------------------------------
DListIterator<Item*> m_currentweapon;
// -------------------------------------------------------
// Name: m_graphics
// Description: a 2D array of graphics that make up the
// sprite animation.
// -------------------------------------------------------
SDL_Surface* m_graphics[DIRECTIONS][FRAMES];
// -------------------------------------------------------
// Name: m_lastattack
// Description: Keeps track of the last time that the
// player has attacked
// -------------------------------------------------------
int m_lastattack;
// -------------------------------------------------------
// Name: m_lastmove
// Description: Keeps track of the last time that the
// player has moved
// -------------------------------------------------------
int m_lastmove;
// -------------------------------------------------------
// Name: m_attackmodifier
// Description: the "handicap" of the player. Determines
// how much faster or slower (milliseconds)
// the person attacks
// -------------------------------------------------------
int m_attackmodifier;
public:
// =======================================================
// Functions
// =======================================================
// -------------------------------------------------------
// Name: Person
// Description: Constructs the person
// -------------------------------------------------------
Person()
{
// set the person type to 0
m_type = 0;
// set up the health and armor
m_health = 100;
m_armor = 100;
// set up the initial direction (pointing down)
m_direction = 2;
m_currentweapon = m_inventory.GetIterator();
// clear the images
int f, d;
for( d = 0; d < DIRECTIONS; d++ )
{
for( f = 0; f < FRAMES; f++ )
{
m_graphics[d][f] = 0;
}
}
// clear the timers
m_lastmove = 0;
m_lastattack = 0;
m_attackmodifier = 0;
}
// -------------------------------------------------------
// Name: ~Person
// Description: Destructs the person, and deletes all of
// their inventory
// -------------------------------------------------------
~Person()
{
DListIterator<Item*> itr = m_inventory.GetIterator();
for( itr.Start(); itr.Valid(); itr.Forth() )
{
if( itr.Item() != 0 )
delete itr.Item();
}
}
// -------------------------------------------------------
// Name: Copy Constructor/assignment operator
// Description: this is the copy constructor, it copies
// a player to another
// -------------------------------------------------------
Person( Person& p_person )
{
*this = p_person;
}
void operator= ( Person& p_person )
{
int d, f;
m_health = p_person.m_health;
m_armor = p_person.m_armor;
m_type = p_person.m_type;
m_direction = p_person.m_direction;
for( d = 0; d < DIRECTIONS; d++ )
{
for( f = 0; f < FRAMES; f++ )
{
m_graphics[d][f] = p_person.m_graphics[d][f];
}
}
// don't copy the inventory over.
m_lastattack = p_person.m_lastattack;
m_lastmove = p_person.m_lastmove;
m_attackmodifier = p_person.m_attackmodifier;
m_x = p_person.m_x;
m_y = p_person.m_y;
m_cell = p_person.m_cell;
}
// -------------------------------------------------------
// Name: GetDirection
// Description: Gets the direction of the person
// -------------------------------------------------------
int GetDirection()
{
return m_direction;
}
// -------------------------------------------------------
// Name: SetDirection
// Description: Sets the direction of the person
// -------------------------------------------------------
void SetDirection( int p_direction )
{
m_direction = (p_direction + 4) % 4;
}
// -------------------------------------------------------
// Name: SetPersonType
// Description: Sets the type of the person
// -------------------------------------------------------
void SetPersonType( int p_type )
{
m_type = p_type;
}
// -------------------------------------------------------
// Name: GetPersonType
// Description: Gets the type of the person
// -------------------------------------------------------
int GetPersonType()
{
return m_type;
}
// -------------------------------------------------------
// Name: SetHealth
// Description: sets the health of the person
// -------------------------------------------------------
void SetHealth( int p_health )
{
// set the health, and make sure it doesn't go below 0 or above 100;
m_health = p_health;
if( m_health < 0 )
m_health = 0;
if( m_health > 100 )
m_health = 100;
}
// -------------------------------------------------------
// Name: GetHealth
// Description: gets the health of the person
// -------------------------------------------------------
int GetHealth()
{
return m_health;
}
// -------------------------------------------------------
// Name: SetArmor
// Description: sets the armor of the person
// -------------------------------------------------------
void SetArmor( int p_armor )
{
m_armor = p_armor;
if( m_armor < 0 )
m_armor = 0;
if( m_armor > 100 )
m_armor = 100;
}
// -------------------------------------------------------
// Name: GetArmor
// Description: gets the armor of the person
// -------------------------------------------------------
int GetArmor()
{
return m_armor;
}
// -------------------------------------------------------
// Name: GetItemIterator
// Description: gets an item iterator pointing at the
// current item
// -------------------------------------------------------
DListIterator<Item*> GetItemIterator()
{
return m_currentweapon;
}
// -------------------------------------------------------
// Name: AddItem
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -