summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-10-14 16:16:34 +0200
committerPaweł Redman <pawel.redman@gmail.com>2017-10-14 16:16:34 +0200
commit672180b2ee3ed9b9ff984538a85e6eaf2e1c91bc (patch)
tree9dc40562890b7dff088afc46fb4e2af0ea3552d8 /src
parente4ca910e7731e2a12815a4a8de2582157f519898 (diff)
Move assets to assets.cpp.
Diffstat (limited to 'src')
-rw-r--r--src/assets.cpp15
-rw-r--r--src/common.hpp12
-rw-r--r--src/game.cpp33
-rw-r--r--src/main.cpp4
-rw-r--r--src/render.cpp4
5 files changed, 40 insertions, 28 deletions
diff --git a/src/assets.cpp b/src/assets.cpp
new file mode 100644
index 0000000..530723d
--- /dev/null
+++ b/src/assets.cpp
@@ -0,0 +1,15 @@
+#include "common.hpp"
+
+namespace assets {
+
+human_assets_t human;
+
+void load(void)
+{
+ human.head_idle.load("assets/units/human/head_idle", 1, 1, 1);
+ human.body_idle.load("assets/units/human/body_idle", 2, 2, 2);
+ human.legs_idle.load("assets/units/human/legs_idle", 2, 2);
+ human.legs_walking.load("assets/units/human/legs_walking", 2, 2);
+}
+
+} // namespace assets
diff --git a/src/common.hpp b/src/common.hpp
index 4645bea..f458190 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -116,7 +116,6 @@ namespace game {
void start(void);
void tick(void);
- void render(render::state_t *render);
};
}
@@ -190,6 +189,17 @@ namespace render {
};
}
+namespace assets {
+ typedef struct {
+ render::oriented_sprite_4M_t head_idle, body_idle;
+ render::oriented_sprite_4M2_t legs_idle, legs_walking;
+ } human_assets_t;
+
+ extern human_assets_t human;
+
+ void load(void);
+};
+
// Divide and round to minus infinity.
template <typename T>
T divide_rmi(T x, T y, T *rem)
diff --git a/src/game.cpp b/src/game.cpp
index 58b56c6..0b3e8d6 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -5,22 +5,6 @@ namespace game {
class unit_t : public world::entity_t {
};
-struct {
- struct {
- render::oriented_sprite_4M_t head_idle, body_idle;
- render::oriented_sprite_4M2_t legs_idle, legs_walking;
- } human;
-} assets;
-
-bool load_assets(void)
-{
- assets.human.head_idle.load("assets/units/human/head_idle", 1, 1, 1);
- assets.human.body_idle.load("assets/units/human/body_idle", 2, 2, 2);
- assets.human.legs_idle.load("assets/units/human/legs_idle", 2, 2);
- assets.human.legs_walking.load("assets/units/human/legs_walking", 2, 2);
- return true;
-}
-
class human_t : public unit_t {
public:
@@ -30,10 +14,10 @@ public:
void render_to(render::state_t *render)
{
- render->render((walking ? &assets.human.legs_walking :
- &assets.human.legs_idle), bounds, angle);
- render->render(&assets.human.body_idle, bounds, angle);
- render->render(&assets.human.head_idle, bounds, angle);
+ render->render((walking ? &assets::human.legs_walking :
+ &assets::human.legs_idle), bounds, angle);
+ render->render(&assets::human.body_idle, bounds, angle);
+ render->render(&assets::human.head_idle, bounds, angle);
}
};
@@ -41,11 +25,7 @@ static std::list<human_t> humans;
void state_t::start(void)
{
-}
-
-void state_t::tick(void)
-{
- if (rand() % 5 == 0) {
+ for (size_t i = 0; i < 5; i++) {
humans.emplace(humans.end());
human_t &human = *(--humans.end());
@@ -56,7 +36,10 @@ void state_t::tick(void)
human.bounds.height = 1.0f;
human.link(&world);
}
+}
+void state_t::tick(void)
+{
for (human_t &human : humans) {
human.stalin -= ((float)rand() / RAND_MAX) * 0.1f;
diff --git a/src/main.cpp b/src/main.cpp
index 4aa234c..82b5e2e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -19,7 +19,8 @@ int main()
window.setVerticalSyncEnabled(true);
- game::load_assets();
+ assets::load();
+
game.start();
while (1) {
@@ -33,7 +34,6 @@ int main()
window.clear();
render.begin_frame(now);
render.render(&game);
- //game.render(&render);
interface.render();
render.end_frame();
}
diff --git a/src/render.cpp b/src/render.cpp
index ce9b837..ee2e5b2 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -8,6 +8,7 @@ static void draw_tile(sf::RenderWindow *window, float x, float y,
{
sf::Color color;
+ wot_rect.setTexture(NULL);
wot_rect.setSize(sf::Vector2f(1.0f, 1.0f));
wot_rect.setPosition(sf::Vector2f(x, y));
@@ -109,6 +110,9 @@ void state_t::render(game::state_t *game)
void state_t::render(animated_texture_t *anim, sf::FloatRect bounds, bool mirror){
size_t frame;
+ if (!anim)
+ return;
+
if (!anim->frame_count)
return;