Created
August 9, 2015 05:30
-
-
Save TheOpenDevProject/6d57eba2357dd25bd40d to your computer and use it in GitHub Desktop.
Heh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QCoreApplication> | |
#include <SFML/Graphics.hpp> | |
#include <SFML/Network.hpp> | |
#include <vector> | |
std::vector<sf::Sprite*> getCharacterCryWalk(){ | |
//Load all textures into memory | |
sf::Texture walkState; | |
sf::Texture walkState_2; | |
sf::Texture walkState_3; | |
sf::Texture walkState_4; | |
walkState.loadFromFile("/home/reverseinverse/Documents/GitRepos/RPGNet/SampleClient/assets/character_0/cry/frame_0/walk1_0.png"); | |
walkState_2.loadFromFile("/home/reverseinverse/Documents/GitRepos/RPGNet/SampleClient/assets/character_0/cry/frame_0/walk1_1.png"); | |
walkState_3.loadFromFile("/home/reverseinverse/Documents/GitRepos/RPGNet/SampleClient/assets/character_0/cry/frame_0/walk1_2.png"); | |
walkState_4.loadFromFile("/home/reverseinverse/Documents/GitRepos/RPGNet/SampleClient/assets/character_0/cry/frame_0/walk1_3.png"); | |
std::vector<sf::Sprite*> Character_0; | |
sf::Sprite *State_0 = new sf::Sprite(); | |
State_0->setTexture(walkState); | |
State_0->setTextureRect(sf::IntRect(0,0,76,74)); | |
Character_0.push_back(State_0); | |
sf::Sprite *State_1 = new sf::Sprite(); | |
State_1->setTexture(walkState_2); | |
State_1->setTextureRect(sf::IntRect(0,0,76,74)); | |
Character_0.push_back(State_1); | |
sf::Sprite *State_2 = new sf::Sprite(); | |
State_2->setTexture(walkState_3); | |
State_2->setTextureRect(sf::IntRect(0,0,76,74)); | |
Character_0.push_back(State_2); | |
sf::Sprite *State_3 = new sf::Sprite(); | |
State_3->setTexture(walkState_4); | |
State_3->setTextureRect(sf::IntRect(0,0,76,74)); | |
Character_0.push_back(State_3); | |
return Character_0; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
std::vector<sf::Sprite*> Character_0 = getCharacterCryWalk(); | |
QCoreApplication a(argc, argv); | |
sf::RenderWindow window(sf::VideoMode(1920, 1080), "My window"); | |
sf::Clock animationClock; | |
///////////////////////// | |
int walkCounter = 0; | |
//This is boilerplate code for testing a new map development | |
//Its time to preload all of our Game Assets. | |
while (window.isOpen()) | |
{ | |
sf::Event event; | |
while (window.pollEvent(event)) | |
{ | |
if (event.type == sf::Event::Closed) | |
window.close(); | |
} | |
if(animationClock.getElapsedTime().asMilliseconds() >= 150){ | |
if(walkCounter <= 2){ | |
walkCounter++; | |
}else{ | |
//Reset our walk animation | |
walkCounter = 0; | |
} | |
animationClock.restart(); | |
} | |
window.clear(sf::Color::White); | |
window.draw(*Character_0.at(walkCounter)); | |
window.display(); | |
} | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment