Compare commits

..

1 commit

Author SHA1 Message Date
vylion
ce0ad4fafa Se ha intentado comprobar la defensa a tiempo real 2017-01-22 04:15:02 +01:00
104 changed files with 206 additions and 203 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 736 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Resources/Sounds/clicks.wav Normal file

Binary file not shown.

Binary file not shown.

BIN
Resources/Sounds/intro.wav Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 230 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 744 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View file

@ -1,6 +1,5 @@
uniform vec2 resolution; uniform vec2 resolution;
uniform float time; uniform float time;
uniform float hour;
float rand(vec2 n) { float rand(vec2 n) {
return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453); return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
@ -37,10 +36,8 @@ void main(void) {
if (uv.y < umuv.y) uv.y += abs(time * 0.1); if (uv.y < umuv.y) uv.y += abs(time * 0.1);
else uv.y -= abs(time * 0.1); else uv.y -= abs(time * 0.1);
vec3 colorPink = vec3(255.,0.,255.);
vec3 colorBlue = vec3(0.,255.,255.); vec4 color = vec4(255, 120, 153, 255) / 255.;
vec4 color = vec4(((colorBlue.x*hour) + (colorPink.x*(1.-hour)))/2., vec4 colorB = vec4(255,255,255,255)/ 255.;
((colorBlue.y*hour) + (colorPink.y*(1.-hour)))/2.,
((colorBlue.z*hour) + (colorPink.z*(1.-hour)))/2., 255) / 255.;
gl_FragColor = (grid(fract(uv))) * color - line(umuv.y, 0., 0.175, 0.025) * color * 2.; gl_FragColor = (grid(fract(uv))) * color - line(umuv.y, 0., 0.175, 0.025) * color * 2.;
} }

View file

