summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--assets/src/human.xcfbin15712 -> 35180 bytes
-rw-r--r--assets/tiles/alien_dirt.pngbin0 -> 986 bytes
-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
8 files changed, 42 insertions, 29 deletions
diff --git a/Makefile b/Makefile
index 69c8d29..baad253 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,8 @@ PP_CC := $(PP_BOLD)$(shell tput setf 6)CC$(PP_RESET)
PP_LD := $(PP_BOLD)$(shell tput setf 2)LD$(PP_RESET)
PP_RM := $(PP_BOLD)$(shell tput setf 4)RM$(PP_RESET)
-SRC := src/game.cpp \
+SRC := src/assets.cpp \
+ src/game.cpp \
src/interface.cpp \
src/main.cpp \
src/procgen.cpp \
diff --git a/assets/src/human.xcf b/assets/src/human.xcf
index 17c2aa5..9aa3c02 100644
--- a/assets/src/human.xcf
+++ b/assets/src/human.xcf
Binary files differ
diff --git a/assets/tiles/alien_dirt.png b/assets/tiles/alien_dirt.png
new file mode 100644
index 0000000..7723c65
--- /dev/null
+++ b/assets/tiles/alien_dirt.png
Binary files differ
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;