diff --git a/VaporWaveWars/actor.cpp b/VaporWaveWars/actor.cpp index e294e73..deca1ba 100644 --- a/VaporWaveWars/actor.cpp +++ b/VaporWaveWars/actor.cpp @@ -43,3 +43,4 @@ bool Actor::hitBy(Compas enemy) { Compas Actor::getAttack() const { return compas; } + diff --git a/VaporWaveWars/combat.cpp b/VaporWaveWars/combat.cpp index b6f6915..33e6041 100644 --- a/VaporWaveWars/combat.cpp +++ b/VaporWaveWars/combat.cpp @@ -2,10 +2,10 @@ Combat::Combat() { ia = false; -// ia = true; + // ia = true; attacking = playerOneTurn = true; player = new Player(0); -// enemy = new IaEnemy(1); + // enemy = new IaEnemy(1); enemy = new Player(1); scorePlayer = new Score(0); scoreEnemy = new Score(1); @@ -15,6 +15,13 @@ Combat::Combat() { } +Combat::~Combat(){ + for(std::vector::iterator w = waves.begin(); w != waves.end();){ + w=waves.erase(w); + } +} + + Combat::Combat(bool ia) { this->ia = ia; player = new Player(0); @@ -39,6 +46,15 @@ void Combat::update(float deltaTime, sf::RenderWindow *window) { time += deltaTime; _shader.setParameter("time", time); + for(std::vector::iterator w = waves.begin(); w != waves.end();){ + if ((*w)->getDirection() && (*w)->getPosition().x >= 1024) w=waves.erase(w); + else if (!(*w)->getDirection() && (*w)->getPosition().x <= 0) w=waves.erase(w); + + else{ + (*w)->update(deltaTime); + ++w; + } + } } void Combat::draw(sf::RenderWindow *window) { @@ -47,23 +63,31 @@ void Combat::draw(sf::RenderWindow *window) { enemy->draw(window); scorePlayer->draw(window); scoreEnemy->draw(window); + for(std::vector::iterator w = waves.begin(); w != waves.end(); ++w){ + window->draw(*(*w)); + } } void Combat::updateEvents(sf::Event e) { if (playerOneTurn) { + if(e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::C && !attacking) doMahWaves(!playerOneTurn); bool aux = player->event(e, !attacking); + if (!aux) { //end of player one ritm if (!attacking) { if(!player->hitBy(enemy->getAttack())) { scoreEnemy->incrisScore(); } + } else playerOneTurn = aux; attacking = !attacking; } } else if (!ia) { + if(e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::C && !attacking) doMahWaves(!playerOneTurn); + bool aux = !enemy->event(e, !attacking); enemyManager(aux); //end of player two not ia ritm } @@ -80,3 +104,20 @@ void Combat::enemyManager(bool aux) { attacking = !attacking; } } + +void Combat::doMahWaves(bool p){ + std::cout << "defensa jugador " << p << std::endl; + std::vector notes; + if(p){ + notes = player->getAttack().getNotes(); + } + else notes = enemy->getAttack().getNotes(); + + for(int i = 0; i < notes.size(); ++i){ + std::cout << notes[i] << std::endl; + Wave* w = new Wave(p); + if(!p) w->setPosition(512+512*notes[i],500); + else w->setPosition(512-512*notes[i],500); + waves.push_back(w); + } +} diff --git a/VaporWaveWars/combat.hpp b/VaporWaveWars/combat.hpp index 70c23c9..190b4a2 100644 --- a/VaporWaveWars/combat.hpp +++ b/VaporWaveWars/combat.hpp @@ -9,10 +9,11 @@ #include "actor.hpp" #include "soundmanager.hpp" #include "score.hpp" - +#include "wave.hpp" class Combat : public Scene { public: Combat(); + ~Combat(); Combat(bool ia); Combat(const Combat& m) = delete; Combat(const Combat&& m) = delete; @@ -29,10 +30,11 @@ private: sf::Texture _text; sf::Sprite _background; sf::Shader _shader; - + std::vector waves; Score *scoreEnemy, *scorePlayer; void initShader(); void enemyManager(bool aux); + void doMahWaves(bool p); }; #endif // COMBAT_H diff --git a/VaporWaveWars/commons.hpp b/VaporWaveWars/commons.hpp index d5dd879..60aeb88 100644 --- a/VaporWaveWars/commons.hpp +++ b/VaporWaveWars/commons.hpp @@ -8,6 +8,7 @@ #include /* getenv */ #include /* srand, rand */ #include /* time */ +#include // std::iterator, std::input_iterator_tag #include #include #include "soundmanager.hpp" diff --git a/VaporWaveWars/compas.cpp b/VaporWaveWars/compas.cpp index 18a2253..79b9101 100644 --- a/VaporWaveWars/compas.cpp +++ b/VaporWaveWars/compas.cpp @@ -40,6 +40,12 @@ bool Compas::isPressed() const { return isPress; } +const std::vector& Compas::getNotes() const +{ + return notes; +} + + int Compas::get (int i) const { return notes[i]; } diff --git a/VaporWaveWars/compas.hpp b/VaporWaveWars/compas.hpp index 5afb2ff..cc67f8d 100644 --- a/VaporWaveWars/compas.hpp +++ b/VaporWaveWars/compas.hpp @@ -22,6 +22,7 @@ public: void incraeseTime(); bool isPressed() const; bool operator ==(const Compas& d) const; + const std::vector &getNotes() const; }; #endif // COMPAS_HPP diff --git a/VaporWaveWars/game.cpp b/VaporWaveWars/game.cpp index 5c55c67..7e87cfd 100644 --- a/VaporWaveWars/game.cpp +++ b/VaporWaveWars/game.cpp @@ -21,6 +21,7 @@ Game* Game::i() { void Game::run() { sf::Clock c; sf::RenderWindow window(sf::VideoMode(W_WIDTH, W_HEIGHT), "( ( ( Radio Waves ) ) )"); + window.setKeyRepeatEnabled(false); float oldTime = c.getElapsedTime().asSeconds(); while (isRunning) { float time = c.getElapsedTime().asSeconds(); diff --git a/VaporWaveWars/wave.cpp b/VaporWaveWars/wave.cpp index 6a18d8a..f77ae64 100644 --- a/VaporWaveWars/wave.cpp +++ b/VaporWaveWars/wave.cpp @@ -1,20 +1,27 @@ #include "wave.hpp" + +bool Wave::getDirection() const +{ + return direction; +} + + Wave::Wave(bool dir){ direction = dir; ASSERT(texture.loadFromFile(spriteFile)); setTexture(texture); - sf::IntRect rect = sf::IntRect(0, 0, texture.getSize().x, texture.getSize().y); - setTextureRect(rect); +// sf::IntRect rect = sf::IntRect(0, 0, texture.getSize().x, texture.getSize().y); +// setTextureRect(rect); } void Wave::update(float deltaTime){ float pos = getPosition().x; if (direction){ - pos += 0; // AMOUNT?? + pos += 1280*deltaTime; // AMOUNT?? } else{ - pos -= 0; // "" + pos -= 1280*deltaTime; // "" } setPosition(pos, getPosition().y); } diff --git a/VaporWaveWars/wave.hpp b/VaporWaveWars/wave.hpp index c304d47..683f831 100644 --- a/VaporWaveWars/wave.hpp +++ b/VaporWaveWars/wave.hpp @@ -6,10 +6,6 @@ class Wave : public sf::Sprite{ private: //CONFIG const std::string spriteFile = WORK_DIR+"Resources/pulsation.png"; - //POSICIO PLAYER 1 - float posX1 = W_WIDTH*0.05f, posY1 = W_HEIGHT*0.6f; - //POSICIO PLAYER 2 - float posX2 = W_WIDTH*0.65f, posY2 = W_HEIGHT*0.6f; //END CONFIG bool direction; //TRUE => CAP A LA DRETA @@ -17,9 +13,9 @@ private: sf::Texture texture; public: - Wave(); Wave(bool dir); void update(float deltaTime); + bool getDirection() const; }; #endif // WAVE_HPP