Merge branch 'master' of github.com:ralucado/WaveGGJ17
This commit is contained in:
commit
c53d63b45b
7 changed files with 94 additions and 47 deletions
|
@ -30,14 +30,14 @@ bool Actor::update(float deltaTime, sf::RenderWindow *window) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Actor::hitBy(Compas enemy) {
|
bool Actor::hitBy(Compas enemy) {
|
||||||
bool hit = enemy == compas;
|
bool dodge = enemy == compas;
|
||||||
if (hit) std::cout << "dodge" << std::endl;
|
if (dodge) std::cout << "dodge" << std::endl;
|
||||||
else std::cout << "hit" << std::endl;
|
else std::cout << "hit" << std::endl;
|
||||||
if (!hit) {
|
if (!dodge) {
|
||||||
character->setState(PlayerState::hurt);
|
character->setState(PlayerState::hurt);
|
||||||
animate = PlayerState::inMidle;
|
animate = PlayerState::hurt;
|
||||||
}
|
}
|
||||||
return hit;
|
return dodge;
|
||||||
}
|
}
|
||||||
|
|
||||||
Compas Actor::getAttack() const {
|
Compas Actor::getAttack() const {
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
Combat::Combat() {
|
Combat::Combat() {
|
||||||
ia = false;
|
ia = false;
|
||||||
// ia = true;
|
// ia = true;
|
||||||
attacking = playerOneTurn = true;
|
state = CombatState::player_atk;
|
||||||
player = new Player(0);
|
player = new Player(0);
|
||||||
// enemy = new IaEnemy(1);
|
// enemy = new IaEnemy(1);
|
||||||
enemy = new Player(1);
|
enemy = new Player(1);
|
||||||
|
@ -29,12 +29,38 @@ Combat::~Combat(){
|
||||||
Combat::Combat(bool ia) {
|
Combat::Combat(bool ia) {
|
||||||
this->ia = ia;
|
this->ia = ia;
|
||||||
player = new Player(0);
|
player = new Player(0);
|
||||||
attacking = playerOneTurn = true;
|
state = CombatState::player_atk;
|
||||||
if (ia) enemy = new IaEnemy(1);
|
if (ia) enemy = new IaEnemy(1);
|
||||||
else enemy = new Player(1);
|
else enemy = new Player(1);
|
||||||
initShader();
|
initShader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Combat::isAttack() const {
|
||||||
|
return state == CombatState::player_atk or state == CombatState::enemy_atk;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Combat::isPlayerOne() const {
|
||||||
|
return state == CombatState::player_def or state == CombatState::player_atk;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Combat::updateHalo() {
|
||||||
|
switch(state) {
|
||||||
|
case CombatState::player_def:
|
||||||
|
case CombatState::enemy_def:
|
||||||
|
_shaderHalo.setParameter("type", 0.0f);
|
||||||
|
break;
|
||||||
|
case CombatState::enemy_atk:
|
||||||
|
_shaderHalo.setParameter("type", 1.0f);
|
||||||
|
break;
|
||||||
|
case CombatState::player_atk:
|
||||||
|
_shaderHalo.setParameter("type", 2.0f);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Combat::initShader() {
|
void Combat::initShader() {
|
||||||
time = 0;
|
time = 0;
|
||||||
_text.create(W_WIDTH, W_HEIGHT);
|
_text.create(W_WIDTH, W_HEIGHT);
|
||||||
|
@ -53,9 +79,8 @@ void Combat::initShader() {
|
||||||
sf::IntRect rect = sf::IntRect(0, 0, _plataformT.getSize().x/2, _plataformT.getSize().y);
|
sf::IntRect rect = sf::IntRect(0, 0, _plataformT.getSize().x/2, _plataformT.getSize().y);
|
||||||
_plataform.setTextureRect(rect);
|
_plataform.setTextureRect(rect);
|
||||||
_shaderHalo.loadFromFile(WORK_DIR+"Resources/halo.frag", sf::Shader::Fragment);
|
_shaderHalo.loadFromFile(WORK_DIR+"Resources/halo.frag", sf::Shader::Fragment);
|
||||||
_shaderHalo.setParameter("type", 0.0f);
|
|
||||||
_shaderHalo.setParameter("time", time);
|
_shaderHalo.setParameter("time", time);
|
||||||
|
updateHalo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Combat::update(float deltaTime, sf::RenderWindow *window) {
|
void Combat::update(float deltaTime, sf::RenderWindow *window) {
|
||||||
|
@ -78,7 +103,7 @@ void Combat::update(float deltaTime, sf::RenderWindow *window) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (playerOneTurn) {
|
if (isPlayerOne()) {
|
||||||
if(_halo.getPosition().x != W_WIDTH*0.05f)
|
if(_halo.getPosition().x != W_WIDTH*0.05f)
|
||||||
toEnemy = false;
|
toEnemy = false;
|
||||||
}
|
}
|
||||||
|
@ -87,14 +112,12 @@ void Combat::update(float deltaTime, sf::RenderWindow *window) {
|
||||||
toEnemy = true;
|
toEnemy = true;
|
||||||
}
|
}
|
||||||
animationTo(toEnemy, deltaTime);
|
animationTo(toEnemy, deltaTime);
|
||||||
if (!attacking) _shaderHalo.setParameter("type", 0.0f);
|
|
||||||
else {
|
updateHalo();
|
||||||
if (playerOneTurn)_shaderHalo.setParameter("type", 2.0f);
|
|
||||||
else _shaderHalo.setParameter("type", 1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
sf::IntRect rect;
|
sf::IntRect rect;
|
||||||
if (playerOneTurn)
|
if (isPlayerOne())
|
||||||
rect = sf::IntRect(0, 0, _plataformT.getSize().x/2, _plataformT.getSize().y);
|
rect = sf::IntRect(0, 0, _plataformT.getSize().x/2, _plataformT.getSize().y);
|
||||||
else
|
else
|
||||||
rect = sf::IntRect(_plataformT.getSize().x/2, 0, _plataformT.getSize().x/2, _plataformT.getSize().y);
|
rect = sf::IntRect(_plataformT.getSize().x/2, 0, _plataformT.getSize().x/2, _plataformT.getSize().y);
|
||||||
|
@ -117,43 +140,44 @@ void Combat::draw(sf::RenderWindow *window) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Combat::updateEvents(sf::Event e) {
|
void Combat::updateEvents(sf::Event e) {
|
||||||
if (playerOneTurn) {
|
if (isPlayerOne()) {
|
||||||
if(e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::C && !attacking) doMahWaves(!playerOneTurn);
|
if(e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::C && !attacking) doMahWaves(!playerOneTurn);
|
||||||
_halo.setPosition(W_WIDTH*0.05f, W_HEIGHT*0.5f);
|
bool compasFinish = !player->event(e);
|
||||||
bool aux = player->event(e);
|
enemyManager(compasFinish);
|
||||||
if (!aux) { //end of player one ritm
|
|
||||||
|
|
||||||
if (!attacking && !ia) {
|
|
||||||
if(!player->hitBy(enemy->getAttack())) {
|
|
||||||
scoreEnemy->incrisScore();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else playerOneTurn = aux;
|
|
||||||
attacking = !attacking;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (!ia) {
|
else if (!ia) {
|
||||||
if(e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::C && !attacking) doMahWaves(!playerOneTurn);
|
if(e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::C && !attacking) doMahWaves(!playerOneTurn);
|
||||||
_halo.setPosition(W_WIDTH*0.65f, W_HEIGHT*0.5f);
|
bool compasFinish = !enemy->event(e);
|
||||||
bool aux = !enemy->event(e);
|
enemyManager(compasFinish);
|
||||||
enemyManager(aux); //end of player two not ia ritm
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Combat::enemyManager(bool aux) {
|
void Combat::enemyManager(bool compasFinish) {
|
||||||
if (aux) {
|
if(compasFinish) {
|
||||||
if (!attacking) {
|
Compas compas;
|
||||||
if(!enemy->hitBy(player->getAttack())) {
|
if(isPlayerOne()) compas = enemy->getAttack();
|
||||||
|
else compas = player->getAttack();
|
||||||
|
|
||||||
|
if(!isAttack()) {
|
||||||
|
if(!ia) {
|
||||||
|
bool hit;
|
||||||
|
if(isPlayerOne()) hit = !player->hitBy(compas);
|
||||||
|
else hit = !enemy->hitBy(compas);
|
||||||
|
if(hit) {
|
||||||
|
if(isPlayerOne())
|
||||||
|
scoreEnemy->incrisScore();
|
||||||
|
else
|
||||||
scorePlayer->incrisScore();
|
scorePlayer->incrisScore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else playerOneTurn = aux;
|
}
|
||||||
attacking = !attacking;
|
else if(compas.isFailed())
|
||||||
|
state = (CombatState::combatState) ((((int) state)+1) % 4);
|
||||||
|
state = (CombatState::combatState) ((((int) state)+1) % 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Combat::doMahWaves(bool p){
|
void Combat::doMahWaves(bool p) {
|
||||||
std::cout << "defensa jugador " << p << std::endl;
|
std::cout << "defensa jugador " << p << std::endl;
|
||||||
std::vector<int> notes;
|
std::vector<int> notes;
|
||||||
if(p){
|
if(p){
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "score.hpp"
|
#include "score.hpp"
|
||||||
#include "wave.hpp"
|
#include "wave.hpp"
|
||||||
class Combat : public Scene {
|
class Combat : public Scene {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Combat();
|
Combat();
|
||||||
~Combat();
|
~Combat();
|
||||||
|
@ -26,17 +27,20 @@ class Combat : public Scene {
|
||||||
bool playerOneTurn, ia, attacking, toEnemy;
|
bool playerOneTurn, ia, attacking, toEnemy;
|
||||||
Actor *player, *enemy;
|
Actor *player, *enemy;
|
||||||
float time;
|
float time;
|
||||||
|
CombatState::combatState state;
|
||||||
std::vector<Wave*> waves;
|
std::vector<Wave*> waves;
|
||||||
sf::Texture _text, _haloT, _plataformT, axisT;
|
sf::Texture _text, _haloT, _plataformT, axisT;
|
||||||
sf::Sprite _background, _halo, _plataform, _axis;
|
sf::Sprite _background, _halo, _plataform, _axis;
|
||||||
sf::Shader _shader, _shaderHalo;
|
sf::Shader _shader, _shaderHalo;
|
||||||
|
|
||||||
Score *scoreEnemy, *scorePlayer;
|
Score *scoreEnemy, *scorePlayer;
|
||||||
void initShader();
|
void initShader();
|
||||||
void enemyManager(bool aux);
|
void enemyManager(bool aux);
|
||||||
void doMahWaves(bool p);
|
|
||||||
void animationTo(bool toEnemy, float deltaTime);
|
void animationTo(bool toEnemy, float deltaTime);
|
||||||
|
bool isAttack() const;
|
||||||
|
bool isPlayerOne() const;
|
||||||
|
void updateHalo();
|
||||||
|
void doMahWaves(bool p);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COMBAT_H
|
#endif // COMBAT_H
|
||||||
|
|
|
@ -46,4 +46,8 @@ namespace PlayerState {
|
||||||
enum playerState{idle, attacking, inMidle, hurt, success};
|
enum playerState{idle, attacking, inMidle, hurt, success};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace CombatState {
|
||||||
|
enum combatState{player_def = 0, player_atk = 1, enemy_def = 2, enemy_atk = 3};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // COMMONS_HPP
|
#endif // COMMONS_HPP
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
Compas::Compas() {
|
Compas::Compas() {
|
||||||
spaceTime = 1;
|
spaceTime = 1;
|
||||||
isPress = false;
|
isPress = false;
|
||||||
|
failed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compas::start() {
|
void Compas::start() {
|
||||||
|
failed = false;
|
||||||
if (not isPress) {
|
if (not isPress) {
|
||||||
// std::cout << "start" << std::endl;
|
// std::cout << "start" << std::endl;
|
||||||
isPress = true;
|
isPress = true;
|
||||||
|
@ -32,6 +34,11 @@ void Compas::end() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Compas::fail() {
|
||||||
|
failed = true;
|
||||||
|
end();
|
||||||
|
}
|
||||||
|
|
||||||
void Compas::incraeseTime() {
|
void Compas::incraeseTime() {
|
||||||
++spaceTime;
|
++spaceTime;
|
||||||
}
|
}
|
||||||
|
@ -40,6 +47,10 @@ bool Compas::isPressed() const {
|
||||||
return isPress;
|
return isPress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Compas::isFailed() const {
|
||||||
|
return failed;
|
||||||
|
}
|
||||||
|
|
||||||
const std::vector<int>& Compas::getNotes() const
|
const std::vector<int>& Compas::getNotes() const
|
||||||
{
|
{
|
||||||
return notes;
|
return notes;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
class Compas {
|
class Compas {
|
||||||
private:
|
private:
|
||||||
bool isPress;
|
bool isPress;
|
||||||
|
bool failed;
|
||||||
int spaceTime;
|
int spaceTime;
|
||||||
std::vector<int> notes;
|
std::vector<int> notes;
|
||||||
int get(int i) const;
|
int get(int i) const;
|
||||||
|
@ -19,8 +20,10 @@ public:
|
||||||
void start();
|
void start();
|
||||||
void add();
|
void add();
|
||||||
void end();
|
void end();
|
||||||
|
void fail();
|
||||||
void incraeseTime();
|
void incraeseTime();
|
||||||
bool isPressed() const;
|
bool isPressed() const;
|
||||||
|
bool isFailed() const;
|
||||||
bool operator ==(const Compas& d) const;
|
bool operator ==(const Compas& d) const;
|
||||||
const std::vector<int> &getNotes() const;
|
const std::vector<int> &getNotes() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,15 +38,16 @@ bool Player::event(sf::Event e) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
compas.end();
|
compas.fail();
|
||||||
animate = PlayerState::hurt;
|
animate = PlayerState::hurt;
|
||||||
error = true;
|
error = true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (sf::Event::KeyReleased):
|
case (sf::Event::KeyReleased):
|
||||||
if (e.key.code == sf::Keyboard::C) {
|
if (compas.isPressed() and e.key.code == sf::Keyboard::C) {
|
||||||
compas.end();
|
compas.end();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue