• Fichier: Player.cpp
  • Path: /dungeon_ascii/DungeonASCII/Player.cpp
  • File size: 1.49 KB
  • MIME-type: text/x-c
  • Charset: utf-8
 
Retour
#include "Player.h"

Player::Player(std::string pName, int px, int py, int pHp)
{
	m_name = pName;

	m_coordinates.x = px;
	m_coordinates.y = py;

	m_hp = pHp;
}

void Player::move(int px, int py, Sector *pSector)
{
	if (pSector->getMap()[m_coordinates.y + py][m_coordinates.x + px] != '#')
	{
		m_coordinates.x += px;
		m_coordinates.y += py;

		if (pSector->getMap()[m_coordinates.y][m_coordinates.x] == '/') // Si le joueur rencontre une porte
		{
			// TODO: Avec la liste d'interactable (Collection heterogene), la liste de porte devient superflu. Possible de merger le tout en un seul if...
			Door *door = pSector->getDoorAt(m_coordinates.x, m_coordinates.y);
			door->interact();
		}
		else if (pSector->getMap()[m_coordinates.y][m_coordinates.x] != ' ') // Si le joueur rencontre un objet
		{
			Interactable *interactable = pSector->getInteractableAt(m_coordinates.x, m_coordinates.y);
			interactable->interact();
		}
	}
}

std::string Player::getName()
{
	return m_name;
}

Vector2* Player::getCoordinates()
{
	return &m_coordinates;
}

int Player::getHP()
{
	return m_hp;
}

void Player::setName(std::string pName)
{
	m_name = pName;
}

void Player::setHP(int pHp)
{
	if (pHp > 10)
		m_hp = 10;
	else
		m_hp = pHp;
}

void Player::doDamage(int pHp)
{
	m_hp -= pHp;
}

void Player::doHeal(int pHp)
{
	m_hp += pHp;
}

void Player::setCoordinates(int px, int py)
{
	m_coordinates.x = px;
	m_coordinates.y = py;
}

Player::~Player()
{

}