workin on waves

This commit is contained in:
Ralusama19 2017-01-21 20:55:12 +01:00
parent 78feb5e092
commit d32840dc51
9 changed files with 69 additions and 13 deletions

View file

@ -43,3 +43,4 @@ bool Actor::hitBy(Compas enemy) {
Compas Actor::getAttack() const { Compas Actor::getAttack() const {
return compas; return compas;
} }

View file

@ -15,6 +15,13 @@ Combat::Combat() {
} }
Combat::~Combat(){
for(std::vector<Wave*>::iterator w = waves.begin(); w != waves.end();){
w=waves.erase(w);
}
}
Combat::Combat(bool ia) { Combat::Combat(bool ia) {
this->ia = ia; this->ia = ia;
player = new Player(0); player = new Player(0);
@ -39,6 +46,15 @@ void Combat::update(float deltaTime, sf::RenderWindow *window) {
time += deltaTime; time += deltaTime;
_shader.setParameter("time", time); _shader.setParameter("time", time);
for(std::vector<Wave*>::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) { void Combat::draw(sf::RenderWindow *window) {
@ -47,23 +63,31 @@ void Combat::draw(sf::RenderWindow *window) {
enemy->draw(window); enemy->draw(window);
scorePlayer->draw(window); scorePlayer->draw(window);
scoreEnemy->draw(window); scoreEnemy->draw(window);
for(std::vector<Wave*>::iterator w = waves.begin(); w != waves.end(); ++w){
window->draw(*(*w));
}
} }
void Combat::updateEvents(sf::Event e) { void Combat::updateEvents(sf::Event e) {
if (playerOneTurn) { if (playerOneTurn) {
if(e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::C && !attacking) doMahWaves(!playerOneTurn);
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
if (!attacking) { if (!attacking) {
if(!player->hitBy(enemy->getAttack())) { if(!player->hitBy(enemy->getAttack())) {
scoreEnemy->incrisScore(); scoreEnemy->incrisScore();
} }
} }
else playerOneTurn = aux; else playerOneTurn = aux;
attacking = !attacking; attacking = !attacking;
} }
} }
else if (!ia) { else if (!ia) {
if(e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::C && !attacking) doMahWaves(!playerOneTurn);
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
} }
@ -80,3 +104,20 @@ void Combat::enemyManager(bool aux) {
attacking = !attacking; attacking = !attacking;
} }
} }
void Combat::doMahWaves(bool p){
std::cout << "defensa jugador " << p << std::endl;
std::vector<int> 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);
}
}

View file

@ -9,10 +9,11 @@
#include "actor.hpp" #include "actor.hpp"
#include "soundmanager.hpp" #include "soundmanager.hpp"
#include "score.hpp" #include "score.hpp"
#include "wave.hpp"
class Combat : public Scene { class Combat : public Scene {
public: public:
Combat(); Combat();
~Combat();
Combat(bool ia); Combat(bool ia);
Combat(const Combat& m) = delete; Combat(const Combat& m) = delete;
Combat(const Combat&& m) = delete; Combat(const Combat&& m) = delete;
@ -29,10 +30,11 @@ private:
sf::Texture _text; sf::Texture _text;
sf::Sprite _background; sf::Sprite _background;
sf::Shader _shader; sf::Shader _shader;
std::vector<Wave*> waves;
Score *scoreEnemy, *scorePlayer; Score *scoreEnemy, *scorePlayer;
void initShader(); void initShader();
void enemyManager(bool aux); void enemyManager(bool aux);
void doMahWaves(bool p);
}; };
#endif // COMBAT_H #endif // COMBAT_H

View file

@ -8,6 +8,7 @@
#include <stdlib.h> /* getenv */ #include <stdlib.h> /* getenv */
#include <stdlib.h> /* srand, rand */ #include <stdlib.h> /* srand, rand */
#include <time.h> /* time */ #include <time.h> /* time */
#include <iterator> // std::iterator, std::input_iterator_tag
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "soundmanager.hpp" #include "soundmanager.hpp"

View file

@ -40,6 +40,12 @@ bool Compas::isPressed() const {
return isPress; return isPress;
} }
const std::vector<int>& Compas::getNotes() const
{
return notes;
}
int Compas::get (int i) const { int Compas::get (int i) const {
return notes[i]; return notes[i];
} }

View file

@ -22,6 +22,7 @@ public:
void incraeseTime(); void incraeseTime();
bool isPressed() const; bool isPressed() const;
bool operator ==(const Compas& d) const; bool operator ==(const Compas& d) const;
const std::vector<int> &getNotes() const;
}; };
#endif // COMPAS_HPP #endif // COMPAS_HPP

View file

@ -21,6 +21,7 @@ Game* Game::i() {
void Game::run() { void Game::run() {
sf::Clock c; sf::Clock c;
sf::RenderWindow window(sf::VideoMode(W_WIDTH, W_HEIGHT), "( ( ( Radio Waves ) ) )"); sf::RenderWindow window(sf::VideoMode(W_WIDTH, W_HEIGHT), "( ( ( Radio Waves ) ) )");
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();

View file

@ -1,20 +1,27 @@
#include "wave.hpp" #include "wave.hpp"
bool Wave::getDirection() const
{
return direction;
}
Wave::Wave(bool dir){ Wave::Wave(bool dir){
direction = dir; direction = dir;
ASSERT(texture.loadFromFile(spriteFile)); ASSERT(texture.loadFromFile(spriteFile));
setTexture(texture); setTexture(texture);
sf::IntRect rect = sf::IntRect(0, 0, texture.getSize().x, texture.getSize().y); // sf::IntRect rect = sf::IntRect(0, 0, texture.getSize().x, texture.getSize().y);
setTextureRect(rect); // setTextureRect(rect);
} }
void Wave::update(float deltaTime){ void Wave::update(float deltaTime){
float pos = getPosition().x; float pos = getPosition().x;
if (direction){ if (direction){
pos += 0; // AMOUNT?? pos += 1280*deltaTime; // AMOUNT??
} }
else{ else{
pos -= 0; // "" pos -= 1280*deltaTime; // ""
} }
setPosition(pos, getPosition().y); setPosition(pos, getPosition().y);
} }

View file

@ -6,10 +6,6 @@ class Wave : public sf::Sprite{
private: private:
//CONFIG //CONFIG
const std::string spriteFile = WORK_DIR+"Resources/pulsation.png"; 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 //END CONFIG
bool direction; //TRUE => CAP A LA DRETA bool direction; //TRUE => CAP A LA DRETA
@ -17,9 +13,9 @@ private:
sf::Texture texture; sf::Texture texture;
public: public:
Wave();
Wave(bool dir); Wave(bool dir);
void update(float deltaTime); void update(float deltaTime);
bool getDirection() const;
}; };
#endif // WAVE_HPP #endif // WAVE_HPP