diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-12-13 12:02:48 +0100 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-12-13 12:02:48 +0100 |
commit | 15f4780dd94a06bec5616155c05810c731d2e4af (patch) | |
tree | 11c6917805582f603e36bc47e7fd14f95b713a2b | |
parent | efaa4c026b60d52705b163f6886567793ef94123 (diff) |
Add the alien.
-rw-r--r-- | assets/units/alien/idle_ny_0.png | bin | 0 -> 1546 bytes | |||
-rw-r--r-- | assets/units/alien/idle_ny_1.png | bin | 0 -> 1505 bytes | |||
-rw-r--r-- | assets/units/alien/idle_x_0.png | bin | 0 -> 1775 bytes | |||
-rw-r--r-- | assets/units/alien/idle_x_1.png | bin | 0 -> 1562 bytes | |||
-rw-r--r-- | assets/units/alien/idle_y_0.png | bin | 0 -> 1590 bytes | |||
-rw-r--r-- | assets/units/alien/idle_y_1.png | bin | 0 -> 1555 bytes | |||
-rw-r--r-- | assets/units/alien/walking_ny_0.png | bin | 0 -> 1508 bytes | |||
-rw-r--r-- | assets/units/alien/walking_ny_1.png | bin | 0 -> 1470 bytes | |||
-rw-r--r-- | assets/units/alien/walking_x_0.png | bin | 0 -> 1484 bytes | |||
-rw-r--r-- | assets/units/alien/walking_x_1.png | bin | 0 -> 1460 bytes | |||
-rw-r--r-- | assets/units/alien/walking_y_0.png | bin | 0 -> 1513 bytes | |||
-rw-r--r-- | assets/units/alien/walking_y_1.png | bin | 0 -> 1578 bytes | |||
-rw-r--r-- | src/game/assets.cpp | 6 | ||||
-rw-r--r-- | src/game/game.cpp | 5 | ||||
-rw-r--r-- | src/game/game.hpp | 17 | ||||
-rw-r--r-- | src/game/units.cpp | 50 | ||||
-rw-r--r-- | src/render.cpp | 1 |
17 files changed, 64 insertions, 15 deletions
diff --git a/assets/units/alien/idle_ny_0.png b/assets/units/alien/idle_ny_0.png Binary files differnew file mode 100644 index 0000000..20c622e --- /dev/null +++ b/assets/units/alien/idle_ny_0.png diff --git a/assets/units/alien/idle_ny_1.png b/assets/units/alien/idle_ny_1.png Binary files differnew file mode 100644 index 0000000..6929178 --- /dev/null +++ b/assets/units/alien/idle_ny_1.png diff --git a/assets/units/alien/idle_x_0.png b/assets/units/alien/idle_x_0.png Binary files differnew file mode 100644 index 0000000..7378357 --- /dev/null +++ b/assets/units/alien/idle_x_0.png diff --git a/assets/units/alien/idle_x_1.png b/assets/units/alien/idle_x_1.png Binary files differnew file mode 100644 index 0000000..cc94179 --- /dev/null +++ b/assets/units/alien/idle_x_1.png diff --git a/assets/units/alien/idle_y_0.png b/assets/units/alien/idle_y_0.png Binary files differnew file mode 100644 index 0000000..18a6598 --- /dev/null +++ b/assets/units/alien/idle_y_0.png diff --git a/assets/units/alien/idle_y_1.png b/assets/units/alien/idle_y_1.png Binary files differnew file mode 100644 index 0000000..0af362e --- /dev/null +++ b/assets/units/alien/idle_y_1.png diff --git a/assets/units/alien/walking_ny_0.png b/assets/units/alien/walking_ny_0.png Binary files differnew file mode 100644 index 0000000..3b1a5df --- /dev/null +++ b/assets/units/alien/walking_ny_0.png diff --git a/assets/units/alien/walking_ny_1.png b/assets/units/alien/walking_ny_1.png Binary files differnew file mode 100644 index 0000000..49b7b50 --- /dev/null +++ b/assets/units/alien/walking_ny_1.png diff --git a/assets/units/alien/walking_x_0.png b/assets/units/alien/walking_x_0.png Binary files differnew file mode 100644 index 0000000..3b74409 --- /dev/null +++ b/assets/units/alien/walking_x_0.png diff --git a/assets/units/alien/walking_x_1.png b/assets/units/alien/walking_x_1.png Binary files differnew file mode 100644 index 0000000..b0bdf80 --- /dev/null +++ b/assets/units/alien/walking_x_1.png diff --git a/assets/units/alien/walking_y_0.png b/assets/units/alien/walking_y_0.png Binary files differnew file mode 100644 index 0000000..8108c3f --- /dev/null +++ b/assets/units/alien/walking_y_0.png diff --git a/assets/units/alien/walking_y_1.png b/assets/units/alien/walking_y_1.png Binary files differnew file mode 100644 index 0000000..a9cdb8f --- /dev/null +++ b/assets/units/alien/walking_y_1.png diff --git a/src/game/assets.cpp b/src/game/assets.cpp index c20d77b..b9b1289 100644 --- a/src/game/assets.cpp +++ b/src/game/assets.cpp @@ -3,8 +3,7 @@ namespace game::assets { human_assets_t human; -sf::Texture tile_dirt; -sf::Texture tile_wall; +alien_assets_t alien; void load(void) { @@ -13,6 +12,9 @@ void load(void) human.legs_idle.load("assets/units/human/legs_idle", 2, 2); human.legs_walking.load("assets/units/human/legs_walking", 2, 2); + alien.idle.load("assets/units/alien/idle", 2, 2, 2); + alien.walking.load("assets/units/alien/walking", 2, 2, 2); + world::register_tile(TILE_DIRT, 0); world::register_tile(TILE_WALL, 1); render::register_tile(TILE_DIRT, "assets/tiles/dirt.png"); diff --git a/src/game/game.cpp b/src/game/game.cpp index e58b8d5..71d24ac 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -7,12 +7,17 @@ size_t selection_cookie = 1; void state_t::start(void) { human_t *human; + alien_t *alien; world.generator = worldgen; human = new human_t; human->place(&world, v2f_t(0.5, 0.5)); units.insert(human); + + alien = new alien_t; + alien->place(&world, v2f_t(5.5, 5.5)); + units.insert(alien); } void state_t::stop(void) diff --git a/src/game/game.hpp b/src/game/game.hpp index fa75da1..f45aecf 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -22,9 +22,12 @@ namespace game { render::oriented_sprite_4M2_t legs_idle, legs_walking; } human_assets_t; + typedef struct { + render::oriented_sprite_4M_t idle, walking; + } alien_assets_t; + extern human_assets_t human; - extern sf::Texture tile_dirt; - extern sf::Texture tile_wall; + extern alien_assets_t alien; void load(void); } @@ -59,9 +62,10 @@ namespace game { const wchar_t *say_text; double say_time = -INFINITY; + void render_to(render::state_t *render); void say(const wchar_t *wstr, double now); void place(world::world_t *world_, v2f_t x_); - void keep_moving(double now, double dt); + bool keep_moving(double now, double dt); bool start_moving(v2f_t dst_, double now); }; @@ -69,5 +73,12 @@ namespace game { public: human_t(); void render_to(render::state_t *render); + bool keep_moving(double now, double dt); + }; + + class alien_t : public unit_t { + public: + alien_t(); + void render_to(render::state_t *render); }; }; diff --git a/src/game/units.cpp b/src/game/units.cpp index 7dc2d84..d695050 100644 --- a/src/game/units.cpp +++ b/src/game/units.cpp @@ -24,6 +24,15 @@ unit_t::unit_t() : entity_t(ET_UNIT) { } +void unit_t::render_to(render::state_t *render) +{ + if (selected == selection_cookie) + render->render_hlrect(render_bounds, sf::Color::Blue); + + if (move.moving && debug_draw_paths) + render->debug_path(&move.path); +} + void unit_t::say(const wchar_t *wstr, double now) { say_text = wstr; @@ -44,15 +53,15 @@ void unit_t::place(world::world_t *world_, v2f_t x_) link(world); } -void unit_t::keep_moving(double now, double dt) +bool unit_t::keep_moving(double now, double dt) { float time; if (!move.moving) - return; + return false; if (move.blocked && now < move.next_attempt) - return; + return false; time = dt * 10; @@ -97,10 +106,10 @@ void unit_t::keep_moving(double now, double dt) break; } - unlink(); compute_bounds(); link(world); + return true; } bool unit_t::start_moving(v2f_t dst_, double now) @@ -136,13 +145,15 @@ human_t::human_t() render_size[1] = v2f_t(+0.5f, +0.5f); } +bool human_t::keep_moving(double now, double dt) +{ + unit_t::keep_moving(now, dt); +} + void human_t::render_to(render::state_t *render) { bool moving; - if (selected == selection_cookie) - render->render_hlrect(render_bounds, sf::Color::Blue); - moving = move.moving && !move.blocked; render->render((moving ? &assets::human.legs_walking : @@ -150,9 +161,6 @@ void human_t::render_to(render::state_t *render) render->render(&assets::human.body_idle, render_bounds, move.angle); render->render(&assets::human.head_idle, render_bounds, move.angle); - if (move.moving && debug_draw_paths) - render->debug_path(&move.path); - if (say_time + 5.0 > render->now) { v2f_t text_pos; float height; @@ -163,6 +171,28 @@ void human_t::render_to(render::state_t *render) render::ALIGN_CENTER_BOTTOM, sf::Color::White); } + + unit_t::render_to(render); +} + +alien_t::alien_t() +{ + size[0] = v2f_t(-0.2f, -0.2f); + size[1] = v2f_t(+0.2f, +0.2f); + render_size[0] = v2f_t(-0.3f, -0.3f); + render_size[1] = v2f_t(+0.3f, +0.3f); +} + +void alien_t::render_to(render::state_t *render) +{ + bool moving; + + moving = move.moving && !move.blocked; + + render->render((moving ? &assets::alien.walking : + &assets::alien.idle), render_bounds, move.angle); + + unit_t::render_to(render); } } // namespace game diff --git a/src/render.cpp b/src/render.cpp index 48beaa9..b80dcbd 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -272,6 +272,7 @@ bool animated_texture_t::load(std::string prefix, size_t frame_count_) if (!frames[i].loadFromFile(path)) { delete[] frames; frames = NULL; + frame_count = 0; return false; } } |