background
This commit is contained in:
parent
96d80e1c4b
commit
d9d2deab51
6 changed files with 37 additions and 36 deletions
|
@ -3,11 +3,14 @@
|
||||||
Actor::Actor() {}
|
Actor::Actor() {}
|
||||||
|
|
||||||
void Actor::draw(sf::RenderWindow *window) {
|
void Actor::draw(sf::RenderWindow *window) {
|
||||||
|
window->draw(character);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Actor::update(float deltaTime, sf::RenderWindow *window) {
|
bool Actor::update(float deltaTime, sf::RenderWindow *window) {
|
||||||
character.update(deltaTime);
|
character.update(deltaTime);
|
||||||
|
if (animate) {
|
||||||
|
character.setState(PlayerState::attacking);
|
||||||
|
animate = false;
|
||||||
|
}
|
||||||
return this->updateLogic(deltaTime, window);
|
return this->updateLogic(deltaTime, window);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,36 @@
|
||||||
#include "character.hpp"
|
#include "character.hpp"
|
||||||
|
|
||||||
Character::Character(){
|
Character::Character(){
|
||||||
|
sf::Texture texture;
|
||||||
ASSERT(texture.loadFromFile(spriteFile));
|
ASSERT(texture.loadFromFile(spriteFile));
|
||||||
height = texture.getSize().y/5;
|
height = texture.getSize().y;
|
||||||
width = texture.getSize().x/5;
|
width = texture.getSize().x;
|
||||||
next = timestamp = indexX = indexY = 0;
|
next = 0;
|
||||||
setTexture(texture);
|
setTexture(texture);
|
||||||
sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height);
|
|
||||||
setTextureRect(rect);
|
|
||||||
actualState = previousState = PlayerState::idle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::update(float deltaTime){
|
void Character::update(float deltaTime){
|
||||||
timestamp += deltaTime;
|
timestamp += deltaTime;
|
||||||
if (timestamp >= frameTime){
|
if (timestamp >= frameTime){
|
||||||
timestamp = 0;
|
timestamp = 0;
|
||||||
|
if (actualState == previousState){
|
||||||
if (actualState == PlayerState::attacking and indexX >= 3){
|
if (actualState == PlayerState::idle){
|
||||||
actualState = PlayerState::idle;
|
indexX = (indexX+1)%numFrames;
|
||||||
indexX = 0;
|
}
|
||||||
|
else if (actualState == PlayerState::attacking){
|
||||||
|
if (indexX == width){
|
||||||
|
indexX = 0;
|
||||||
|
actualState = PlayerState::idle;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
indexX = (indexX+1)%4;
|
indexX = 0;
|
||||||
|
if (actualState == PlayerState::idle)
|
||||||
|
actualState = PlayerState::attacking;
|
||||||
|
|
||||||
|
else if (actualState == PlayerState::attacking)
|
||||||
|
actualState = PlayerState::idle;
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height);
|
sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height);
|
||||||
|
@ -29,16 +38,3 @@ void Character::update(float deltaTime){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::setState(PlayerState::playerState state){
|
|
||||||
previousState = actualState;
|
|
||||||
actualState = state;
|
|
||||||
if (state == PlayerState::idle){
|
|
||||||
indexX = 0;
|
|
||||||
indexY = 0;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
indexX = 0;
|
|
||||||
indexY = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -11,20 +11,21 @@ Combat::Combat(bool ia) {
|
||||||
playerOneTurn = true;
|
playerOneTurn = true;
|
||||||
if (ia) enemy = new IaEnemy();
|
if (ia) enemy = new IaEnemy();
|
||||||
else enemy = new Player();
|
else enemy = new Player();
|
||||||
initShader();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Combat::initShader() {
|
void Combat::initShader() {
|
||||||
|
time = 0;
|
||||||
_text.create(W_WIDTH, W_HEIGHT);
|
_text.create(W_WIDTH, W_HEIGHT);
|
||||||
_background.setTexture(_text);
|
_background.setTexture(_text);
|
||||||
_shader.loadFromFile("./resources/shader.frag", sf::Shader::Fragment);
|
_shader.loadFromFile("./Resources/shader.frag", sf::Shader::Fragment);
|
||||||
_shader.setParameter("resolution", sf::Vector2f(W_WIDTH, W_HEIGHT));
|
_shader.setParameter("resolution", sf::Vector2f(W_WIDTH, W_HEIGHT));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Combat::update(float deltaTime, sf::RenderWindow *window) {
|
void Combat::update(float deltaTime, sf::RenderWindow *window) {
|
||||||
if (playerOneTurn) player.update(deltaTime, window);
|
if (playerOneTurn) player.update(deltaTime, window);
|
||||||
else if (ia) playerOneTurn = enemy->update(deltaTime, window);
|
else if (ia) playerOneTurn = enemy->update(deltaTime, window);
|
||||||
_shader.setParameter("time", deltaTime);
|
time += deltaTime;
|
||||||
|
_shader.setParameter("time", time);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Combat::draw(sf::RenderWindow *window) {
|
void Combat::draw(sf::RenderWindow *window) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ private:
|
||||||
bool playerOneTurn, ia;
|
bool playerOneTurn, ia;
|
||||||
Player player;
|
Player player;
|
||||||
Actor *enemy;
|
Actor *enemy;
|
||||||
|
float time;
|
||||||
sf::Texture _text;
|
sf::Texture _text;
|
||||||
sf::Sprite _background;
|
sf::Sprite _background;
|
||||||
sf::Shader _shader;
|
sf::Shader _shader;
|
||||||
|
|
|
@ -7,7 +7,7 @@ Compas::Compas() {
|
||||||
|
|
||||||
void Compas::start() {
|
void Compas::start() {
|
||||||
if (not isPress) {
|
if (not isPress) {
|
||||||
std::cout << "start" << std::endl;
|
// std::cout << "start" << std::endl;
|
||||||
isPress = true;
|
isPress = true;
|
||||||
spaceTime = 1;
|
spaceTime = 1;
|
||||||
notes = std::vector<int>();
|
notes = std::vector<int>();
|
||||||
|
@ -18,17 +18,17 @@ void Compas::add() {
|
||||||
if (isPress) {
|
if (isPress) {
|
||||||
notes.push_back(spaceTime);
|
notes.push_back(spaceTime);
|
||||||
spaceTime = 1;
|
spaceTime = 1;
|
||||||
std::cout << "add" << std::endl;
|
// std::cout << "add" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ void MyGame::update(float deltaTime, sf::RenderWindow*window) {
|
||||||
|
|
||||||
void MyGame::draw(sf::RenderWindow*window) {
|
void MyGame::draw(sf::RenderWindow*window) {
|
||||||
//a e s t h e t i c s
|
//a e s t h e t i c s
|
||||||
window->clear(sf::Color::Cyan);
|
window->clear(sf::Color::Black);
|
||||||
// draw shit
|
// draw shit
|
||||||
_scenes[_scene]->draw(window);
|
_scenes[_scene]->draw(window);
|
||||||
window->display();
|
window->display();
|
||||||
|
|
Reference in a new issue