This repository has been archived on 2022-12-14. You can view files and clone it, but cannot push or open issues or pull requests.
WaveGGJ17/VaporWaveWars/combat.cpp
2017-01-21 17:58:55 +01:00

81 lines
2.1 KiB
C++

#include "combat.hpp"
Combat::Combat() {
ia = false;
// ia = true;
attacking = playerOneTurn = true;
player = new Player(0);
// enemy = new IaEnemy(1);
enemy = new Player(1);
scorePlayer = new Score(0);
scoreEnemy = new Score(1);
initShader();
SoundManager::load();
SoundManager::playMusic("music");
}
Combat::Combat(bool ia) {
this->ia = ia;
player = new Player(0);
attacking = playerOneTurn = true;
if (ia) enemy = new IaEnemy(1);
else enemy = new Player(1);
initShader();
}
void Combat::initShader() {
time = 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));
}
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 ritm
time += deltaTime;
_shader.setParameter("time", time);
}
void Combat::draw(sf::RenderWindow *window) {
window->draw(_background, &_shader);
player->draw(window);
enemy->draw(window);
scorePlayer->draw(window);
scoreEnemy->draw(window);
}
void Combat::updateEvents(sf::Event e) {
if (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) {
bool aux = !enemy->event(e, !attacking);
enemyManager(aux); //end of player two not ia ritm
}
}
void Combat::enemyManager(bool aux) {
if (aux) {
if (!attacking) {
if(!enemy->hitBy(player->getAttack())) {
scorePlayer->incrisScore();
}
}
else playerOneTurn = aux;
attacking = !attacking;
}
}