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 {
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) {
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<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) {
@ -47,23 +63,31 @@ void Combat::draw(sf::RenderWindow *window) {
enemy->draw(window);
scorePlayer->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) {
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<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 "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<Wave*> waves;
Score *scoreEnemy, *scorePlayer;
void initShader();
void enemyManager(bool aux);
void doMahWaves(bool p);
};
#endif // COMBAT_H

View file

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

View file

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

View file

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

View file

@ -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();

View file

@ -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);
}

View file

@ -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