So I'm creating a player class that holds the players name, health, and mana. I figured this would be a good class to also hold the players sprite and texture to that sprite as well, though I'm starting to see where that might be an issue. Trying to wrap my head around the logical way to go about this. I'll leave my code here so you can see what I'm talking about.
Player.cpp
#include "Player.h"
#include "SFML/Graphics.hpp"
Player::Player(std::string p_Name, int p_Health, int p_Mana, sf::Texture p_Texture)
{
Name = p_Name;
newHealth = p_Health;
newMana = p_Mana;
newTexture = p_Texture;
}
Player::~Player()
{
}
//Get class data.
std::string Player::getName()
{
return Name;
}
int Player::getHealth()
{
return newHealth;
}
int Player::getMana()
{
return newMana;
}
//Set class data.
void Player::setName(std::string p_Name)
{
Name = p_Name;
}
void Player::setHealth(int p_Health)
{
newHealth = p_Health;
}
void Player::setMana(int p_Mana)
{
newMana = p_Mana;
}
void Player::setTexture(sf::Texture pTexture)
{
newTexture = pTexture;
}
void Player::setSprite(sf::Sprite pSprite)
{
Sprite = pSprite;
}
Player.h
#pragma once
#ifndef PLAYER_H
#define PLAYER_H
#include <iostream>
#include <string>
#include "SFML/Graphics.hpp"
class Player
{
public:
Player();
Player(std::string, int, int, sf::Texture);
~Player();
std::string getName();
int getHealth();
int getMana();
void setName(std::string);
void setHealth(int);
void setMana(int);
void setSprite(sf::Sprite);
void setTexture(sf::Texture);
private:
std::string Name;
int newHealth;
int newMana;
sf::Texture newTexture;
sf::Sprite Sprite;
};
#endif
main.cpp
#include "SFML/Graphics.hpp"
#include "Player.h"
#include <conio.h>
#include <iostream>
#include <string>
int main()
{
std::string name;
int health = 0, mana = 10;
sf::Texture DarthVader;
sf::Texture pTexture;
sf::Sprite mainChar;
Player Player1(name, health, mana, pTexture);
std::cin >> name;
Player1.setName(name);
Player1.setTexture(DarthVader);
Player1.setSprite(mainChar);
std::cout << Player1.getMana();
std::cout << Player1.getName() << std::endl;
return 0;
}
Now obviously having a player class function "setTexture" is going to cause a conflict (at least a think). Secondly, do I even need to set the sprite and the texture with a class function? The player will be able to choose to play from a few different characters, but does that require setting the sprite and texture for each one or should I just have a setTexture for the sprite? I'm a little confused on how to best go about this.
Any input is appreciated. Thank you and Merry Christmas!