-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrick.cpp
86 lines (72 loc) · 1.39 KB
/
Brick.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
80
81
82
83
84
85
86
#include "pch.h"
#include "Brick.h"
/*
Brick type 1 : blue 1 hit
Brick type 2 : red 2 hit
Brick type 3 : Green 1 hit buffMoreBall
*/
void Brick::initShape(int type)
{
this->shape.setSize(sf::Vector2f(50.f, 20.f));
if (type == 1)
this->shape.setFillColor(sf::Color::Blue);
else if (type == 2)
this->shape.setFillColor(sf::Color::Red);
else
{
this->shape.setFillColor(sf::Color::Green);
}
}
void Brick::initVar(int type)
{
this->type = type; buffBall = nullptr;
if (type == 1) this->health = 1;
else if (type == 2) this->health = 2;
else if (type == 3)
{
this->health = 1;
sf::Vector2f pos = this->shape.getPosition();
sf::Vector2f sz = this->shape.getSize(); sz.x /= 2; sz.y /= 2;
pos.x += sz.x; pos.y += sz.y;
buffBall = new BuffBall(pos,1);
}
}
void Brick::initPos(sf::Vector2f pos)
{
this->shape.setPosition(pos);
}
Brick::Brick(sf::Vector2f pos,int health)
{
this->initShape(health);
this->initPos(pos);
this->initVar(health);
}
Brick::~Brick()
{
}
sf::RectangleShape Brick::getShape()
{
return this->shape;
}
int Brick::getHealth()
{
return this->health;
}
BuffBall* Brick::getBuff()
{
return this->buffBall;
}
void Brick::decreaseHealth()
{
this->health--;
}
void Brick::update()
{
//this->health--;
if (this->health == 1 && this->type == 2)
this->shape.setFillColor(sf::Color::Blue);
}
void Brick::render(sf::RenderTarget* window)
{
window->draw(this->shape);
}