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() {}
|
||||
|
||||
void Actor::draw(sf::RenderWindow *window) {
|
||||
|
||||
window->draw(character);
|
||||
}
|
||||
|
||||
bool Actor::update(float deltaTime, sf::RenderWindow *window) {
|
||||
character.update(deltaTime);
|
||||
|
||||
if (animate) {
|
||||
character.setState(PlayerState::attacking);
|
||||
animate = false;
|
||||
}
|
||||
return this->updateLogic(deltaTime, window);
|
||||
}
|
||||
|
|
|
@ -1,27 +1,36 @@
|
|||
#include "character.hpp"
|
||||
|
||||
Character::Character(){
|
||||
sf::Texture texture;
|
||||
ASSERT(texture.loadFromFile(spriteFile));
|
||||
height = texture.getSize().y/5;
|
||||
width = texture.getSize().x/5;
|
||||
next = timestamp = indexX = indexY = 0;
|
||||
height = texture.getSize().y;
|
||||
width = texture.getSize().x;
|
||||
next = 0;
|
||||
setTexture(texture);
|
||||
sf::IntRect rect = sf::IntRect(indexX*width, indexY*height, width, height);
|
||||
setTextureRect(rect);
|
||||
actualState = previousState = PlayerState::idle;
|
||||
}
|
||||
|
||||
void Character::update(float deltaTime){
|
||||
timestamp += deltaTime;
|
||||
if (timestamp >= frameTime){
|
||||
timestamp = 0;
|
||||
|
||||
if (actualState == PlayerState::attacking and indexX >= 3){
|
||||
actualState = PlayerState::idle;
|
||||
if (actualState == previousState){
|
||||
if (actualState == PlayerState::idle){
|
||||
indexX = (indexX+1)%numFrames;
|
||||
}
|
||||
else if (actualState == PlayerState::attacking){
|
||||
if (indexX == width){
|
||||
indexX = 0;
|
||||
actualState = PlayerState::idle;
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
@ -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;
|
||||
if (ia) enemy = new IaEnemy();
|
||||
else enemy = new Player();
|
||||
initShader();
|
||||
}
|
||||
|
||||
void Combat::initShader() {
|
||||
time = 0;
|
||||
_text.create(W_WIDTH, W_HEIGHT);
|
||||
_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));
|
||||
}
|
||||
|
||||
void Combat::update(float deltaTime, sf::RenderWindow *window) {
|
||||
if (playerOneTurn) player.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) {
|
||||
|
|
|
@ -23,6 +23,7 @@ private:
|
|||
bool playerOneTurn, ia;
|
||||
Player player;
|
||||
Actor *enemy;
|
||||
float time;
|
||||
sf::Texture _text;
|
||||
sf::Sprite _background;
|
||||
sf::Shader _shader;
|
||||
|
|
|
@ -7,7 +7,7 @@ Compas::Compas() {
|
|||
|
||||
void Compas::start() {
|
||||
if (not isPress) {
|
||||
std::cout << "start" << std::endl;
|
||||
// std::cout << "start" << std::endl;
|
||||
isPress = true;
|
||||
spaceTime = 1;
|
||||
notes = std::vector<int>();
|
||||
|
@ -18,17 +18,17 @@ void Compas::add() {
|
|||
if (isPress) {
|
||||
notes.push_back(spaceTime);
|
||||
spaceTime = 1;
|
||||
std::cout << "add" << std::endl;
|
||||
// std::cout << "add" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Compas::end() {
|
||||
if (isPress) {
|
||||
isPress = false;
|
||||
std::cout << "end" << std::endl;
|
||||
for (int i = 0; i < notes.size(); ++i) {
|
||||
std::cout << notes[i] << std::endl;
|
||||
}
|
||||
// std::cout << "end" << std::endl;
|
||||
// for (int i = 0; i < notes.size(); ++i) {
|
||||
// std::cout << notes[i] << std::endl;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ void MyGame::update(float deltaTime, sf::RenderWindow*window) {
|
|||
|
||||
void MyGame::draw(sf::RenderWindow*window) {
|
||||
//a e s t h e t i c s
|
||||
window->clear(sf::Color::Cyan);
|
||||
window->clear(sf::Color::Black);
|
||||
// draw shit
|
||||
_scenes[_scene]->draw(window);
|
||||
window->display();
|
||||
|
|
Reference in a new issue