@ -35,8 +35,8 @@ bool Actor::update(float deltaTime, sf::RenderWindow *window) {
bool Actor::hitBy(Compas enemy) { bool Actor::hitBy(Compas enemy) {
bool dodge = enemy == compas; bool dodge = enemy == compas;
/*if (dodge) //std::cout << "dodge" << std::endl; if (dodge) std::cout << "dodge" << std::endl;
else //std::cout << "hit" << std::endl;*/ else std::cout << "hit" << std::endl;
if (!dodge) { if (!dodge) {
character->setState(PlayerState::hurt); character->setState(PlayerState::hurt);
animate = PlayerState::inMidle; animate = PlayerState::inMidle;

View file

@ -15,6 +15,7 @@ public:
bool hitBy(Compas enemy); bool hitBy(Compas enemy);
Compas getAttack() const; Compas getAttack() const;
virtual bool event(sf::Event e) = 0; virtual bool event(sf::Event e) = 0;
virtual DefenseResult::defenseResult event(sf::Event e, int note) = 0;
protected: protected:
Compas compas; Compas compas;

View file

@ -25,7 +25,7 @@ int Button::getClicks(){
int c = _clicks; int c = _clicks;
//cout << "popping clicks " << c << endl; //cout << "popping clicks " << c << endl;
_clicks = 0; _clicks = 0;
//if (_clicks > 0) //std::cout << "popclicks = " << _clicks << std::endl; //if (_clicks > 0) std::cout << "popclicks = " << _clicks << std::endl;
return c; return c;
} }
@ -51,14 +51,14 @@ void Button::handleMouseEvent(sf::Event& event){
switch (event.type){ switch (event.type){
case (sf::Event::MouseButtonPressed): case (sf::Event::MouseButtonPressed):
if(_state == ButtonState::active) _state = ButtonState::pressed; if(_state == ButtonState::active) _state = ButtonState::pressed;
////std::cout << "pressed!" << _clicks << std::endl; //std::cout << "pressed!" << _clicks << std::endl;
break; break;
case (sf::Event::MouseButtonReleased): case (sf::Event::MouseButtonReleased):
if(_state == ButtonState::pressed){ if(_state == ButtonState::pressed){
_state = ButtonState::active; _state = ButtonState::active;
++_clicks; ++_clicks;
////std::cout << "released!" << _clicks << std::endl; //std::cout << "released!" << _clicks << std::endl;
} }
break; break;

View file

@ -51,30 +51,23 @@ void Character::setState(PlayerState::playerState state){
indexX = 0; indexX = 0;
indexY = 1 + magicNumber; indexY = 1 + magicNumber;
std::string sample = "atk"+std::to_string(rand()%20+1); std::string sample = "atk"+std::to_string(rand()%20+1);
SoundManager::setVolume(100,sample);
SoundManager::playSound(sample); SoundManager::playSound(sample);
////std::cout << "playing sample " << sample << std::endl; //std::cout << "playing sample " << sample << std::endl;
} }
else if (state == PlayerState::hurt){ else if (state == PlayerState::hurt){
////std::cout << "i am hurt" << std::endl; std::cout << "i am hurt" << std::endl;
indexX = 0; indexX = 0;
indexY = 2 + magicNumber; indexY = 2 + magicNumber;
std::string sample = "fail"+std::to_string(rand()%6+1); std::string sample = "fail"+std::to_string(rand()%6+1);
SoundManager::setVolume(100,sample);
SoundManager::playSound(sample);
////std::cout << "playing sample " << sample << std::endl;
}
else if (state == PlayerState::success){
////std::cout << "i am succeed!" << std::endl;
indexX = 0;
indexY = 3 + magicNumber;
std::string sample = "bona"+std::to_string(rand()%8+1);
SoundManager::setVolume(10,sample);
SoundManager::playSound(sample); SoundManager::playSound(sample);
//std::cout << "playing sample " << sample << std::endl; //std::cout << "playing sample " << sample << std::endl;
}
else if (state == PlayerState::success){
std::cout << "i am succeed!" << std::endl;
indexX = 0;
indexY = 3 + magicNumber;
//std::string sample = "succeed"+std::to_string(rand()%6+1);
//SoundManager::playSound(sample);
} }
} }

View file

@ -4,6 +4,8 @@ Combat::Combat() {
ia = false; ia = false;
// ia = true; // ia = true;
state = CombatState::player_atk; state = CombatState::player_atk;
readingCompas = false;
readCompas = 0;
player = new Player(0); player = new Player(0);
// enemy = new IaEnemy(1); // enemy = new IaEnemy(1);
enemy = new Player(1); enemy = new Player(1);
@ -33,6 +35,8 @@ Combat::Combat(bool ia) {
if (ia) enemy = new IaEnemy(1); if (ia) enemy = new IaEnemy(1);
else enemy = new Player(1); else enemy = new Player(1);
initShader(); initShader();
readingCompas = false;
readCompas = 0;
} }
bool Combat::isAttack() const { bool Combat::isAttack() const {
@ -61,25 +65,13 @@ void Combat::updateHalo() {
} }
float isNight() {
time_t rawtime;
struct tm * ptm;
time ( &rawtime );
ptm = gmtime ( &rawtime );
float hour = (float ((ptm->tm_hour+UTC)%24))/(23.);
float result = (std::cos(hour*(2*PI)) + 1.f)/2.;
return result;
}
void Combat::initShader() { void Combat::initShader() {
time = 0; time = 0;
aux = 0;
_text.create(W_WIDTH, W_HEIGHT); _text.create(W_WIDTH, W_HEIGHT);
_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); _shader.setParameter("time", time);
_shader.setParameter("hour", isNight());
ASSERT(_haloT.loadFromFile(WORK_DIR+"Resources/platform-halo.png")); ASSERT(_haloT.loadFromFile(WORK_DIR+"Resources/platform-halo.png"));
_halo.setTexture(_haloT); _halo.setTexture(_haloT);
@ -98,7 +90,7 @@ void Combat::initShader() {
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);
@ -152,65 +144,90 @@ void Combat::draw(sf::RenderWindow *window) {
} }
void Combat::updateEvents(sf::Event e) { void Combat::updateEvents(sf::Event e) {
if (isPlayerOne()) { if (isPlayerOne() or !ia) {
bool compasFinish = !player->event(e); enemyManager(e);
enemyManager(compasFinish);
if(e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::C && !isAttack()) doMahWaves(!isPlayerOne());
}
else if (!ia) {
bool compasFinish = !enemy->event(e);
enemyManager(compasFinish);
if(e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::C && !isAttack()) doMahWaves(!isPlayerOne());
} }
} }
void Combat::enemyManager(bool compasFinish) { //To do: considerar si hay ia void Combat::enemyManager(sf::Event e) { //To do: considerar si hay ia
if(compasFinish) { if(e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::C && !isAttack()) doMahWaves(!isPlayerOne());
Compas compas;
switch(state) { Compas compas;
case CombatState::player_def:
compas = enemy->getAttack(); switch(state) {
if(!player->hitBy(compas)) { case CombatState::player_def:
scoreEnemy->incrisScore(); if(!readingCompas) {
} readingCompas = true;
else { readCompas = 0;
scorePlayer->incrisScore(); std::cout << "Start reading pink defense" << std::endl;
} }
compas = enemy->getAttack();
if(readCompas == compas.size()) {
state = CombatState::player_atk; state = CombatState::player_atk;
break; readingCompas = false;
case CombatState::player_atk: }
else {
std::cout << "Reading note " << readCompas << " out of " << compas.size() << std::endl;
DefenseResult::defenseResult defense = player->event(e, compas.get(readCompas));
if(defense == DefenseResult::fail) {
scoreEnemy->incrisScore();
state = CombatState::player_atk;
readingCompas = false;
}
else if(defense == DefenseResult::success) {
++readCompas;
}
}
break;
case CombatState::player_atk:
if(!player->event(e)) {
compas = player->getAttack(); compas = player->getAttack();
if(compas.isFailed()) { if(compas.isFailed()) {
state = CombatState::enemy_atk; state = CombatState::enemy_atk;
} }
else state = CombatState::enemy_def; else state = CombatState::enemy_def;
break; }
case CombatState::enemy_def: break;
compas = player->getAttack(); case CombatState::enemy_def:
if(!enemy->hitBy(compas)) { if(!readingCompas) {
readingCompas = true;
readCompas = 0;
std::cout << "Start reading blue defense" << std::endl;
}
compas = player->getAttack();
if(readCompas < compas.size()) {
std::cout << "Reading note " << readCompas << " out of " << compas.size() << std::endl;
DefenseResult::defenseResult defense = enemy->event(e, compas.get(readCompas));
if(defense == DefenseResult::fail) {
scorePlayer->incrisScore(); scorePlayer->incrisScore();
state = CombatState::enemy_atk;
readingCompas = false;
} }
else { else if(defense == DefenseResult::success) {
scoreEnemy->incrisScore(); ++readCompas;
} }
}
else {
state = CombatState::enemy_atk; state = CombatState::enemy_atk;
break; readingCompas = false;
case CombatState::enemy_atk: }
break;
case CombatState::enemy_atk:
if(!enemy->event(e)) {
compas = enemy->getAttack(); compas = enemy->getAttack();
if(compas.isFailed()) { if(compas.isFailed()) {
state = CombatState::player_atk; state = CombatState::player_atk;
} }
else state = CombatState::player_def; else state = CombatState::player_def;
break; }
default: break;
break; default:
} break;
} }
} }
void Combat::doMahWaves(bool p) { void Combat::doMahWaves(bool p) {
//std::cout << "defensa jugador " << p << std::endl; std::cout << "defensa jugador " << p << std::endl;
std::vector<int> notes; std::vector<int> notes;
if(p){ if(p){
notes = player->getAttack().getNotes(); notes = player->getAttack().getNotes();
@ -221,11 +238,11 @@ void Combat::doMahWaves(bool p) {
if(!p) anterior = 256+256*anterior; if(!p) anterior = 256+256*anterior;
else anterior = 768-256*anterior; else anterior = 768-256*anterior;
for(int i = 0; i < notes.size(); ++i){ for(int i = 0; i < notes.size(); ++i){
//std::cout << notes[i] << std::endl; std::cout << notes[i] << std::endl;
Wave* w = new Wave(p); Wave* w = new Wave(p);
//if(!p) w->setPosition(anterior,500); //if(!p) w->setPosition(anterior,500);
//else w->setPosition(512-512*anterior,500); //else w->setPosition(512-512*anterior,500);
w->setPosition(anterior,W_HEIGHT/2 + 17); w->setPosition(anterior,W_HEIGHT/2);
if(i<notes.size()) { if(i<notes.size()) {
if(!p) anterior += 176*notes[i+1]; if(!p) anterior += 176*notes[i+1];
else anterior -= 176*notes[i+1]; else anterior -= 176*notes[i+1];
@ -237,7 +254,7 @@ void Combat::doMahWaves(bool p) {
// if(!p) anterior = 512+256*anterior; // if(!p) anterior = 512+256*anterior;
// else anterior = 512-256*anterior; // else anterior = 512-256*anterior;
// for(int i = 0; i < 20; ++i){ // for(int i = 0; i < 20; ++i){
// ////std::cout << 0 << std::endl; // //std::cout << 0 << std::endl;
// Wave* w = new Wave(p); // Wave* w = new Wave(p);
// //if(!p) w->setPosition(anterior,500); // //if(!p) w->setPosition(anterior,500);
// //else w->setPosition(512-512*anterior,500); // //else w->setPosition(512-512*anterior,500);

View file

@ -10,11 +10,6 @@
#include "soundmanager.hpp" #include "soundmanager.hpp"
#include "score.hpp" #include "score.hpp"
#include "wave.hpp" #include "wave.hpp"
#include <time.h>
#define PI 3.14159265
class Combat : public Scene { class Combat : public Scene {
public: public:
@ -29,7 +24,8 @@ class Combat : public Scene {
void draw(sf::RenderWindow *window) final override; void draw(sf::RenderWindow *window) final override;
void updateEvents(sf::Event e) final override; void updateEvents(sf::Event e) final override;
private: private:
bool playerOneTurn, ia, attacking, toEnemy; bool playerOneTurn, ia, attacking, toEnemy, readingCompas;
int readCompas;
Actor *player, *enemy; Actor *player, *enemy;
float time; float time;
CombatState::combatState state; CombatState::combatState state;
@ -39,13 +35,12 @@ class Combat : public Scene {
sf::Shader _shader, _shaderHalo; sf::Shader _shader, _shaderHalo;
Score *scoreEnemy, *scorePlayer; Score *scoreEnemy, *scorePlayer;
void initShader(); void initShader();
void enemyManager(bool aux); void enemyManager(sf::Event e);
void animationTo(bool toEnemy, float deltaTime); void animationTo(bool toEnemy, float deltaTime);
bool isAttack() const; bool isAttack() const;
bool isPlayerOne() const; bool isPlayerOne() const;
void updateHalo(); void updateHalo();
void doMahWaves(bool p); void doMahWaves(bool p);
int aux;
}; };

View file

@ -13,11 +13,9 @@
#include <string> #include <string>
#include "soundmanager.hpp" #include "soundmanager.hpp"
const int SCENE_NUM = 4; const int SCENE_NUM = 4;
#define MARGEERR 0.25f #define MARGEERR 0.2f
#define BLACKVALUE 0.4f #define BLACKVALUE 0.4f
#define W_WIDTH 1024 #define W_WIDTH 1024
#define UTC (0)
#define W_HEIGHT 768 #define W_HEIGHT 768
const std::string WORK_DIR(getenv("WORK_DIR")); const std::string WORK_DIR(getenv("WORK_DIR"));
@ -52,4 +50,8 @@ namespace CombatState {
enum combatState{player_def = 0, player_atk = 1, enemy_def = 2, enemy_atk = 3}; enum combatState{player_def = 0, player_atk = 1, enemy_def = 2, enemy_atk = 3};
} }
namespace DefenseResult {
enum defenseResult{nothing = 0, success = 1, fail = 2};
}
#endif // COMMONS_HPP #endif // COMMONS_HPP

View file

@ -9,7 +9,7 @@ Compas::Compas() {
void Compas::start() { void Compas::start() {
failed = false; failed = false;
if (not isPress) { if (not isPress) {
// //std::cout << "start" << std::endl; // std::cout << "start" << std::endl;
isPress = true; isPress = true;
spaceTime = 1; spaceTime = 1;
notes = std::vector<int>(); notes = std::vector<int>();
@ -20,16 +20,16 @@ void Compas::add() {
if (isPress) { if (isPress) {
notes.push_back(spaceTime); notes.push_back(spaceTime);
spaceTime = 1; spaceTime = 1;
// //std::cout << "add" << std::endl; // std::cout << "add" << std::endl;
} }
} }
void Compas::end() { void Compas::end() {
if (isPress) { if (isPress) {
isPress = false; isPress = false;
// //std::cout << "end" << std::endl; // std::cout << "end" << std::endl;
// for (int i = 0; i < notes.size(); ++i) { // for (int i = 0; i < notes.size(); ++i) {
// //std::cout << notes[i] << std::endl; // std::cout << notes[i] << std::endl;
// } // }
} }
} }
@ -39,7 +39,7 @@ void Compas::fail() {
end(); end();
} }
void Compas::incraeseTime() { void Compas::increaseTime() {
++spaceTime; ++spaceTime;
} }
@ -51,6 +51,17 @@ bool Compas::isFailed() const {
return failed; return failed;
} }
bool Compas::check(int note) {
std::cout << "Checking note " << note << std::endl;
bool res = false;
if(isPress) {
res = (std::abs((float) note - spaceTime) / (float) note) < (MARGEERR);
spaceTime = 1;
}
return res;
}
const std::vector<int>& Compas::getNotes() const const std::vector<int>& Compas::getNotes() const
{ {
return notes; return notes;

View file

@ -12,18 +12,19 @@ private:
bool failed; bool failed;
int spaceTime; int spaceTime;
std::vector<int> notes; std::vector<int> notes;
int get(int i) const;
int size() const;
public: public:
Compas(); Compas();
int get(int i) const;
int size() const;
void start(); void start();
void add(); void add();
void end(); void end();
void fail(); void fail();
void incraeseTime(); void increaseTime();
bool isPressed() const; bool isPressed() const;
bool isFailed() const; bool isFailed() const;
bool check(int note);
bool operator ==(const Compas& d) const; bool operator ==(const Compas& d) const;
const std::vector<int> &getNotes() const; const std::vector<int> &getNotes() const;
}; };

View file

@ -20,17 +20,15 @@ Game* Game::i() {
// Main game loop // Main game loop
void Game::run() { void Game::run() {
sf::Clock c; sf::Clock c;
sf::RenderWindow window(sf::VideoMode(W_WIDTH, W_HEIGHT), "( ( ( Radio Wave ) ) )", sf::Style::Close); sf::RenderWindow window(sf::VideoMode(W_WIDTH, W_HEIGHT), "( ( ( Radio Waves ) ) )", sf::Style::Close);
window.setFramerateLimit(25); window.setFramerateLimit(25);
window.setKeyRepeatEnabled(false); window.setKeyRepeatEnabled(false);
float oldTime = c.getElapsedTime().asSeconds(); float oldTime = c.getElapsedTime().asSeconds();
while (isRunning) { while (isRunning) {
float time = c.getElapsedTime().asSeconds(); float time = c.getElapsedTime().asSeconds();
float deltaTime = time-oldTime; float deltaTime = time-oldTime;
oldTime = time; oldTime = time;
////std::cout << deltaTime << std::endl; //std::cout << deltaTime << std::endl;
update(deltaTime, &window); update(deltaTime, &window);
draw( &window); draw( &window);
} }

View file

@ -8,3 +8,5 @@ bool IaEnemy::updateLogic(float deltaTime, sf::RenderWindow *window) {
} }
bool IaEnemy::event(sf::Event e) {return false;} bool IaEnemy::event(sf::Event e) {return false;}
DefenseResult::defenseResult IaEnemy::event(sf::Event e, int note) {return DefenseResult::fail;}

View file

@ -8,6 +8,7 @@ public:
IaEnemy(); IaEnemy();
IaEnemy(int player); IaEnemy(int player);
bool event(sf::Event e) final override; bool event(sf::Event e) final override;
DefenseResult::defenseResult event(sf::Event e, int note) final override;
protected: protected:
bool updateLogic(float deltaTime, sf::RenderWindow *window); bool updateLogic(float deltaTime, sf::RenderWindow *window);

View file

@ -17,7 +17,7 @@ Menu::Menu() {
void Menu::update(float deltaTime, sf::RenderWindow*window){ void Menu::update(float deltaTime, sf::RenderWindow*window){
//float dx = InputManager::action(InputAction::moveX0); //float dx = InputManager::action(InputAction::moveX0);
//_buttons[0]->move(dx,0); //_buttons[0]->move(dx,0);
////std::cout << dx << std::endl; //std::cout << dx << std::endl;
for(unsigned int i = 0; i < _buttons.size(); ++i){ for(unsigned int i = 0; i < _buttons.size(); ++i){
_buttons[i]->update(window->mapPixelToCoords(sf::Vector2i(sf::Mouse::getPosition(*window)))); _buttons[i]->update(window->mapPixelToCoords(sf::Vector2i(sf::Mouse::getPosition(*window))));
} }
@ -31,14 +31,14 @@ void Menu::draw(sf::RenderWindow* window){
} }
void Menu::updateEvents(sf::Event e){ void Menu::updateEvents(sf::Event e){
// //std::cout << "update menu buttons" << std::endl; // std::cout << "update menu buttons" << std::endl;
for(unsigned int i = 0; i < _buttons.size(); ++i){ for(unsigned int i = 0; i < _buttons.size(); ++i){
_buttons[i]->handleMouseEvent(e); _buttons[i]->handleMouseEvent(e);
} }
MyGame* g = static_cast<MyGame*>(Game::i()); MyGame* g = static_cast<MyGame*>(Game::i());
if (_start.getClicks() > 0){ if (_start.getClicks() > 0){
g->changeScene(GameScene::inGame); g->changeScene(GameScene::inGame);
//std::cout << "Game not ready to be played. Please Wait." << std::endl; std::cout << "Game not ready to be played. Please Wait." << std::endl;
} }
else if(_exit.getClicks() > 0) g->isRunning = false; else if(_exit.getClicks() > 0) g->isRunning = false;

View file

@ -8,8 +8,9 @@ MyGame::MyGame() {
_scenes[GameScene::inGame] = _combat; _scenes[GameScene::inGame] = _combat;
_scenes[GameScene::help] = _menu; _scenes[GameScene::help] = _menu;
_scenes[GameScene::credits] = _menu; _scenes[GameScene::credits] = _menu;
//std::cout << "in menu" << std::endl; std::cout << "in menu" << std::endl;
SoundManager::load(); SoundManager::load();
SoundManager::setGlobalSoundVolumen(50);
SoundManager::setLoop(true, "intro"); SoundManager::setLoop(true, "intro");
SoundManager::playMusic("intro"); SoundManager::playMusic("intro");
} }
@ -30,7 +31,6 @@ void MyGame::changeScene(GameScene::gameScene n){
_combat = new Combat; _combat = new Combat;
_scenes[_scene] = _combat; _scenes[_scene] = _combat;
SoundManager::setLoop(true, "clicks"); SoundManager::setLoop(true, "clicks");
SoundManager::setVolume(85,"clicks");
SoundManager::playMusic("clicks"); SoundManager::playMusic("clicks");
} }
} }
@ -38,7 +38,7 @@ void MyGame::changeScene(GameScene::gameScene n){
// Main game loop // Main game loop
void MyGame::update(float deltaTime, sf::RenderWindow*window) { void MyGame::update(float deltaTime, sf::RenderWindow*window) {
// //std::cout << deltaTime << std::endl; // std::cout << deltaTime << std::endl;
sf::Event event; sf::Event event;
while(window->pollEvent(event)){ while(window->pollEvent(event)){
switch (event.type) { switch (event.type) {
@ -56,7 +56,7 @@ void MyGame::update(float deltaTime, sf::RenderWindow*window) {
switch(_scene){ switch(_scene){
case(GameScene::menu): case(GameScene::menu):
////std::cout << "still in menu" << std::endl; //std::cout << "still in menu" << std::endl;
break; break;
default: default:
break; break;

View file

@ -4,26 +4,20 @@ Player::Player(int num) : Actor(num) {
compas = Compas(); compas = Compas();
error = false; error = false;
time = 0; time = 0;
mod = false;
} }
Player::Player() : Actor() { Player::Player() : Actor() {
compas = Compas(); compas = Compas();
error = false; error = false;
time = 0; time = 0;
mod = false;
} }
bool Player::updateLogic(float deltaTime, sf::RenderWindow *window) { bool Player::updateLogic(float deltaTime, sf::RenderWindow *window) {
time += deltaTime; time += deltaTime;
clock += deltaTime;
if (time > BLACKVALUE) { if (time > BLACKVALUE) {
compas.incraeseTime(); compas.increaseTime();
time = 0; time = 0;
} }
if (clock >= 89.15) clock = 0.0;
if (!mod && clock > 38.10 && clock < 64) mod = true;
else if (mod && clock < 38.10 || clock > 64) mod = false;
return false; return false;
} }
@ -31,11 +25,9 @@ bool Player::event(sf::Event e) {
switch(e.type) { switch(e.type) {
case (sf::Event::KeyPressed): case (sf::Event::KeyPressed):
if(e.key.code == sf::Keyboard::C) { if(e.key.code == sf::Keyboard::C) {
std::string sample = "note"+std::to_string(rand()%4+1);
std::string sample = "mod"+std::to_string(rand()%4+1);
if(!mod) sample = "note"+std::to_string(rand()%4+1);
SoundManager::playSound(sample); SoundManager::playSound(sample);
//std::cout << "playing sample " << sample << std::endl; std::cout << "playing sample " << sample << std::endl;
compas.start(); compas.start();
error = false; error = false;
} }
@ -65,3 +57,44 @@ bool Player::event(sf::Event e) {
} }
return true; return true;
} }
DefenseResult::defenseResult Player::event(sf::Event e, int note) {
std::cout << "Let's read an event" << std::endl;
switch(e.type) {
case (sf::Event::KeyPressed):
if(e.key.code == sf::Keyboard::C) {
std::string sample = "note"+std::to_string(rand()%4+1);
SoundManager::playSound(sample);
std::cout << "playing sample " << sample << std::endl;
if(!compas.isPressed()) compas.start();
error = false;
}
if(e.key.code == sf::Keyboard::Space) {
if (animate == PlayerState::idle && !error) {
std::cout << "Let's check notes" << std::endl;
bool correct = compas.check(note);
if(!correct) {
animate = PlayerState::hurt;
compas.end();
return DefenseResult::fail;
}
else {
animate = PlayerState::attacking;
return DefenseResult::success;
}
}
else {
if (!error) {
compas.fail();
animate = PlayerState::hurt;
error = true;
return DefenseResult::fail;
}
}
}
break;
default:
break;
}
return DefenseResult::nothing;
}

View file

@ -9,13 +9,13 @@ public:
Player(); Player();
Player(int num); Player(int num);
bool event(sf::Event e) final override; bool event(sf::Event e) final override;
DefenseResult::defenseResult event(sf::Event e, int note) final override;
protected: protected:
bool updateLogic(float deltaTime, sf::RenderWindow *window); bool updateLogic(float deltaTime, sf::RenderWindow *window);
private: private:
float time; float time;
bool error; bool error;
bool mod;
float clock = 0.0;
}; };
#endif // PLAYER_H #endif // PLAYER_H

Some files were not shown because too many files have changed in this diff Show more