From 672180b2ee3ed9b9ff984538a85e6eaf2e1c91bc Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Sat, 14 Oct 2017 16:16:34 +0200 Subject: Move assets to assets.cpp. --- Makefile | 3 ++- assets/src/human.xcf | Bin 15712 -> 35180 bytes assets/tiles/alien_dirt.png | Bin 0 -> 986 bytes src/assets.cpp | 15 +++++++++++++++ src/common.hpp | 12 +++++++++++- src/game.cpp | 33 ++++++++------------------------- src/main.cpp | 4 ++-- src/render.cpp | 4 ++++ 8 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 assets/tiles/alien_dirt.png create mode 100644 src/assets.cpp 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 Binary files a/assets/src/human.xcf and b/assets/src/human.xcf differ diff --git a/assets/tiles/alien_dirt.png b/assets/tiles/alien_dirt.png new file mode 100644 index 0000000..7723c65 Binary files /dev/null and b/assets/tiles/alien_dirt.png 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 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 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; -- cgit