summary refs log tree commit diff stats
path: root/src/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp73
1 files changed, 43 insertions, 30 deletions
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 @@
4#include "components/controllable.h" 4#include "components/controllable.h"
5#include "components/droppable.h" 5#include "components/droppable.h"
6#include "components/ponderable.h" 6#include "components/ponderable.h"
7#include "components/orientable.h"
7#include "systems/rendering.h" 8#include "systems/rendering.h"
8#include "systems/controlling.h" 9#include "systems/controlling.h"
9#include "systems/pondering.h" 10#include "systems/pondering.h"
11#include "systems/animating.h"
12#include "animation.h"
10 13
11void key_callback(GLFWwindow* window, int key, int, int action, int) 14void key_callback(GLFWwindow* window, int key, int, int action, int)
12{ 15{
13 Game& game = *((Game*) glfwGetWindowUserPointer(window)); 16 Game& game = *((Game*) glfwGetWindowUserPointer(window));
14 17
15 if ((action == GLFW_PRESS) && (key == GLFW_KEY_ESCAPE)) 18 if ((action == GLFW_PRESS) && (key == GLFW_KEY_ESCAPE))
16 { 19 {
17 game.shouldQuit = true; 20 game.shouldQuit_ = true;
18 21
19 return; 22 return;
20 } 23 }
21 24
22 game.systemManager.getSystem<ControllingSystem>().input(key, action); 25 game.systemManager_.getSystem<ControllingSystem>().input(key, action);
23} 26}
24 27
25Game::Game(GLFWwindow* window) : window(window) 28Game::Game(GLFWwindow* window) : window_(window)
26{ 29{
27 systemManager.emplaceSystem<ControllingSystem>(*this); 30 systemManager_.emplaceSystem<ControllingSystem>(*this);
28 systemManager.emplaceSystem<RenderingSystem>(*this); 31 systemManager_.emplaceSystem<PonderingSystem>(*this);
29 systemManager.emplaceSystem<PonderingSystem>(*this); 32 systemManager_.emplaceSystem<RenderingSystem>(*this);
30 33 systemManager_.emplaceSystem<AnimatingSystem>(*this);
31 int player = entityManager.emplaceEntity(); 34
32 entityManager.emplaceComponent<AnimatableComponent>(player, "res/Starla.png", 10, 12, 6); 35 int player = entityManager_.emplaceEntity();
33 entityManager.emplaceComponent<TransformableComponent>(player, 203, 44, 10, 12); 36
34 entityManager.emplaceComponent<DroppableComponent>(player); 37 AnimationSet playerGraphics {"res/Starla2.bmp", 10, 12, 6};
35 entityManager.emplaceComponent<PonderableComponent>(player); 38 playerGraphics.emplaceAnimation("stillLeft", 3, 1, 1);
36 entityManager.emplaceComponent<ControllableComponent>(player); 39 playerGraphics.emplaceAnimation("stillRight", 0, 1, 1);
37 40 playerGraphics.emplaceAnimation("walkingLeft", 4, 2, 10);
41 playerGraphics.emplaceAnimation("walkingRight", 1, 2, 10);
42
43 entityManager_.emplaceComponent<AnimatableComponent>(
44 player,
45 std::move(playerGraphics),
46 "stillLeft");
47
48 entityManager_.emplaceComponent<TransformableComponent>(
49 player,
50 203, 44, 10, 12);
51
52 entityManager_.emplaceComponent<DroppableComponent>(player);
53 entityManager_.emplaceComponent<PonderableComponent>(player);
54 entityManager_.emplaceComponent<ControllableComponent>(player);
55 entityManager_.emplaceComponent<OrientableComponent>(player);
56
38 glfwSwapInterval(1); 57 glfwSwapInterval(1);
39 glfwSetWindowUserPointer(window, this); 58 glfwSetWindowUserPointer(window_, this);
40 glfwSetKeyCallback(window, key_callback); 59 glfwSetKeyCallback(window_, key_callback);
41} 60}
42 61
43void Game::execute() 62void Game::execute()
@@ -46,7 +65,7 @@ void Game::execute()
46 const double dt = 0.01; 65 const double dt = 0.01;
47 double accumulator = 0.0; 66 double accumulator = 0.0;
48 67
49 while (!(shouldQuit || glfwWindowShouldClose(window))) 68 while (!(shouldQuit_ || glfwWindowShouldClose(window_)))
50 { 69 {
51 double currentTime = glfwGetTime(); 70 double currentTime = glfwGetTime();
52 double frameTime = currentTime - lastTime; 71 double frameTime = currentTime - lastTime;
@@ -57,19 +76,13 @@ void Game::execute()
57 accumulator += frameTime; 76 accumulator += frameTime;
58 while (accumulator >= dt) 77 while (accumulator >= dt)
59 { 78 {
60 systemManager.getSystem<ControllingSystem>().tick(dt); 79 systemManager_.getSystem<ControllingSystem>().tick(dt);
61 systemManager.getSystem<PonderingSystem>().tick(dt); 80 systemManager_.getSystem<PonderingSystem>().tick(dt);
81 systemManager_.getSystem<AnimatingSystem>().tick(dt);
62 82
63 accumulator -= dt; 83 accumulator -= dt;
64 } 84 }
65 85
66 systemManager.getSystem<RenderingSystem>().tick(frameTime); 86 systemManager_.getSystem<RenderingSystem>().tick(frameTime);
67 } 87 }
68} 88}
69
70EntityManager& Game::getEntityManager()
71{
72 return entityManager;
73}
74
75