Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
|
ce0ad4fafa |
BIN
Radio Wave.zip
Before Width: | Height: | Size: 736 KiB |
BIN
Resources/Sounds/Fails/1.wav
Normal file
BIN
Resources/Sounds/Fails/2.wav
Normal file
BIN
Resources/Sounds/Fails/3.wav
Normal file
BIN
Resources/Sounds/Fails/4.wav
Normal file
BIN
Resources/Sounds/Fails/5.wav
Normal file
BIN
Resources/Sounds/Fails/6.wav
Normal file
BIN
Resources/Sounds/Notes/1.wav
Normal file
BIN
Resources/Sounds/Notes/2.wav
Normal file
BIN
Resources/Sounds/Notes/3.wav
Normal file
BIN
Resources/Sounds/Notes/4.wav
Normal file
BIN
Resources/Sounds/Samples/1.wav
Normal file
BIN
Resources/Sounds/Samples/10.wav
Normal file
BIN
Resources/Sounds/Samples/11.wav
Normal file
BIN
Resources/Sounds/Samples/12.wav
Normal file
BIN
Resources/Sounds/Samples/13.wav
Normal file
BIN
Resources/Sounds/Samples/14.wav
Normal file
BIN
Resources/Sounds/Samples/15.wav
Normal file
BIN
Resources/Sounds/Samples/16.wav
Normal file
BIN
Resources/Sounds/Samples/17.wav
Normal file
BIN
Resources/Sounds/Samples/18.wav
Normal file
BIN
Resources/Sounds/Samples/19.wav
Normal file
BIN
Resources/Sounds/Samples/2.wav
Normal file
BIN
Resources/Sounds/Samples/20.wav
Normal file
BIN
Resources/Sounds/Samples/3.wav
Normal file
BIN
Resources/Sounds/Samples/4.wav
Normal file
BIN
Resources/Sounds/Samples/5.wav
Normal file
BIN
Resources/Sounds/Samples/6.wav
Normal file
BIN
Resources/Sounds/Samples/7.wav
Normal file
BIN
Resources/Sounds/Samples/8.wav
Normal file
BIN
Resources/Sounds/Samples/9.wav
Normal file
BIN
Resources/Sounds/clicks.wav
Normal file
BIN
Resources/Sounds/intro.wav
Normal file
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3 KiB |
Before Width: | Height: | Size: 230 KiB |
Before Width: | Height: | Size: 744 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
|
@ -1,6 +1,5 @@
|
|||
uniform vec2 resolution;
|
||||
uniform float time;
|
||||
uniform float hour;
|
||||
|
||||
float rand(vec2 n) {
|
||||
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);
|
||||
else uv.y -= abs(time * 0.1);
|
||||
vec3 colorPink = vec3(255.,0.,255.);
|
||||
vec3 colorBlue = vec3(0.,255.,255.);
|
||||
vec4 color = vec4(((colorBlue.x*hour) + (colorPink.x*(1.-hour)))/2.,
|
||||
((colorBlue.y*hour) + (colorPink.y*(1.-hour)))/2.,
|
||||
((colorBlue.z*hour) + (colorPink.z*(1.-hour)))/2., 255) / 255.;
|
||||
|
||||
vec4 color = vec4(255, 120, 153, 255) / 255.;
|
||||
vec4 colorB = vec4(255,255,255,255)/ 255.;
|
||||
gl_FragColor = (grid(fract(uv))) * color - line(umuv.y, 0., 0.175, 0.025) * color * 2.;
|
||||
}
|
|
@ -35,8 +35,8 @@ bool Actor::update(float deltaTime, sf::RenderWindow *window) {
|
|||
|
||||
bool Actor::hitBy(Compas enemy) {
|
||||
bool dodge = enemy == compas;
|
||||
/*if (dodge) //std::cout << "dodge" << std::endl;
|
||||
else //std::cout << "hit" << std::endl;*/
|
||||
if (dodge) std::cout << "dodge" << std::endl;
|
||||
else std::cout << "hit" << std::endl;
|
||||
if (!dodge) {
|
||||
character->setState(PlayerState::hurt);
|
||||
animate = PlayerState::inMidle;
|
||||
|
|
|
@ -15,6 +15,7 @@ public:
|
|||
bool hitBy(Compas enemy);
|
||||
Compas getAttack() const;
|
||||
virtual bool event(sf::Event e) = 0;
|
||||
virtual DefenseResult::defenseResult event(sf::Event e, int note) = 0;
|
||||
|
||||
protected:
|
||||
Compas compas;
|
||||
|
|
|
@ -25,7 +25,7 @@ int Button::getClicks(){
|
|||
int c = _clicks;
|
||||
//cout << "popping clicks " << c << endl;
|
||||
_clicks = 0;
|
||||
//if (_clicks > 0) //std::cout << "popclicks = " << _clicks << std::endl;
|
||||
//if (_clicks > 0) std::cout << "popclicks = " << _clicks << std::endl;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
@ -51,14 +51,14 @@ void Button::handleMouseEvent(sf::Event& event){
|
|||
switch (event.type){
|
||||
case (sf::Event::MouseButtonPressed):
|
||||
if(_state == ButtonState::active) _state = ButtonState::pressed;
|
||||
////std::cout << "pressed!" << _clicks << std::endl;
|
||||
//std::cout << "pressed!" << _clicks << std::endl;
|
||||
break;
|
||||
|
||||
case (sf::Event::MouseButtonReleased):
|
||||
if(_state == ButtonState::pressed){
|
||||
_state = ButtonState::active;
|
||||
++_clicks;
|
||||
////std::cout << "released!" << _clicks << std::endl;
|
||||
//std::cout << "released!" << _clicks << std::endl;
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -51,30 +51,23 @@ void Character::setState(PlayerState::playerState state){
|
|||
indexX = 0;
|
||||
indexY = 1 + magicNumber;
|
||||
std::string sample = "atk"+std::to_string(rand()%20+1);
|
||||
SoundManager::setVolume(100,sample);
|
||||
|
||||
SoundManager::playSound(sample);
|
||||
////std::cout << "playing sample " << sample << std::endl;
|
||||
//std::cout << "playing sample " << sample << std::endl;
|
||||
}
|
||||
else if (state == PlayerState::hurt){
|
||||
////std::cout << "i am hurt" << std::endl;
|
||||
std::cout << "i am hurt" << std::endl;
|
||||
indexX = 0;
|
||||
indexY = 2 + magicNumber;
|
||||
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);
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ Combat::Combat() {
|
|||
ia = false;
|
||||
// ia = true;
|
||||
state = CombatState::player_atk;
|
||||
readingCompas = false;
|
||||
readCompas = 0;
|
||||
player = new Player(0);
|
||||
// enemy = new IaEnemy(1);
|
||||
enemy = new Player(1);
|
||||
|
@ -33,6 +35,8 @@ Combat::Combat(bool ia) {
|
|||
if (ia) enemy = new IaEnemy(1);
|
||||
else enemy = new Player(1);
|
||||
initShader();
|
||||
readingCompas = false;
|
||||
readCompas = 0;
|
||||
}
|
||||
|
||||
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() {
|
||||
time = 0;
|
||||
aux = 0;
|
||||
_text.create(W_WIDTH, W_HEIGHT);
|
||||
_background.setTexture(_text);
|
||||
_shader.loadFromFile(WORK_DIR+"Resources/shader.frag", sf::Shader::Fragment);
|
||||
_shader.setParameter("resolution", sf::Vector2f(W_WIDTH, W_HEIGHT));
|
||||
_shader.setParameter("time", time);
|
||||
_shader.setParameter("hour", isNight());
|
||||
|
||||
ASSERT(_haloT.loadFromFile(WORK_DIR+"Resources/platform-halo.png"));
|
||||
_halo.setTexture(_haloT);
|
||||
|
@ -98,7 +90,7 @@ void Combat::initShader() {
|
|||
void Combat::update(float deltaTime, sf::RenderWindow *window) {
|
||||
player->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;
|
||||
_shader.setParameter("time", time);
|
||||
|
@ -152,65 +144,90 @@ void Combat::draw(sf::RenderWindow *window) {
|
|||
}
|
||||
|
||||
void Combat::updateEvents(sf::Event e) {
|
||||
if (isPlayerOne()) {
|
||||
bool compasFinish = !player->event(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());
|
||||
if (isPlayerOne() or !ia) {
|
||||
enemyManager(e);
|
||||
}
|
||||
}
|
||||
|
||||
void Combat::enemyManager(bool compasFinish) { //To do: considerar si hay ia
|
||||
if(compasFinish) {
|
||||
void Combat::enemyManager(sf::Event e) { //To do: considerar si hay ia
|
||||
if(e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::C && !isAttack()) doMahWaves(!isPlayerOne());
|
||||
|
||||
Compas compas;
|
||||
|
||||
switch(state) {
|
||||
case CombatState::player_def:
|
||||
if(!readingCompas) {
|
||||
readingCompas = true;
|
||||
readCompas = 0;
|
||||
std::cout << "Start reading pink defense" << std::endl;
|
||||
}
|
||||
compas = enemy->getAttack();
|
||||
if(!player->hitBy(compas)) {
|
||||
scoreEnemy->incrisScore();
|
||||
if(readCompas == compas.size()) {
|
||||
state = CombatState::player_atk;
|
||||
readingCompas = false;
|
||||
}
|
||||
else {
|
||||
scorePlayer->incrisScore();
|
||||
}
|
||||
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();
|
||||
if(compas.isFailed()) {
|
||||
state = CombatState::enemy_atk;
|
||||
}
|
||||
else state = CombatState::enemy_def;
|
||||
}
|
||||
break;
|
||||
case CombatState::enemy_def:
|
||||
if(!readingCompas) {
|
||||
readingCompas = true;
|
||||
readCompas = 0;
|
||||
std::cout << "Start reading blue defense" << std::endl;
|
||||
}
|
||||
compas = player->getAttack();
|
||||
if(!enemy->hitBy(compas)) {
|
||||
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();
|
||||
state = CombatState::enemy_atk;
|
||||
readingCompas = false;
|
||||
}
|
||||
else if(defense == DefenseResult::success) {
|
||||
++readCompas;
|
||||
}
|
||||
}
|
||||
else {
|
||||
scoreEnemy->incrisScore();
|
||||
}
|
||||
state = CombatState::enemy_atk;
|
||||
readingCompas = false;
|
||||
}
|
||||
break;
|
||||
case CombatState::enemy_atk:
|
||||
if(!enemy->event(e)) {
|
||||
compas = enemy->getAttack();
|
||||
if(compas.isFailed()) {
|
||||
state = CombatState::player_atk;
|
||||
}
|
||||
else state = CombatState::player_def;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Combat::doMahWaves(bool p) {
|
||||
//std::cout << "defensa jugador " << p << std::endl;
|
||||
std::cout << "defensa jugador " << p << std::endl;
|
||||
std::vector<int> notes;
|
||||
if(p){
|
||||
notes = player->getAttack().getNotes();
|
||||
|
@ -221,11 +238,11 @@ void Combat::doMahWaves(bool p) {
|
|||
if(!p) anterior = 256+256*anterior;
|
||||
else anterior = 768-256*anterior;
|
||||
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);
|
||||
//if(!p) w->setPosition(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(!p) 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;
|
||||
// else anterior = 512-256*anterior;
|
||||
// for(int i = 0; i < 20; ++i){
|
||||
// ////std::cout << 0 << std::endl;
|
||||
// //std::cout << 0 << std::endl;
|
||||
// Wave* w = new Wave(p);
|
||||
// //if(!p) w->setPosition(anterior,500);
|
||||
// //else w->setPosition(512-512*anterior,500);
|
||||
|
|
|
@ -10,11 +10,6 @@
|
|||
#include "soundmanager.hpp"
|
||||
#include "score.hpp"
|
||||
#include "wave.hpp"
|
||||
#include <time.h>
|
||||
|
||||
#define PI 3.14159265
|
||||
|
||||
|
||||
class Combat : public Scene {
|
||||
|
||||
public:
|
||||
|
@ -29,7 +24,8 @@ class Combat : public Scene {
|
|||
void draw(sf::RenderWindow *window) final override;
|
||||
void updateEvents(sf::Event e) final override;
|
||||
private:
|
||||
bool playerOneTurn, ia, attacking, toEnemy;
|
||||
bool playerOneTurn, ia, attacking, toEnemy, readingCompas;
|
||||
int readCompas;
|
||||
Actor *player, *enemy;
|
||||
float time;
|
||||
CombatState::combatState state;
|
||||
|
@ -39,13 +35,12 @@ class Combat : public Scene {
|
|||
sf::Shader _shader, _shaderHalo;
|
||||
Score *scoreEnemy, *scorePlayer;
|
||||
void initShader();
|
||||
void enemyManager(bool aux);
|
||||
void enemyManager(sf::Event e);
|
||||
void animationTo(bool toEnemy, float deltaTime);
|
||||
bool isAttack() const;
|
||||
bool isPlayerOne() const;
|
||||
void updateHalo();
|
||||
void doMahWaves(bool p);
|
||||
int aux;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
#include <string>
|
||||
#include "soundmanager.hpp"
|
||||
const int SCENE_NUM = 4;
|
||||
#define MARGEERR 0.25f
|
||||
#define MARGEERR 0.2f
|
||||
#define BLACKVALUE 0.4f
|
||||
#define W_WIDTH 1024
|
||||
|
||||
#define UTC (0)
|
||||
#define W_HEIGHT 768
|
||||
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};
|
||||
}
|
||||
|
||||
namespace DefenseResult {
|
||||
enum defenseResult{nothing = 0, success = 1, fail = 2};
|
||||
}
|
||||
|
||||
#endif // COMMONS_HPP
|
||||
|
|
|
@ -9,7 +9,7 @@ Compas::Compas() {
|
|||
void Compas::start() {
|
||||
failed = false;
|
||||
if (not isPress) {
|
||||
// //std::cout << "start" << std::endl;
|
||||
// std::cout << "start" << std::endl;
|
||||
isPress = true;
|
||||
spaceTime = 1;
|
||||
notes = std::vector<int>();
|
||||
|
@ -20,16 +20,16 @@ void Compas::add() {
|
|||
if (isPress) {
|
||||
notes.push_back(spaceTime);
|
||||
spaceTime = 1;
|
||||
// //std::cout << "add" << std::endl;
|
||||
// std::cout << "add" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Compas::end() {
|
||||
if (isPress) {
|
||||
isPress = false;
|
||||
// //std::cout << "end" << std::endl;
|
||||
// std::cout << "end" << std::endl;
|
||||
// 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();
|
||||
}
|
||||
|
||||
void Compas::incraeseTime() {
|
||||
void Compas::increaseTime() {
|
||||
++spaceTime;
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,17 @@ bool Compas::isFailed() const {
|
|||
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
|
||||
{
|
||||
return notes;
|
||||
|
|
|
@ -12,18 +12,19 @@ private:
|
|||
bool failed;
|
||||
int spaceTime;
|
||||
std::vector<int> notes;
|
||||
int get(int i) const;
|
||||
int size() const;
|
||||
|
||||
public:
|
||||
Compas();
|
||||
int get(int i) const;
|
||||
int size() const;
|
||||
void start();
|
||||
void add();
|
||||
void end();
|
||||
void fail();
|
||||
void incraeseTime();
|
||||
void increaseTime();
|
||||
bool isPressed() const;
|
||||
bool isFailed() const;
|
||||
bool check(int note);
|
||||
bool operator ==(const Compas& d) const;
|
||||
const std::vector<int> &getNotes() const;
|
||||
};
|
||||
|
|
|
@ -20,17 +20,15 @@ Game* Game::i() {
|
|||
// Main game loop
|
||||
void Game::run() {
|
||||
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.setKeyRepeatEnabled(false);
|
||||
|
||||
|
||||
float oldTime = c.getElapsedTime().asSeconds();
|
||||
while (isRunning) {
|
||||
float time = c.getElapsedTime().asSeconds();
|
||||
float deltaTime = time-oldTime;
|
||||
oldTime = time;
|
||||
////std::cout << deltaTime << std::endl;
|
||||
//std::cout << deltaTime << std::endl;
|
||||
update(deltaTime, &window);
|
||||
draw( &window);
|
||||
}
|
||||
|
|
|
@ -8,3 +8,5 @@ bool IaEnemy::updateLogic(float deltaTime, sf::RenderWindow *window) {
|
|||
}
|
||||
|
||||
bool IaEnemy::event(sf::Event e) {return false;}
|
||||
|
||||
DefenseResult::defenseResult IaEnemy::event(sf::Event e, int note) {return DefenseResult::fail;}
|
||||
|
|
|
@ -8,6 +8,7 @@ public:
|
|||
IaEnemy();
|
||||
IaEnemy(int player);
|
||||
bool event(sf::Event e) final override;
|
||||
DefenseResult::defenseResult event(sf::Event e, int note) final override;
|
||||
protected:
|
||||
bool updateLogic(float deltaTime, sf::RenderWindow *window);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ Menu::Menu() {
|
|||
void Menu::update(float deltaTime, sf::RenderWindow*window){
|
||||
//float dx = InputManager::action(InputAction::moveX0);
|
||||
//_buttons[0]->move(dx,0);
|
||||
////std::cout << dx << std::endl;
|
||||
//std::cout << dx << std::endl;
|
||||
for(unsigned int i = 0; i < _buttons.size(); ++i){
|
||||
_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){
|
||||
// //std::cout << "update menu buttons" << std::endl;
|
||||
// std::cout << "update menu buttons" << std::endl;
|
||||
for(unsigned int i = 0; i < _buttons.size(); ++i){
|
||||
_buttons[i]->handleMouseEvent(e);
|
||||
}
|
||||
MyGame* g = static_cast<MyGame*>(Game::i());
|
||||
if (_start.getClicks() > 0){
|
||||
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;
|
||||
|
||||
|
|
|
@ -8,8 +8,9 @@ MyGame::MyGame() {
|
|||
_scenes[GameScene::inGame] = _combat;
|
||||
_scenes[GameScene::help] = _menu;
|
||||
_scenes[GameScene::credits] = _menu;
|
||||
//std::cout << "in menu" << std::endl;
|
||||
std::cout << "in menu" << std::endl;
|
||||
SoundManager::load();
|
||||
SoundManager::setGlobalSoundVolumen(50);
|
||||
SoundManager::setLoop(true, "intro");
|
||||
SoundManager::playMusic("intro");
|
||||
}
|
||||
|
@ -30,7 +31,6 @@ void MyGame::changeScene(GameScene::gameScene n){
|
|||
_combat = new Combat;
|
||||
_scenes[_scene] = _combat;
|
||||
SoundManager::setLoop(true, "clicks");
|
||||
SoundManager::setVolume(85,"clicks");
|
||||
SoundManager::playMusic("clicks");
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ void MyGame::changeScene(GameScene::gameScene n){
|
|||
|
||||
// Main game loop
|
||||
void MyGame::update(float deltaTime, sf::RenderWindow*window) {
|
||||
// //std::cout << deltaTime << std::endl;
|
||||
// std::cout << deltaTime << std::endl;
|
||||
sf::Event event;
|
||||
while(window->pollEvent(event)){
|
||||
switch (event.type) {
|
||||
|
@ -56,7 +56,7 @@ void MyGame::update(float deltaTime, sf::RenderWindow*window) {
|
|||
|
||||
switch(_scene){
|
||||
case(GameScene::menu):
|
||||
////std::cout << "still in menu" << std::endl;
|
||||
//std::cout << "still in menu" << std::endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -4,26 +4,20 @@ Player::Player(int num) : Actor(num) {
|
|||
compas = Compas();
|
||||
error = false;
|
||||
time = 0;
|
||||
mod = false;
|
||||
}
|
||||
|
||||
Player::Player() : Actor() {
|
||||
compas = Compas();
|
||||
error = false;
|
||||
time = 0;
|
||||
mod = false;
|
||||
}
|
||||
|
||||
bool Player::updateLogic(float deltaTime, sf::RenderWindow *window) {
|
||||
time += deltaTime;
|
||||
clock += deltaTime;
|
||||
if (time > BLACKVALUE) {
|
||||
compas.incraeseTime();
|
||||
compas.increaseTime();
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -31,11 +25,9 @@ bool Player::event(sf::Event e) {
|
|||
switch(e.type) {
|
||||
case (sf::Event::KeyPressed):
|
||||
if(e.key.code == sf::Keyboard::C) {
|
||||
|
||||
std::string sample = "mod"+std::to_string(rand()%4+1);
|
||||
if(!mod) sample = "note"+std::to_string(rand()%4+1);
|
||||
std::string sample = "note"+std::to_string(rand()%4+1);
|
||||
SoundManager::playSound(sample);
|
||||
//std::cout << "playing sample " << sample << std::endl;
|
||||
std::cout << "playing sample " << sample << std::endl;
|
||||
compas.start();
|
||||
error = false;
|
||||
}
|
||||
|
@ -65,3 +57,44 @@ bool Player::event(sf::Event e) {
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -9,13 +9,13 @@ public:
|
|||
Player();
|
||||
Player(int num);
|
||||
bool event(sf::Event e) final override;
|
||||
DefenseResult::defenseResult event(sf::Event e, int note) final override;
|
||||
protected:
|
||||
bool updateLogic(float deltaTime, sf::RenderWindow *window);
|
||||
|
||||
private:
|
||||
float time;
|
||||
bool error;
|
||||
bool mod;
|
||||
float clock = 0.0;
|
||||
};
|
||||
|
||||
#endif // PLAYER_H
|
||||
|
|