This repository was archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
64 lines (55 loc) · 1.28 KB
/
Player.cpp
File metadata and controls
64 lines (55 loc) · 1.28 KB
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
60
61
62
63
64
#include "Player.hpp"
#include "Game.hpp"
Player::Player(int _hp, float _speed, sf::Texture& texture) : SpaceShip(_hp, _speed, texture)
{}
void Player::getDamage()
{
hpCurrent--;
}
void Player::getHeal()
{
if (hpCurrent < hpMax) hpCurrent++;
}
void Player::getHeal(unsigned int x)
{
hpCurrent += x;
if (hpCurrent > hpMax) hpCurrent = hpMax;
}
void Player::moveLeft()
{
//Movement Limit
if(sprite.getPosition().x > 60.0f)
sprite.move(-(1.0f/120.0f*speed),0.0f);
}
void Player::moveRight()
{
//Movement Limit
if(sprite.getPosition().x < 1860.0f)
sprite.move(1.0f/120.0f*speed, 0);
}
void Player::shot(std::vector<Bullet>& listofBullets, sf::Texture& tx)
{
if (listofBullets.size() < 1)
{
Bullet tempbullet(sprite.getPosition().x, sprite.getPosition().y - sprite.getTexture()->getSize().y * 0.20f, tx, -1);
listofBullets.push_back(tempbullet);
soundShot.play();
}
}
void Player::deadEnd(int _hp, float _speed)
{
hpCurrent = _hp;
hpMax = _hp;
speed = _speed;
}
void Player::deadEnd(int _hp, float _speed, sf::Texture& texture, sf::SoundBuffer& sb)
{
hpCurrent = _hp;
hpMax = _hp;
speed = _speed;
sprite.setTexture(texture);
sprite.setOrigin(texture.getSize().x*0.5f, texture.getSize().y*0.5f);
sprite.setScale(0.4f, 0.4f);
soundShot.setBuffer(sb);
soundShot.setVolume(50.0f);
}