diff --git a/VaporWaveWars/commons.hpp b/VaporWaveWars/commons.hpp index 62a3d42..6270508 100644 --- a/VaporWaveWars/commons.hpp +++ b/VaporWaveWars/commons.hpp @@ -7,6 +7,9 @@ #include #include #include + +#define MARGEERR 0.30f +#define BLACKVALUE 0.00025f #define ASSERT(expression) do \ { \ if(!(expression)) { \ diff --git a/VaporWaveWars/compas.cpp b/VaporWaveWars/compas.cpp index 33b3fca..e6de97c 100644 --- a/VaporWaveWars/compas.cpp +++ b/VaporWaveWars/compas.cpp @@ -1,7 +1,7 @@ #include "compas.hpp" Compas::Compas() { - spaceTime = 0; + spaceTime = 1; isPress = false; } @@ -9,7 +9,7 @@ void Compas::start() { if (not isPress) { std::cout << "start" << std::endl; isPress = true; - spaceTime = 0; + spaceTime = 1; notes = std::vector(); } } @@ -17,7 +17,7 @@ void Compas::start() { void Compas::add() { if (isPress) { notes.push_back(spaceTime); - spaceTime = 0; + spaceTime = 1; std::cout << "add" << std::endl; } } @@ -32,7 +32,7 @@ void Compas::end() { } } -void Compas::incriseTime() { +void Compas::incraeseTime() { ++spaceTime; } @@ -40,11 +40,16 @@ int Compas::get (int i) const { return notes[i]; } +int Compas::size() const { + return notes.size(); +} + bool Compas::operator ==(const Compas& d) const{ int n = notes.size(); + if (n != d.size()) return false; for (int i = 0; i < n; ++i) { float diff = ((float) (std::abs(notes[i] - d.get(i))))/((float) (notes[i])); - if (diff > margeErr) return false; + if (diff > MARGEERR) return false; } return true; } diff --git a/VaporWaveWars/compas.hpp b/VaporWaveWars/compas.hpp index 8067e04..a73a400 100644 --- a/VaporWaveWars/compas.hpp +++ b/VaporWaveWars/compas.hpp @@ -4,24 +4,22 @@ #include #include #include +#include -static const float margeErr = 0.80f; - -class Compas -{ - +class Compas { private: bool isPress; int spaceTime; std::vector notes; + int get(int i) const; + int size() const; public: Compas(); void start(); void add(); void end(); - void incriseTime(); - int get(int i) const; + void incraeseTime(); bool operator ==(const Compas& d) const; }; diff --git a/VaporWaveWars/mygame.cpp b/VaporWaveWars/mygame.cpp index 0fb03b7..c02d9f3 100644 --- a/VaporWaveWars/mygame.cpp +++ b/VaporWaveWars/mygame.cpp @@ -3,6 +3,7 @@ MyGame::MyGame() { _state = GameState::menu; std::cout << "in menu" << std::endl; + compas2 = compas = Compas(); } MyGame::~MyGame() { @@ -10,6 +11,8 @@ MyGame::~MyGame() { // Main game loop void MyGame::update(float deltaTime, sf::RenderWindow*window) { +// std::cout << deltaTime << std::endl; + if (deltaTime > BLACKVALUE) compas.incraeseTime(); sf::Event event; while(window->pollEvent(event)){ switch (event.type) { @@ -17,9 +20,19 @@ void MyGame::update(float deltaTime, sf::RenderWindow*window) { Game::i()->isRunning = false; break; case (sf::Event::KeyPressed): - if(event.key.code == sf::Keyboard::Escape) - // Exit the game like this - Game::i()->isRunning = false; + if(event.key.code == sf::Keyboard::Escape) + Game::i()->isRunning = false; // Exit the game like this + if(event.key.code == sf::Keyboard::C) + compas.start(); + if(event.key.code == sf::Keyboard::Space) + compas.add(); + break; + case (sf::Event::KeyReleased): + if (event.key.code == sf::Keyboard::C) { + compas.end(); + std::cout << (compas == compas2) << std::endl; + compas2 = compas; + } break; case (sf::Event::MouseMoved): case (sf::Event::MouseButtonPressed): diff --git a/VaporWaveWars/mygame.hpp b/VaporWaveWars/mygame.hpp index 0b544fe..2659c1b 100644 --- a/VaporWaveWars/mygame.hpp +++ b/VaporWaveWars/mygame.hpp @@ -1,13 +1,15 @@ #ifndef MYGAME_HPP #define MYGAME_HPP #include "game.hpp" - +#include "compas.hpp" class MyGame : public Game{ public: MyGame(); virtual ~MyGame(); private: + Compas compas, compas2; + GameState::gameState _state; virtual void update(float deltaTime, sf::RenderWindow *window) final override; virtual void draw(sf::RenderWindow *window) final override;