-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.cpp
59 lines (56 loc) · 1.36 KB
/
Player.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
57
58
59
#include "Player.h"
Player::Player(
sf::Vector2f pPosition,
sf::Vector2f pVelocity,
sf::Vector2i pSize,
sf::Texture *pTexture,
float pAngle,
float pAngularVelocity) :
AnimatedSprite(pPosition, pVelocity, pSize, pTexture, pAngle, pAngularVelocity)
{
//add animations idle/walk/jump
mAnimations.insert(mAnimations.begin(), Animation(2));
mAnimations.insert(mAnimations.begin(), Animation(2));
mAnimations.insert(mAnimations.begin(), Animation(2));
mSprite.scale(4,4);
//start playing idle animation
AnimatedSprite::startAnimation();
mPlayerState = pNONE;
}
Player::~Player(void)
{
}
//update depending on player state
void Player::update()
{
//right now just moves and switches animations
switch(mPlayerState)
{
case(pLEFT):
mVelocity = sf::Vector2f(-mSpeed, 0);
AnimatedSprite::setCurrentAnimation(2);
mSprite.setScale(-4.f,4.f);
break;
case(pRIGHT):
mVelocity = sf::Vector2f(mSpeed, 0);
AnimatedSprite::setCurrentAnimation(2);
mSprite.setScale(4.f,4.f);
break;
case(pUP):
mVelocity = sf::Vector2f(0, -mSpeed);
AnimatedSprite::setCurrentAnimation(1);
break;
case(pDOWN):
mVelocity = sf::Vector2f(0, +mSpeed);
AnimatedSprite::setCurrentAnimation(2);
break;
case(pNONE):
AnimatedSprite::setCurrentAnimation(0);
mVelocity = sf::Vector2f(0, 0);
break;
default:
break;
}
//call superclass update
AnimatedSprite::update();
}