-
Notifications
You must be signed in to change notification settings - Fork 1
/
CircleComponent.h
86 lines (70 loc) · 1.9 KB
/
CircleComponent.h
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
/** Circle Component Header
*
* @author Caleb Geiger
* Created: 8-2-2013
* Source File: CircleComponent.h
*/
#pragma once
#include "IRenderComponent.h"
using namespace std;
using namespace sf;
class CircleComponent : public IRenderComponent
{
friend class RenderSystem;
private:
CircleShape _Circle;
public:
CircleComponent(unsigned int z = 0, sf::Vector2f offset = sf::Vector2f(0.f, 0.f)) : IRenderComponent("circle", z, offset) {
_Circle.setRadius(10);
_Circle.setFillColor(Color::Red);
}
void SetPosition(const Vector2f &pos) override
{
_Circle.setPosition(pos);
}
Drawable const& GetDrawable() const override
{
return _Circle;
}
void setRadius(float radius){
_Circle.setRadius(radius);
}
void setColor(Color const& c){
_Circle.setFillColor(c);
}
float getRadius(){
return _Circle.getRadius();
}
Color const& getColor(){
return _Circle.getFillColor();
}
void rLoad(lua_State *L) override
{
sf::Color color;
lua_pushstring(L, "radius");
lua_gettable(L, -2);
_Circle.setRadius(lua_tonumber(L, -1));
lua_pop(L, 1);
lua_pushstring(L, "r");
lua_gettable(L, -2);
color.r = lua_tonumber(L, -1);
lua_pop(L, 1);
lua_pushstring(L, "g");
lua_gettable(L, -2);
color.g = lua_tonumber(L, -1);
lua_pop(L, 1);
lua_pushstring(L, "b");
lua_gettable(L, -2);
color.b = lua_tonumber(L, -1);
lua_pop(L, 1);
lua_pushstring(L, "a");
lua_gettable(L, -2);
color.a = lua_tonumber(L, -1);
lua_pop(L, 1);
_Circle.setFillColor(color);
lua_getglobal(L, "x");
lua_getglobal(L, "y");
_Circle.setPosition(lua_tonumber(L, -2) + _offset.x, lua_tonumber(L, -1) + _offset.y);
lua_pop(L, 2);
}
};