From cefe66cdbb8786dc455657376e36f0ff8785d5bc Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 8 Feb 2018 12:34:42 -0500 Subject: Introduced animated sprites Also restyled a lot of the code. --- src/game.cpp | 73 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 30 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index 5d1ec18..492e4d0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -4,40 +4,59 @@ #include "components/controllable.h" #include "components/droppable.h" #include "components/ponderable.h" +#include "components/orientable.h" #include "systems/rendering.h" #include "systems/controlling.h" #include "systems/pondering.h" +#include "systems/animating.h" +#include "animation.h" void key_callback(GLFWwindow* window, int key, int, int action, int) { Game& game = *((Game*) glfwGetWindowUserPointer(window)); - + if ((action == GLFW_PRESS) && (key == GLFW_KEY_ESCAPE)) { - game.shouldQuit = true; - + game.shouldQuit_ = true; + return; } - - game.systemManager.getSystem().input(key, action); + + game.systemManager_.getSystem().input(key, action); } -Game::Game(GLFWwindow* window) : window(window) +Game::Game(GLFWwindow* window) : window_(window) { - systemManager.emplaceSystem(*this); - systemManager.emplaceSystem(*this); - systemManager.emplaceSystem(*this); - - int player = entityManager.emplaceEntity(); - entityManager.emplaceComponent(player, "res/Starla.png", 10, 12, 6); - entityManager.emplaceComponent(player, 203, 44, 10, 12); - entityManager.emplaceComponent(player); - entityManager.emplaceComponent(player); - entityManager.emplaceComponent(player); - + systemManager_.emplaceSystem(*this); + systemManager_.emplaceSystem(*this); + systemManager_.emplaceSystem(*this); + systemManager_.emplaceSystem(*this); + + int player = entityManager_.emplaceEntity(); + + AnimationSet playerGraphics {"res/Starla2.bmp", 10, 12, 6}; + playerGraphics.emplaceAnimation("stillLeft", 3, 1, 1); + playerGraphics.emplaceAnimation("stillRight", 0, 1, 1); + playerGraphics.emplaceAnimation("walkingLeft", 4, 2, 10); + playerGraphics.emplaceAnimation("walkingRight", 1, 2, 10); + + entityManager_.emplaceComponent( + player, + std::move(playerGraphics), + "stillLeft"); + + entityManager_.emplaceComponent( + player, + 203, 44, 10, 12); + + entityManager_.emplaceComponent(player); + entityManager_.emplaceComponent(player); + entityManager_.emplaceComponent(player); + entityManager_.emplaceComponent(player); + glfwSwapInterval(1); - glfwSetWindowUserPointer(window, this); - glfwSetKeyCallback(window, key_callback); + glfwSetWindowUserPointer(window_, this); + glfwSetKeyCallback(window_, key_callback); } void Game::execute() @@ -46,7 +65,7 @@ void Game::execute() const double dt = 0.01; double accumulator = 0.0; - while (!(shouldQuit || glfwWindowShouldClose(window))) + while (!(shouldQuit_ || glfwWindowShouldClose(window_))) { double currentTime = glfwGetTime(); double frameTime = currentTime - lastTime; @@ -57,19 +76,13 @@ void Game::execute() accumulator += frameTime; while (accumulator >= dt) { - systemManager.getSystem().tick(dt); - systemManager.getSystem().tick(dt); + systemManager_.getSystem().tick(dt); + systemManager_.getSystem().tick(dt); + systemManager_.getSystem().tick(dt); accumulator -= dt; } - systemManager.getSystem().tick(frameTime); + systemManager_.getSystem().tick(frameTime); } } - -EntityManager& Game::getEntityManager() -{ - return entityManager; -} - - -- cgit 1.4.1