fix error time

This commit is contained in:
serk 2017-01-21 16:39:02 +01:00
commit 24af73dda2
14 changed files with 45 additions and 15 deletions

BIN
Resources/Sounds/clicks.wav Normal file

Binary file not shown.

View file

@ -19,6 +19,10 @@ bool Actor::update(float deltaTime, sf::RenderWindow *window) {
character->setState(PlayerState::attacking); character->setState(PlayerState::attacking);
animate = PlayerState::inMidle; animate = PlayerState::inMidle;
} }
else if (animate == PlayerState::hurt) {
character->setState(PlayerState::hurt);
animate = PlayerState::inMidle;
}
else if (animate == PlayerState::inMidle) { else if (animate == PlayerState::inMidle) {
if (character->isLastFrame()) animate = PlayerState::idle; if (character->isLastFrame()) animate = PlayerState::idle;
} }

View file

@ -39,6 +39,12 @@ void Character::update(float deltaTime){
setState(PlayerState::idle); setState(PlayerState::idle);
} }
//Acabar automaticament la animacio de hurt
if (actualState == PlayerState::hurt and indexX%4 == 3){
setState(PlayerState::idle);
}
idleFrame = (idleFrame+1)%4; idleFrame = (idleFrame+1)%4;
} }
} }
@ -56,7 +62,8 @@ void Character::setState(PlayerState::playerState state){
SoundManager::playSound(sample); SoundManager::playSound(sample);
std::cout << "playing sample " << sample << std::endl; std::cout << "playing sample " << sample << std::endl;
} }
else if (false /*state == PlayerState::damaged*/){ else if (state == PlayerState::hurt){
std::cout << "i am hurt" << std::endl;
indexX = 0; indexX = 0;
indexY = 2 + magicNumber; indexY = 2 + magicNumber;
} }

View file

@ -10,9 +10,9 @@ Combat::Combat() {
scorePlayer = new Score(0); scorePlayer = new Score(0);
scoreEnemy = new Score(1); scoreEnemy = new Score(1);
initShader(); initShader();
SoundManager::load(); SoundManager::load();
SoundManager::playMusic("music"); SoundManager::playMusic("music");
} }
Combat::Combat(bool ia) { Combat::Combat(bool ia) {
@ -37,6 +37,7 @@ void Combat::update(float deltaTime, sf::RenderWindow *window) {
bool aux = enemy->update(deltaTime, window); bool aux = enemy->update(deltaTime, window);
if (ia) enemyManager(aux); //end of player two ia ritm if (ia) enemyManager(aux); //end of player two ia ritm
time += deltaTime; time += deltaTime;
_shader.setParameter("time", time); _shader.setParameter("time", time);
} }

View file

@ -12,10 +12,10 @@
#include <string> #include <string>
#include "soundmanager.hpp" #include "soundmanager.hpp"
const int SCENE_NUM = 4; const int SCENE_NUM = 4;
#define MARGEERR 0.05f #define MARGEERR 0.2f
#define BLACKVALUE 0.60f #define BLACKVALUE 0.6f
#define W_WIDTH 800 #define W_WIDTH 1024
#define W_HEIGHT 600 #define W_HEIGHT 768
const std::string WORK_DIR(getenv("WORK_DIR")); const std::string WORK_DIR(getenv("WORK_DIR"));
@ -42,7 +42,7 @@ enum gameScene{menu,inGame,help,credits};
} }
namespace PlayerState { namespace PlayerState {
enum playerState{idle, attacking, inMidle}; enum playerState{idle, attacking, inMidle, hurt};
} }
#endif // COMMONS_HPP #endif // COMMONS_HPP

View file

