-
Notifications
You must be signed in to change notification settings - Fork 0
/
Character.cpp
56 lines (50 loc) · 1.51 KB
/
Character.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* This class is for the hero/main character
*
* @author Nathan Clark and Sebastian Mark
*/
#include "Character.h"
// constructor for the character
//constructors
Character::Character(std::string path, std::string walkSoundPath){
this->texture.loadFromFile(path);
this->sprite.setTexture(texture);
this->walkSound.setSound(walkSoundPath);
}
// overloaded constructor
Character::Character(std::string path, sf::IntRect textRec, std::string walkSoundPath) {
this->texture.loadFromFile(path);
this->sprite.setTextureRect(textRec);
this->sprite.setTexture(texture);
this->walkSound.setSound(walkSoundPath);
this->walkSound.getSound().setVolume(50);
}
// setting character (hero) position
void Character::setPosition(float x, float y){
this->sprite.setPosition(x, y);
}
// setting scale/size of the hero
void Character::setScale(float x, float y){
this->sprite.setScale(x, y);
}
// returning the position of the hero when called
sf::Vector2f Character::getPosition() {
return this->sprite.getPosition();
}
// returns the sprite object when called
sf::Sprite* Character::getSprite(){
return &this->sprite;
}
// returns current tile for the hero
int Character::getCurrentTile() {
return currentTile;
}
// setting current tile for the hero
void Character::setCurrentTile(int currentTile) {
this->currentTile = currentTile;
}
//moves player sprite by given x and y
void Character::move(float offSetX, float offSetY) {
this->sprite.move(offSetX, offSetY);
this->walkSound.play();
}