score
This commit is contained in:
parent
3b3aca7549
commit
777384e51e
7 changed files with 88 additions and 21 deletions
|
@ -16,7 +16,8 @@ SOURCES += main.cpp \
|
||||||
player.cpp \
|
player.cpp \
|
||||||
iaenemy.cpp \
|
iaenemy.cpp \
|
||||||
actor.cpp \
|
actor.cpp \
|
||||||
soundmanager.cpp
|
soundmanager.cpp \
|
||||||
|
score.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
game.hpp \
|
game.hpp \
|
||||||
|
@ -31,4 +32,5 @@ HEADERS += \
|
||||||
player.hpp \
|
player.hpp \
|
||||||
iaenemy.hpp \
|
iaenemy.hpp \
|
||||||
actor.hpp \
|
actor.hpp \
|
||||||
soundmanager.hpp
|
soundmanager.hpp \
|
||||||
|
score.hpp
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
#include "actor.hpp"
|
#include "actor.hpp"
|
||||||
Actor::Actor() {
|
Actor::Actor() {
|
||||||
score = 0;
|
|
||||||
animate = PlayerState::attacking;
|
animate = PlayerState::attacking;
|
||||||
this->character = new Character(0);
|
this->character = new Character(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Actor::Actor(int num) {
|
Actor::Actor(int num) {
|
||||||
score = 0;
|
|
||||||
animate = PlayerState::attacking;
|
animate = PlayerState::attacking;
|
||||||
this->character = new Character(num);
|
this->character = new Character(num);
|
||||||
}
|
}
|
||||||
|
@ -36,11 +34,3 @@ bool Actor::hitBy(Compas enemy) const {
|
||||||
Compas Actor::getAttack() const {
|
Compas Actor::getAttack() const {
|
||||||
return compas;
|
return compas;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actor::upScore() {
|
|
||||||
++score;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Actor::getScore() const {
|
|
||||||
return score;
|
|
||||||
}
|
|
||||||
|
|
|
@ -15,10 +15,8 @@ public:
|
||||||
bool hitBy(Compas enemy) const;
|
bool hitBy(Compas enemy) const;
|
||||||
Compas getAttack() const;
|
Compas getAttack() const;
|
||||||
virtual bool event(sf::Event e) = 0;
|
virtual bool event(sf::Event e) = 0;
|
||||||
void upScore();
|
|
||||||
int getScore() const;
|
|
||||||
protected:
|
protected:
|
||||||
int score;
|
|
||||||
Compas compas;
|
Compas compas;
|
||||||
PlayerState::playerState animate;
|
PlayerState::playerState animate;
|
||||||
virtual bool updateLogic(float deltaTime, sf::RenderWindow *window) = 0;
|
virtual bool updateLogic(float deltaTime, sf::RenderWindow *window) = 0;
|
||||||
|
|
|
@ -44,8 +44,8 @@ void Combat::draw(sf::RenderWindow *window) {
|
||||||
window->draw(_background, &_shader);
|
window->draw(_background, &_shader);
|
||||||
player->draw(window);
|
player->draw(window);
|
||||||
enemy->draw(window);
|
enemy->draw(window);
|
||||||
window->draw(*scorePlayer);
|
scorePlayer->draw(window);
|
||||||
window->draw(*scoreEnemy);
|
scoreEnemy->draw(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Combat::updateEvents(sf::Event e) {
|
void Combat::updateEvents(sf::Event e) {
|
||||||
|
@ -54,8 +54,7 @@ void Combat::updateEvents(sf::Event e) {
|
||||||
if (!aux) { //end of player one ritm
|
if (!aux) { //end of player one ritm
|
||||||
if (!attacking) {
|
if (!attacking) {
|
||||||
if(!player->hitBy(enemy->getAttack())) {
|
if(!player->hitBy(enemy->getAttack())) {
|
||||||
enemy->upScore();
|
scoreEnemy->incrisScore();
|
||||||
scoreEnemy->setScore(enemy->getScore());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else playerOneTurn = aux;
|
else playerOneTurn = aux;
|
||||||
|
@ -72,8 +71,7 @@ void Combat::enemyManager(bool aux) {
|
||||||
if (aux) {
|
if (aux) {
|
||||||
if (!attacking) {
|
if (!attacking) {
|
||||||
if(!enemy->hitBy(player->getAttack())) {
|
if(!enemy->hitBy(player->getAttack())) {
|
||||||
player->upScore();
|
scorePlayer->incrisScore();
|
||||||
scorePlayer->setScore(player->getScore());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else playerOneTurn = aux;
|
else playerOneTurn = aux;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "iaenemy.hpp"
|
#include "iaenemy.hpp"
|
||||||
#include "actor.hpp"
|
#include "actor.hpp"
|
||||||
#include "soundmanager.hpp"
|
#include "soundmanager.hpp"
|
||||||
|
#include "score.hpp"
|
||||||
|
|
||||||
class Combat : public Scene {
|
class Combat : public Scene {
|
||||||
public:
|
public:
|
||||||
|
@ -29,6 +30,7 @@ private:
|
||||||
sf::Sprite _background;
|
sf::Sprite _background;
|
||||||
sf::Shader _shader;
|
sf::Shader _shader;
|
||||||
|
|
||||||
|
Score *scoreEnemy, *scorePlayer;
|
||||||
void initShader();
|
void initShader();
|
||||||
void enemyManager(bool aux);
|
void enemyManager(bool aux);
|
||||||
};
|
};
|
||||||
|
|
56
VaporWaveWars/score.cpp
Normal file
56
VaporWaveWars/score.cpp
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
#include "score.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
Score::Score() {
|
||||||
|
ASSERT(_texture.loadFromFile(_spriteFile));
|
||||||
|
_scoreSprite.push_back(sf::Sprite());
|
||||||
|
_scoreSprite[0].setTexture(_texture);
|
||||||
|
_score = 0;
|
||||||
|
setScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Score::Score(int num) : Score() {
|
||||||
|
if (num == 0) {
|
||||||
|
_posX = 100;
|
||||||
|
_posY = 50;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_posX = 600;
|
||||||
|
_posY = 50;
|
||||||
|
}
|
||||||
|
_scoreSprite[0].setPosition(_posX, _posY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Score::draw(sf::RenderWindow *window){
|
||||||
|
for (int i = 0; i < _scoreSprite.size(); ++i)
|
||||||
|
window->draw(_scoreSprite[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Score::incrisScore() {
|
||||||
|
++_score;
|
||||||
|
setScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Score::setScore() {
|
||||||
|
int height = _texture.getSize().y;
|
||||||
|
int width = _texture.getSize().x/10;
|
||||||
|
int s = _score;
|
||||||
|
for (int i = 0; i < _scoreSprite.size(); ++i) {
|
||||||
|
int num = s%10;
|
||||||
|
s = s/10;
|
||||||
|
sf::IntRect rect = sf::IntRect(num*width, 0, width, height);
|
||||||
|
_scoreSprite[i].setTextureRect(rect);
|
||||||
|
}
|
||||||
|
while (s > 0) {
|
||||||
|
int num = s%10;
|
||||||
|
s = s/10;
|
||||||
|
_scoreSprite.push_back(sf::Sprite());
|
||||||
|
int i = _scoreSprite.size() - 1;
|
||||||
|
_scoreSprite[i].setTexture(_texture);
|
||||||
|
sf::IntRect rect = sf::IntRect(num*width, 0, width, height);
|
||||||
|
_scoreSprite[i].setTextureRect(rect);
|
||||||
|
_scoreSprite[i].setPosition(_posX-(width*i),_posY);
|
||||||
|
}
|
||||||
|
}
|
21
VaporWaveWars/score.hpp
Normal file
21
VaporWaveWars/score.hpp
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef SCORE_H
|
||||||
|
#define SCORE_H
|
||||||
|
|
||||||
|
#include "commons.hpp"
|
||||||
|
|
||||||
|
class Score {
|
||||||
|
public:
|
||||||
|
Score();
|
||||||
|
Score(int num);
|
||||||
|
void draw(sf::RenderWindow *window);
|
||||||
|
void incrisScore();
|
||||||
|
private:
|
||||||
|
std::vector<sf::Sprite> _scoreSprite;
|
||||||
|
sf::Texture _texture;
|
||||||
|
const std::string _spriteFile = WORK_DIR+"Resources/numbers-spreadsheet.png";
|
||||||
|
int _score;
|
||||||
|
int _posX, _posY;
|
||||||
|
void setScore();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SCORE_H
|
Reference in a new issue