@ -25,10 +25,10 @@ void Compas::add() {
void Compas::end() { void Compas::end() {
if (isPress) { if (isPress) {
isPress = false; isPress = false;
// std::cout << "end" << std::endl; std::cout << "end" << std::endl;
// for (int i = 0; i < notes.size(); ++i) { for (int i = 0; i < notes.size(); ++i) {
// std::cout << notes[i] << std::endl; std::cout << notes[i] << std::endl;
// } }
} }
} }

View file

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

@ -8,6 +8,7 @@ Menu::Menu() {
_exit.turnOn(); _exit.turnOn();
_buttons.push_back(&_start); _buttons.push_back(&_start);
_buttons.push_back(&_exit); _buttons.push_back(&_exit);
} }
void Menu::update(float deltaTime, sf::RenderWindow*window){ void Menu::update(float deltaTime, sf::RenderWindow*window){

View file

@ -10,6 +10,8 @@ MyGame::MyGame() {
_scenes[GameScene::credits] = _menu; _scenes[GameScene::credits] = _menu;
std::cout << "in menu" << std::endl; std::cout << "in menu" << std::endl;
SoundManager::load(); SoundManager::load();
SoundManager::setLoop(true, "intro");
SoundManager::playMusic("intro");
} }
MyGame::~MyGame() { MyGame::~MyGame() {
@ -24,8 +26,11 @@ void MyGame::changeScene(GameScene::gameScene n){
_scene = n; _scene = n;
if(_scenes[_scene] == NULL){ if(_scenes[_scene] == NULL){
if(_scene == GameScene::inGame){ if(_scene == GameScene::inGame){
SoundManager::stopMusic("intro");
_combat = new Combat; _combat = new Combat;
_scenes[_scene] = _combat; _scenes[_scene] = _combat;
SoundManager::setLoop(true, "clicks");
SoundManager::playMusic("clicks");
} }
} }
} }

View file

@ -3,15 +3,21 @@
Player::Player(int num) : Actor(num) { Player::Player(int num) : Actor(num) {
compas = Compas(); compas = Compas();
error = false; error = false;
time = 0;
} }
Player::Player() : Actor() { Player::Player() : Actor() {
compas = Compas(); compas = Compas();
error = false; error = false;
time = 0;
} }
bool Player::updateLogic(float deltaTime, sf::RenderWindow *window) { bool Player::updateLogic(float deltaTime, sf::RenderWindow *window) {
if (deltaTime > BLACKVALUE) compas.incraeseTime(); time += deltaTime;
if (time > BLACKVALUE) {
compas.incraeseTime();
time = 0;
}
return false; return false;
} }
@ -30,6 +36,8 @@ bool Player::event(sf::Event e) {
else { else {
compas.end(); compas.end();
error = true; //weird? error = true; //weird?
if (animate != PlayerState::inMidle) animate = PlayerState::hurt;
} }
} }
break; break;

View file

@ -13,6 +13,7 @@ protected:
bool updateLogic(float deltaTime, sf::RenderWindow *window); bool updateLogic(float deltaTime, sf::RenderWindow *window);
private: private:
float time;
bool error; bool error;
}; };

View file

@ -7,6 +7,8 @@
/* Example: /* Example:
sf::Music SoundManager::overWorldMusic;*/ sf::Music SoundManager::overWorldMusic;*/
sf::Music SoundManager::worldMusic; sf::Music SoundManager::worldMusic;
sf::Music SoundManager::clickTrack;
sf::SoundBuffer SoundManager::atk1; sf::SoundBuffer SoundManager::atk1;
sf::SoundBuffer SoundManager::atk2; sf::SoundBuffer SoundManager::atk2;
sf::SoundBuffer SoundManager::atk3; sf::SoundBuffer SoundManager::atk3;
@ -39,8 +41,8 @@ void SoundManager::load(){
//LOAD HERE YOUR SOUNDS AND MUSIC //LOAD HERE YOUR SOUNDS AND MUSIC
/* Example: */ /* Example: */
musicMap["music"].openFromFile(WORK_DIR+"Resources/Sounds/wave.wav"); musicMap["intro"].openFromFile(WORK_DIR+"Resources/Sounds/intro.wav");
musicMap["clicks"].openFromFile(WORK_DIR+"Resources/Sounds/clicks.wav");
ASSERT(atk1.loadFromFile(WORK_DIR+"Resources/Sounds/Samples/1.wav")); ASSERT(atk1.loadFromFile(WORK_DIR+"Resources/Sounds/Samples/1.wav"));
soundMap["atk1"].setBuffer(atk1); soundMap["atk1"].setBuffer(atk1);
ASSERT(atk2.loadFromFile(WORK_DIR+"Resources/Sounds/Samples/2.wav")); ASSERT(atk2.loadFromFile(WORK_DIR+"Resources/Sounds/Samples/2.wav"));

View file

@ -28,6 +28,7 @@ class SoundManager {
//INITIALIZE YOUR VARIABLES AS STATIC sf::Music or sf::SoundBuffer //INITIALIZE YOUR VARIABLES AS STATIC sf::Music or sf::SoundBuffer
/* Example:*/ /* Example:*/
static sf::Music worldMusic; static sf::Music worldMusic;
static sf::Music clickTrack;
static sf::SoundBuffer atk1; static sf::SoundBuffer atk1;
static sf::SoundBuffer atk2; static sf::SoundBuffer atk2;
static sf::SoundBuffer atk3; static sf::SoundBuffer atk3;