halo
This commit is contained in:
parent
74256387a0
commit
6d3e97da9f
5 changed files with 36 additions and 15 deletions
12
Resources/halo.frag
Normal file
12
Resources/halo.frag
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
uniform float time;
|
||||||
|
uniform bool blue;
|
||||||
|
uniform sampler2D texture;
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
float transpa = max (sin(time*5.)*100., 50.);
|
||||||
|
vec4 color = vec4 (246.,111.,231.,transpa)/255.;
|
||||||
|
if (blue) color = vec4(0.,153.,253.,transpa)/255.;
|
||||||
|
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
|
||||||
|
|
||||||
|
gl_FragColor = pixel * color;
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
uniform float time;
|
// uniform float time2;
|
||||||
uniform bool blue;
|
uniform bool blue;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
float transpa = sin(time)*255.;
|
// float transpa = sin(time2)*255.;
|
||||||
vec4 color = (246,111,231, (transpa));
|
vec4 color = (246,111,231, 255);
|
||||||
if (blue) color = (0,153,253, (transpa));
|
if (blue) color = (0,153,253, 255);
|
||||||
gl_FragColor = color;
|
gl_FragColor = color;
|
||||||
}
|
}
|
|
@ -9,9 +9,9 @@ private:
|
||||||
const int numFrames = 4;
|
const int numFrames = 4;
|
||||||
const std::string spriteFile = WORK_DIR+"Resources/spreadsheet.png";
|
const std::string spriteFile = WORK_DIR+"Resources/spreadsheet.png";
|
||||||
//POSICIO PLAYER 1
|
//POSICIO PLAYER 1
|
||||||
float posX1 = W_WIDTH*0.05f, posY1 = W_HEIGHT*0.6f;
|
float posX1 = W_WIDTH*0.05f, posY1 = W_HEIGHT*0.5f;
|
||||||
//POSICIO PLAYER 2
|
//POSICIO PLAYER 2
|
||||||
float posX2 = W_WIDTH*0.65f, posY2 = W_HEIGHT*0.6f;
|
float posX2 = W_WIDTH*0.65f, posY2 = W_HEIGHT*0.5f;
|
||||||
//END CONFIG
|
//END CONFIG
|
||||||
|
|
||||||
int magicNumber;
|
int magicNumber;
|
||||||
|
|
|
@ -30,17 +30,23 @@ void Combat::initShader() {
|
||||||
_background.setTexture(_text);
|
_background.setTexture(_text);
|
||||||
_shader.loadFromFile(WORK_DIR+"Resources/shader.frag", sf::Shader::Fragment);
|
_shader.loadFromFile(WORK_DIR+"Resources/shader.frag", sf::Shader::Fragment);
|
||||||
_shader.setParameter("resolution", sf::Vector2f(W_WIDTH, W_HEIGHT));
|
_shader.setParameter("resolution", sf::Vector2f(W_WIDTH, W_HEIGHT));
|
||||||
|
_shader.setParameter("time", time);
|
||||||
|
|
||||||
|
ASSERT(_haloT.loadFromFile(WORK_DIR+"Resources/platform-halo.png"));
|
||||||
|
_halo.setTexture(_haloT);
|
||||||
|
_halo.setPosition(W_WIDTH*0.05f, W_HEIGHT*0.5f);
|
||||||
|
_shaderHalo.loadFromFile(WORK_DIR+"Resources/halo.frag", sf::Shader::Fragment);
|
||||||
|
_shaderHalo.setParameter("blue", attacking);
|
||||||
|
_shaderHalo.setParameter("time", time);
|
||||||
|
|
||||||
_shaderHalo.loadFromFile(WORK_DIR+"Resources/shaderHalo.frag", sf::Shader::Fragment);
|
|
||||||
_shaderHalo.setParameter("blue", false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Combat::update(float deltaTime, sf::RenderWindow *window) {
|
void Combat::update(float deltaTime, sf::RenderWindow *window) {
|
||||||
player->update(deltaTime, window);
|
player->update(deltaTime, window);
|
||||||
bool aux = enemy->update(deltaTime, window);
|
bool aux = enemy->update(deltaTime, window);
|
||||||
if (ia) enemyManager(aux); //end of player two ia rythm
|
if (ia) enemyManager(aux); //end of player two ia rythm
|
||||||
time += deltaTime;
|
|
||||||
|
|
||||||
|
time += deltaTime;
|
||||||
_shader.setParameter("time", time);
|
_shader.setParameter("time", time);
|
||||||
_shaderHalo.setParameter("time", time);
|
_shaderHalo.setParameter("time", time);
|
||||||
}
|
}
|
||||||
|
@ -49,12 +55,14 @@ void Combat::draw(sf::RenderWindow *window) {
|
||||||
window->draw(_background, &_shader);
|
window->draw(_background, &_shader);
|
||||||
player->draw(window);
|
player->draw(window);
|
||||||
enemy->draw(window);
|
enemy->draw(window);
|
||||||
|
window->draw(_halo, &_shaderHalo);
|
||||||
scorePlayer->draw(window);
|
scorePlayer->draw(window);
|
||||||
scoreEnemy->draw(window);
|
scoreEnemy->draw(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Combat::updateEvents(sf::Event e) {
|
void Combat::updateEvents(sf::Event e) {
|
||||||
if (playerOneTurn) {
|
if (playerOneTurn) {
|
||||||
|
_halo.setPosition(W_WIDTH*0.05f, W_HEIGHT*0.5f);
|
||||||
bool aux = player->event(e, !attacking);
|
bool aux = player->event(e, !attacking);
|
||||||
if (!aux) { //end of player one ritm
|
if (!aux) { //end of player one ritm
|
||||||
|
|
||||||
|
@ -65,9 +73,11 @@ void Combat::updateEvents(sf::Event e) {
|
||||||
}
|
}
|
||||||
else playerOneTurn = aux;
|
else playerOneTurn = aux;
|
||||||
attacking = !attacking;
|
attacking = !attacking;
|
||||||
|
_shaderHalo.setParameter("blue", attacking);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!ia) {
|
else if (!ia) {
|
||||||
|
_halo.setPosition(W_WIDTH*0.65f, W_HEIGHT*0.5f);
|
||||||
bool aux = !enemy->event(e, !attacking);
|
bool aux = !enemy->event(e, !attacking);
|
||||||
enemyManager(aux); //end of player two not ia ritm
|
enemyManager(aux); //end of player two not ia ritm
|
||||||
}
|
}
|
||||||
|
@ -82,5 +92,6 @@ void Combat::enemyManager(bool aux) {
|
||||||
}
|
}
|
||||||
else playerOneTurn = aux;
|
else playerOneTurn = aux;
|
||||||
attacking = !attacking;
|
attacking = !attacking;
|
||||||
|
_shaderHalo.setParameter("blue", attacking);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,14 +23,12 @@ public:
|
||||||
void updateEvents(sf::Event e) final override;
|
void updateEvents(sf::Event e) final override;
|
||||||
private:
|
private:
|
||||||
bool playerOneTurn, ia, attacking;
|
bool playerOneTurn, ia, attacking;
|
||||||
Actor *player;
|
Actor *player, *enemy;
|
||||||
Actor *enemy;
|
|
||||||
float time;
|
float time;
|
||||||
sf::Texture _text;
|
|
||||||
sf::Sprite _background;
|
|
||||||
sf::Shader _shader;
|
|
||||||
|
|
||||||
sf::Shader _shaderHalo;
|
sf::Texture _text, _haloT, _plataformT;
|
||||||
|
sf::Sprite _background, _halo, _plataform;
|
||||||
|
sf::Shader _shader, _shaderHalo;
|
||||||
|
|
||||||
Score *scoreEnemy, *scorePlayer;
|
Score *scoreEnemy, *scorePlayer;
|
||||||
void initShader();
|
void initShader();
|
||||||
|
|
Reference in a new issue