-
Notifications
You must be signed in to change notification settings - Fork 0
/
VisibleGameObject.cpp
118 lines (103 loc) · 1.95 KB
/
VisibleGameObject.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "StdAfx.h"
#include "VisibleGameObject.h"
VisibleGameObject::VisibleGameObject()
: _isLoaded(false)
{
//_isLoaded = false; Slightly faster to use the above constructor initialization.
}
VisibleGameObject::~VisibleGameObject()
{
}
void VisibleGameObject::Load(std::string filename)
{
if(_image.loadFromFile(filename) == false)
{
_filename = "";
_isLoaded = false;
}
else
{
_filename = filename;
_sprite.setTexture(_image);
_isLoaded = true;
}
}
void VisibleGameObject::Draw(sf::RenderWindow & renderWindow)
{
if(_isLoaded)
{
renderWindow.draw(_sprite);
}
}
void VisibleGameObject::Draw(sf::RenderWindow & renderWindow,int ballColorID)
{
if (_isLoaded)
{
float r, g, b;
sf::Shader m_shader;
switch (ballColorID%3)
{
case 0:
r = 0.95f;
g = 0.25f;
b = 0.20f;
break;
case 1:
g = 0.7f;
r = b = 0.3f;
break;
case 2:
b = 0.9f;
g = 0.6f;
r = 0.2f;
break;
}
// Load the shader
m_shader.loadFromFile("shaderFragment.frag", sf::Shader::Fragment);
m_shader.setUniform("merah", r);
m_shader.setUniform("ijo", g);
m_shader.setUniform("biru", b);
m_shader.setUniform("texture", sf::Shader::CurrentTexture);
sf::RenderStates states;
states.shader = &m_shader;
renderWindow.draw(_sprite, states);
}
}
void VisibleGameObject::Update(float elapsedTime)
{
}
void VisibleGameObject::SetPosition(float x, float y)
{
if(_isLoaded)
{
_sprite.setPosition(x,y);
}
}
sf::Vector2f VisibleGameObject::GetPosition() const
{
if(_isLoaded)
{
return _sprite.getPosition();
}
return sf::Vector2f();
}
float VisibleGameObject::GetHeight() const
{
return _sprite.getLocalBounds().height;
}
float VisibleGameObject::GetWidth() const
{
return _sprite.getLocalBounds().width;
}
sf::Rect<float> VisibleGameObject::GetBoundingRect() const
{
return _sprite.getGlobalBounds();
}
sf::Sprite& VisibleGameObject::GetSprite()
{
return _sprite;
}
bool VisibleGameObject::IsLoaded() const
{
return _isLoaded;
}