-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ball.cpp
79 lines (65 loc) · 1.43 KB
/
Ball.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "Ball.h"
//Private functions
void Ball::initVariables()
{
}
void Ball::initShape(const sf::RenderWindow& window)
{
this->shape.setRadius(static_cast<float>(rand() % 10 + 10));
sf::Color color(255, rand() % 155 + 55, 0, 255);
switch (this->type)
{
case DEFAULT:
color = sf::Color(rand() % 155 + 55, 0, 255, 255);
this->shape.setFillColor(color);
color.r -= 50;
color.b -= 50;
break;
case DAMAGING:
color = sf::Color(255, rand() % 155 + 55, 0, 255);
this->shape.setFillColor(color);
color.r -= 50;
color.g -= 50;
break;
case HEALING:
color = sf::Color(0, 255, rand() % 155 + 55, 255);
this->shape.setFillColor(color);
color.g -= 50;
color.b -= 50;
break;
default:
break;
}
this->shape.setOutlineColor(color);
this->shape.setOutlineThickness((this->shape.getRadius()) / 4);
this->shape.setPosition(
sf::Vector2f(
static_cast<float>(rand() % window.getSize().x - this->shape.getGlobalBounds().width),
static_cast<float>(rand() % window.getSize().y - this->shape.getGlobalBounds().height)));
}
//Constructors and Distructors
Ball::Ball(const sf::RenderWindow& window, unsigned type)
: type(type)
{
this->initShape(window);
}
Ball::~Ball()
{
}
//Accessors
const sf::CircleShape Ball::getShape() const
{
return this->shape;
}
const int& Ball::getType() const
{
return this->type;
}
//Functions
void Ball::update()
{
}
void Ball::render(sf::RenderTarget& target)
{
target.draw(this->shape);
}