-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBonus.cpp
65 lines (60 loc) · 1.37 KB
/
Bonus.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
60
61
62
63
64
65
#include "Bonus.h"
#include <iostream>
#include <sstream>
/*
* Constructor
*/
Bonus::Bonus(int minX, int minY, int y)
{
_bonus = y % 5;
//Sprite loading
if (_bonus == Bonus::BONUS_TYPE_HEAL) {
if (!texture.loadFromFile("images/obstacles/heal.png")) {};
}
else {
if (!texture.loadFromFile("images/obstacles/random.png")) {};
}
sprite = sf::Sprite(texture);
//Set position out of screen
int posX = minX + texture.getSize().x;
int posY = y % (minY - texture.getSize().y);
sprite.setPosition(posX, posY);
//Set type
_type = Obstacle::TYPE_BONUS;
}
/*
* Destructor
*/
Bonus::~Bonus()
{
}
/*
* Return the bonus sprite for the bonus type parameter
*/
std::string Bonus::getBonusSprite(int typeBonus)
{
if (typeBonus == -1) return "images/bonus/bonus.png";
std::stringstream ss;
ss << "images/bonus/bonus" << typeBonus << ".png";
return ss.str();
}
/*
* Return the correct laser color for the bonus type parameter
*/
int Bonus::getColorLaser(int typeBonus)
{
switch (typeBonus)
{
case Bonus::BONUS_TYPE_DAMAGE: return Laser::LASER_TYPE_RED;
case Bonus::BONUS_TYPE_SPEED: return Laser::LASER_TYPE_GREEN;
case Bonus::BONUS_TYPE_METEOR: return Laser::LASER_TYPE_YELLOW;
default: return Laser::LASER_TYPE_BLUE; break;
}
}
/*
* Return the bonus type as an integer
*/
int Bonus::getBonus() const
{
return _bonus;
}