From d9d2deab51516fe6c67d4d47ada516d322b59ce3 Mon Sep 17 00:00:00 2001 From: serk Date: Sat, 21 Jan 2017 05:09:40 +0100 Subject: [PATCH] background --- VaporWaveWars/actor.cpp | 7 ++++-- VaporWaveWars/character.cpp | 44 +++++++++++++++++-------------------- VaporWaveWars/combat.cpp | 7 +++--- VaporWaveWars/combat.hpp | 1 + VaporWaveWars/compas.cpp | 12 +++++----- VaporWaveWars/mygame.cpp | 2 +- 6 files changed, 37 insertions(+), 36 deletions(-) diff --git a/VaporWaveWars/actor.cpp b/VaporWaveWars/actor.cpp index fa28de1..b5ffa03 100644 --- a/VaporWaveWars/actor.cpp +++ b/VaporWaveWars/actor.cpp @@ -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); } diff --git a/VaporWaveWars/character.cpp b/VaporWaveWars/character.cpp index 97c30ea..cf12d83 100644 --- a/VaporWaveWars/character.cpp +++ b/VaporWaveWars/character.cpp @@ -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; - indexX = 0; + 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; - } -} - diff --git a/VaporWaveWars/combat.cpp b/VaporWaveWars/combat.cpp index 71ed72b..262640b 100644 --- a/VaporWaveWars/combat.cpp +++ b/VaporWaveWars/combat.cpp @@ -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) { diff --git a/VaporWaveWars/combat.hpp b/VaporWaveWars/combat.hpp index fd0a6a6..c4b610f 100644 --- a/VaporWaveWars/combat.hpp +++ b/VaporWaveWars/combat.hpp @@ -23,6 +23,7 @@ private: bool playerOneTurn, ia; Player player; Actor *enemy; + float time; sf::Texture _text; sf::Sprite _background; sf::Shader _shader; diff --git a/VaporWaveWars/compas.cpp b/VaporWaveWars/compas.cpp index e6de97c..86bbc4e 100644 --- a/VaporWaveWars/compas.cpp +++ b/VaporWaveWars/compas.cpp @@ -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(); @@ -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; +// } } } diff --git a/VaporWaveWars/mygame.cpp b/VaporWaveWars/mygame.cpp index 2d70b26..6a07b9c 100644 --- a/VaporWaveWars/mygame.cpp +++ b/VaporWaveWars/mygame.cpp @@ -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();