From 87422cff1507f8b5a8633eee5dadbadfef872dab Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Sun, 22 Apr 2018 17:37:38 +0200 Subject: Add the builder. --- Makefile | 1 + assets/units/builder/avatar_0.png | Bin 0 -> 12328 bytes assets/units/builder/body_idle_ny_0.png | Bin 0 -> 2368 bytes assets/units/builder/body_idle_x_0.png | Bin 0 -> 2538 bytes assets/units/builder/body_idle_y_0.png | Bin 0 -> 2755 bytes assets/units/builder/dead_0.png | Bin 0 -> 5428 bytes assets/units/builder/gibbing_0.png | Bin 0 -> 6562 bytes assets/units/builder/gibbing_1.png | Bin 0 -> 6380 bytes assets/units/builder/gibbing_2.png | Bin 0 -> 3552 bytes assets/units/builder/head_idle_ny_0.png | Bin 0 -> 1740 bytes assets/units/builder/head_idle_x_0.png | Bin 0 -> 2215 bytes assets/units/builder/head_idle_y_0.png | Bin 0 -> 1959 bytes assets/units/soldier/avatar_0.png | Bin 12533 -> 9563 bytes assets/units/soldier/body_aiming_ny_0.png | Bin 1415 -> 1432 bytes assets/units/soldier/body_aiming_x_0.png | Bin 2180 -> 2208 bytes assets/units/soldier/body_aiming_y_0.png | Bin 1933 -> 1947 bytes assets/units/soldier/body_firing_ny_0.png | Bin 1249 -> 1259 bytes assets/units/soldier/body_firing_ny_1.png | Bin 1362 -> 1389 bytes assets/units/soldier/body_firing_x_0.png | Bin 2235 -> 2265 bytes assets/units/soldier/body_firing_x_1.png | Bin 2460 -> 2501 bytes assets/units/soldier/body_firing_y_0.png | Bin 2605 -> 2675 bytes assets/units/soldier/body_firing_y_1.png | Bin 2298 -> 2334 bytes assets/units/soldier/body_idle_ny_0.png | Bin 2049 -> 2054 bytes assets/units/soldier/body_idle_x_0.png | Bin 2861 -> 2916 bytes assets/units/soldier/body_idle_y_0.png | Bin 2414 -> 2460 bytes assets/units/soldier/dead_0.png | Bin 4431 -> 4570 bytes assets/units/soldier/gibbing_0.png | Bin 5288 -> 5607 bytes assets/units/soldier/gibbing_1.png | Bin 5721 -> 5990 bytes assets/units/soldier/gibbing_2.png | Bin 3451 -> 3639 bytes assets/units/soldier/head_idle_ny_0.png | Bin 1591 -> 1984 bytes assets/units/soldier/head_idle_x_0.png | Bin 2045 -> 2243 bytes assets/units/soldier/head_idle_y_0.png | Bin 1743 -> 2060 bytes src/game/assets.cpp | 7 ++ src/game/game.cpp | 46 ++++++++- src/game/game.hpp | 28 ++++++ src/game/interface.cpp | 4 + src/game/unit_builder.cpp | 153 ++++++++++++++++++++++++++++++ src/game/unit_repl.cpp | 44 +++++---- src/game/unit_soldier.cpp | 32 ++++--- src/game/units.cpp | 2 + 40 files changed, 281 insertions(+), 36 deletions(-) create mode 100644 assets/units/builder/avatar_0.png create mode 100644 assets/units/builder/body_idle_ny_0.png create mode 100644 assets/units/builder/body_idle_x_0.png create mode 100644 assets/units/builder/body_idle_y_0.png create mode 100644 assets/units/builder/dead_0.png create mode 100644 assets/units/builder/gibbing_0.png create mode 100644 assets/units/builder/gibbing_1.png create mode 100644 assets/units/builder/gibbing_2.png create mode 100644 assets/units/builder/head_idle_ny_0.png create mode 100644 assets/units/builder/head_idle_x_0.png create mode 100644 assets/units/builder/head_idle_y_0.png create mode 100644 src/game/unit_builder.cpp diff --git a/Makefile b/Makefile index bd4a292..3280034 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ SRC := src/game/assets.cpp \ src/game/pseudostate.cpp \ src/game/rocket.cpp \ src/game/units.cpp \ + src/game/unit_builder.cpp \ src/game/unit_nest.cpp \ src/game/unit_repl.cpp \ src/game/unit_scientist.cpp \ diff --git a/assets/units/builder/avatar_0.png b/assets/units/builder/avatar_0.png new file mode 100644 index 0000000..0cf2ef6 Binary files /dev/null and b/assets/units/builder/avatar_0.png differ diff --git a/assets/units/builder/body_idle_ny_0.png b/assets/units/builder/body_idle_ny_0.png new file mode 100644 index 0000000..e61dd9e Binary files /dev/null and b/assets/units/builder/body_idle_ny_0.png differ diff --git a/assets/units/builder/body_idle_x_0.png b/assets/units/builder/body_idle_x_0.png new file mode 100644 index 0000000..3029827 Binary files /dev/null and b/assets/units/builder/body_idle_x_0.png differ diff --git a/assets/units/builder/body_idle_y_0.png b/assets/units/builder/body_idle_y_0.png new file mode 100644 index 0000000..cf2ff1e Binary files /dev/null and b/assets/units/builder/body_idle_y_0.png differ diff --git a/assets/units/builder/dead_0.png b/assets/units/builder/dead_0.png new file mode 100644 index 0000000..8b3ddcd Binary files /dev/null and b/assets/units/builder/dead_0.png differ diff --git a/assets/units/builder/gibbing_0.png b/assets/units/builder/gibbing_0.png new file mode 100644 index 0000000..2e4b7c6 Binary files /dev/null and b/assets/units/builder/gibbing_0.png differ diff --git a/assets/units/builder/gibbing_1.png b/assets/units/builder/gibbing_1.png new file mode 100644 index 0000000..f33ef8f Binary files /dev/null and b/assets/units/builder/gibbing_1.png differ diff --git a/assets/units/builder/gibbing_2.png b/assets/units/builder/gibbing_2.png new file mode 100644 index 0000000..a296e02 Binary files /dev/null and b/assets/units/builder/gibbing_2.png differ diff --git a/assets/units/builder/head_idle_ny_0.png b/assets/units/builder/head_idle_ny_0.png new file mode 100644 index 0000000..0108621 Binary files /dev/null and b/assets/units/builder/head_idle_ny_0.png differ diff --git a/assets/units/builder/head_idle_x_0.png b/assets/units/builder/head_idle_x_0.png new file mode 100644 index 0000000..1324f3c Binary files /dev/null and b/assets/units/builder/head_idle_x_0.png differ diff --git a/assets/units/builder/head_idle_y_0.png b/assets/units/builder/head_idle_y_0.png new file mode 100644 index 0000000..7fbd87b Binary files /dev/null and b/assets/units/builder/head_idle_y_0.png differ diff --git a/assets/units/soldier/avatar_0.png b/assets/units/soldier/avatar_0.png index bcb11cf..12ae915 100644 Binary files a/assets/units/soldier/avatar_0.png and b/assets/units/soldier/avatar_0.png differ diff --git a/assets/units/soldier/body_aiming_ny_0.png b/assets/units/soldier/body_aiming_ny_0.png index 6fb5791..2753ce9 100644 Binary files a/assets/units/soldier/body_aiming_ny_0.png and b/assets/units/soldier/body_aiming_ny_0.png differ diff --git a/assets/units/soldier/body_aiming_x_0.png b/assets/units/soldier/body_aiming_x_0.png index ff9fab2..a85f754 100644 Binary files a/assets/units/soldier/body_aiming_x_0.png and b/assets/units/soldier/body_aiming_x_0.png differ diff --git a/assets/units/soldier/body_aiming_y_0.png b/assets/units/soldier/body_aiming_y_0.png index 34d6d50..eae2a2f 100644 Binary files a/assets/units/soldier/body_aiming_y_0.png and b/assets/units/soldier/body_aiming_y_0.png differ diff --git a/assets/units/soldier/body_firing_ny_0.png b/assets/units/soldier/body_firing_ny_0.png index 214e5c4..2496bb0 100644 Binary files a/assets/units/soldier/body_firing_ny_0.png and b/assets/units/soldier/body_firing_ny_0.png differ diff --git a/assets/units/soldier/body_firing_ny_1.png b/assets/units/soldier/body_firing_ny_1.png index b0dedae..78e8806 100644 Binary files a/assets/units/soldier/body_firing_ny_1.png and b/assets/units/soldier/body_firing_ny_1.png differ diff --git a/assets/units/soldier/body_firing_x_0.png b/assets/units/soldier/body_firing_x_0.png index 274bebc..26db666 100644 Binary files a/assets/units/soldier/body_firing_x_0.png and b/assets/units/soldier/body_firing_x_0.png differ diff --git a/assets/units/soldier/body_firing_x_1.png b/assets/units/soldier/body_firing_x_1.png index 640f37d..65b8c03 100644 Binary files a/assets/units/soldier/body_firing_x_1.png and b/assets/units/soldier/body_firing_x_1.png differ diff --git a/assets/units/soldier/body_firing_y_0.png b/assets/units/soldier/body_firing_y_0.png index 20363b0..44a76e5 100644 Binary files a/assets/units/soldier/body_firing_y_0.png and b/assets/units/soldier/body_firing_y_0.png differ diff --git a/assets/units/soldier/body_firing_y_1.png b/assets/units/soldier/body_firing_y_1.png index d2ca534..24bd2bc 100644 Binary files a/assets/units/soldier/body_firing_y_1.png and b/assets/units/soldier/body_firing_y_1.png differ diff --git a/assets/units/soldier/body_idle_ny_0.png b/assets/units/soldier/body_idle_ny_0.png index a4305fe..bfa057f 100644 Binary files a/assets/units/soldier/body_idle_ny_0.png and b/assets/units/soldier/body_idle_ny_0.png differ diff --git a/assets/units/soldier/body_idle_x_0.png b/assets/units/soldier/body_idle_x_0.png index d998a21..e5b51b7 100644 Binary files a/assets/units/soldier/body_idle_x_0.png and b/assets/units/soldier/body_idle_x_0.png differ diff --git a/assets/units/soldier/body_idle_y_0.png b/assets/units/soldier/body_idle_y_0.png index 524ed6a..5fbae90 100644 Binary files a/assets/units/soldier/body_idle_y_0.png and b/assets/units/soldier/body_idle_y_0.png differ diff --git a/assets/units/soldier/dead_0.png b/assets/units/soldier/dead_0.png index a2accf3..4855fca 100644 Binary files a/assets/units/soldier/dead_0.png and b/assets/units/soldier/dead_0.png differ diff --git a/assets/units/soldier/gibbing_0.png b/assets/units/soldier/gibbing_0.png index d0174c5..2415a94 100644 Binary files a/assets/units/soldier/gibbing_0.png and b/assets/units/soldier/gibbing_0.png differ diff --git a/assets/units/soldier/gibbing_1.png b/assets/units/soldier/gibbing_1.png index 8b5e34b..804cb3b 100644 Binary files a/assets/units/soldier/gibbing_1.png and b/assets/units/soldier/gibbing_1.png differ diff --git a/assets/units/soldier/gibbing_2.png b/assets/units/soldier/gibbing_2.png index 089f8cf..bae5619 100644 Binary files a/assets/units/soldier/gibbing_2.png and b/assets/units/soldier/gibbing_2.png differ diff --git a/assets/units/soldier/head_idle_ny_0.png b/assets/units/soldier/head_idle_ny_0.png index d46674a..7782c2b 100644 Binary files a/assets/units/soldier/head_idle_ny_0.png and b/assets/units/soldier/head_idle_ny_0.png differ diff --git a/assets/units/soldier/head_idle_x_0.png b/assets/units/soldier/head_idle_x_0.png index 49c8d62..637ba15 100644 Binary files a/assets/units/soldier/head_idle_x_0.png and b/assets/units/soldier/head_idle_x_0.png differ diff --git a/assets/units/soldier/head_idle_y_0.png b/assets/units/soldier/head_idle_y_0.png index 07f3e11..873f203 100644 Binary files a/assets/units/soldier/head_idle_y_0.png and b/assets/units/soldier/head_idle_y_0.png differ diff --git a/src/game/assets.cpp b/src/game/assets.cpp index 1a84b62..96666a3 100644 --- a/src/game/assets.cpp +++ b/src/game/assets.cpp @@ -21,6 +21,7 @@ namespace game::assets { soldier_assets_t soldier; scientist_assets_t scientist; +builder_assets_t builder; spider_assets_t spider; nest_assets_t nest; repl_assets_t repl; @@ -67,6 +68,12 @@ void load(void) scientist.laugh.load("assets/units/scientist/laugh2.ogg"); scientist.gather.load("assets/units/scientist/gather.ogg"); + builder.body_idle.load("assets/units/builder/body_idle", 1, 1, 1); + builder.head_idle.load("assets/units/builder/head_idle", 1, 1, 1); + builder.dead.load("assets/units/builder/dead_", 1); + builder.gibbing.load("assets/units/builder/gibbing_", 3); + builder.avatar.load("assets/units/builder/avatar_", 1); + spider.idle.load("assets/units/spider/idle", 2, 2, 2); spider.walking.load("assets/units/spider/walking", 2, 2, 2); spider.dead.load("assets/units/spider/dead_", 1); diff --git a/src/game/game.cpp b/src/game/game.cpp index a74a906..086b926 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -161,6 +161,10 @@ void state_t::select(rectf_t rect, int type) unit->say("Я готов.", false); break; + case unit_t::UNIT_BUILDER: + unit->say("Gotowy na rozkaz.", false); + break; + default: break; } @@ -179,13 +183,15 @@ enum { COMMAND_REPL_SOLDIER, COMMAND_REPL_SCIENTIST, + COMMAND_REPL_BUILDER, COMMAND_GATHER }; bool state_t::populate_pie_menu(std::vector &items) { - bool soldiers = false, repls = false, rockets = false, scientists = false; + bool soldiers = false, repls = false, rockets = false, + scientists = false, builders = false; items.clear(); @@ -207,6 +213,10 @@ bool state_t::populate_pie_menu(std::vector &items) scientists = true; break; + case unit_t::UNIT_BUILDER: + builders = true; + break; + case unit_t::UNIT_REPL: repls = true; break; @@ -215,7 +225,7 @@ bool state_t::populate_pie_menu(std::vector &items) } } - if (soldiers || scientists) { + if (soldiers || scientists || builders) { items.push_back((interface::pie_item_t){"Move", COMMAND_MOVE}); items.push_back((interface::pie_item_t){"Stop", COMMAND_STOP}); } @@ -229,9 +239,13 @@ bool state_t::populate_pie_menu(std::vector &items) if (scientists) items.push_back((interface::pie_item_t){"Gather", COMMAND_GATHER}); + if (builders) + items.push_back((interface::pie_item_t){"TODO", -1}); + if (repls) { items.push_back((interface::pie_item_t){"Spawn a soldier", COMMAND_REPL_SOLDIER}); items.push_back((interface::pie_item_t){"Spawn a scientist", COMMAND_REPL_SCIENTIST}); + items.push_back((interface::pie_item_t){"Spawn a builder", COMMAND_REPL_BUILDER}); } return true; @@ -308,6 +322,25 @@ static void command_scientist(unit_scientist_t *scientist, v2f_t x, int number) } } +static void command_builder(unit_builder_t *builder, v2f_t x, int number) +{ + switch (number) { + case COMMAND_MOVE: + if (!builder->start_moving(x)) + builder->say("Nie ma tam drogi.", false); + else { + builder->move_marker = std::make_unique(builder->game, builder->move.path.back()); + builder->say("W drodze.", false); + } + break; + + case COMMAND_STOP: + builder->stop_moving(); + builder->say("Stop.", false); + break; + } +} + static void command_repl(unit_repl_t *repl, v2f_t x, int number) { switch (number) { @@ -318,6 +351,10 @@ static void command_repl(unit_repl_t *repl, v2f_t x, int number) case COMMAND_REPL_SCIENTIST: repl->activate(unit_t::UNIT_SCIENTIST); break; + + case COMMAND_REPL_BUILDER: + repl->activate(unit_t::UNIT_BUILDER); + break; } } @@ -349,6 +386,11 @@ void state_t::command(v2f_t x, int number) x, number); break; + case unit_t::UNIT_BUILDER: + command_builder(dynamic_cast(unit), + x, number); + break; + case unit_t::UNIT_REPL: command_repl(dynamic_cast(unit), x, number); diff --git a/src/game/game.hpp b/src/game/game.hpp index bc9c249..e48e2a3 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -209,6 +209,12 @@ namespace game { audio::sound_t laugh, gather; } scientist_assets_t; + typedef struct { + render::oriented_sprite_4M_t head_idle, body_idle; + render::animated_texture_t dead, gibbing; + render::animated_texture_t avatar; + } builder_assets_t; + typedef struct { render::oriented_sprite_4M_t idle, walking; render::animated_texture_t dead; @@ -242,6 +248,7 @@ namespace game { extern soldier_assets_t soldier; extern scientist_assets_t scientist; + extern builder_assets_t builder; extern spider_assets_t spider; extern nest_assets_t nest; extern repl_assets_t repl; @@ -295,6 +302,7 @@ namespace game { typedef enum { UNIT_SOLDIER, UNIT_SCIENTIST, + UNIT_BUILDER, UNIT_SPIDER, UNIT_NEST, UNIT_REPL @@ -408,6 +416,26 @@ namespace game { void on_death(void); }; + class unit_builder_t : public unit_t { + bool gibbed = false; + + public: + std::unique_ptr move_marker; + + sf::Color selection_color; + + unit_builder_t(game::state_t *game_); + ~unit_builder_t(void) {}; + void render_to(render::state_t *render); + void render_late_to(render::state_t *render); + + void on_think(void); + void on_spawn(void) {}; + void on_wake(void) {}; + void on_damage(unit_t *attacker); + void on_death(void); + }; + class unit_spider_t : public unit_t { public: unit_spider_t(game::state_t *game_); diff --git a/src/game/interface.cpp b/src/game/interface.cpp index fbde982..5b89f58 100644 --- a/src/game/interface.cpp +++ b/src/game/interface.cpp @@ -356,6 +356,10 @@ static void render_avatar(render::state_t *render, game::unit_t *unit, v2f_t at, image = &assets::scientist.avatar; break; + case game::unit_t::UNIT_BUILDER: + image = &assets::builder.avatar; + break; + case game::unit_t::UNIT_REPL: image = &assets::repl.avatar; break; diff --git a/src/game/unit_builder.cpp b/src/game/unit_builder.cpp new file mode 100644 index 0000000..1f5b81c --- /dev/null +++ b/src/game/unit_builder.cpp @@ -0,0 +1,153 @@ +/* +This file is part of Minitrem. + +Minitrem is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +Minitrem is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Minitrem. If not, see . +*/ + +#include "game.hpp" + +namespace game { + +static std::string builder_name(procgen::prng_t *prng) +{ + std::stringstream ss; + static const char *names[] = { + "Janusz", "Henryk", "Wiesław", "Bolesław", "Edward", + "Roman", "Mirosław", "Zbigniew", "Jerzy", "Józef", "Jan" + }; + + ss << "Pan "; + ss << names[prng->next() % (sizeof(names) / sizeof(names[0]))]; + + return ss.str(); +} + +unit_builder_t::unit_builder_t(game::state_t *game) : unit_t(game, UNIT_BUILDER) +{ + size[0] = v2f_t(-0.3f, +0.0f); + size[1] = v2f_t(+0.3f, +0.3f); + render_size[0] = v2f_t(-0.5f, -1.2f); + render_size[1] = v2f_t(+0.5f, +0.3f); + cmodel.cflags = CF_BODY; + move.cflags = CF_SOLID | CF_BODY | CF_WATER; + + name = builder_name(&game->prng); + + wake(); + friendly = true; + controllable = true; + + health = max_health = 45; +} + +void unit_builder_t::on_think(void) +{ + keep_moving(2.0); + game->wake_area(x); + + if (!move.moving) + move_marker.reset(); + + if (move.moving && (x - move.last_step).len() > 0.5f) { + move.last_step = x; + assets::soldier.step_stone.play_3d(x); + } +} + +void unit_builder_t::on_damage(unit_t *attacker) +{ + if (health < -30) { + assets::fx.gibbing.play_3d(x); + game->deletion_list.insert(this); + return; + } else if (health < -10) { + render_size[0] = v2f_t(-0.5f, -1.2f); + render_size[1] = v2f_t(+0.5f, +0.3f); + + if (!gibbed) + assets::fx.gibbing.play_3d(x); + else + assets::fx.corpse_hit.play_3d(x); + + place(world, x); + gibbed = true; + } else if (health <= 0) { + render_size[0] = v2f_t(-0.75f, -0.5f); + render_size[1] = v2f_t(+0.75f, +0.5f); + if (!dead) + assets::soldier.death.play_3d(x); + else + assets::fx.corpse_hit.play_3d(x); + + place(world, x); + } else + assets::soldier.pain.play_3d(x); +} + +void unit_builder_t::on_death(void) +{ + render_layer = render::LAYER_FLAT; + cmodel.cflags = CF_BACKGROUND; + place(world, x); + controllable = false; + move_marker.reset(); +} + +void unit_builder_t::render_to(render::state_t *render) +{ + sf::Color selection_color; + + if (selected == selection_cookie) { + if (health == max_health) + selection_color = sf::Color::Green; + else if (health >= max_health / 2) + selection_color = sf::Color::Yellow; + else if (dead) + selection_color = sf::Color::Black; + else + selection_color = sf::Color::Red; + + render->render(0.0, &assets::unit_selected, cmodel.bounds, selection_color); + } + + if (!dead) { + render::oriented_sprite_t *legs; + + if (move.moving && !move.blocked) + legs = &assets::soldier.legs_walking; + else + legs = &assets::soldier.legs_idle; + + render->render(game->now * 10, legs, render_bounds, move.angle); + render->render(game->now * 10, &assets::builder.body_idle, render_bounds, move.angle); + render->render(game->now * 10, &assets::builder.head_idle, render_bounds, move.angle); + } else { + float phase = clamp((game->now - death_time) * 5, 0, 0.9); + + if (gibbed) + render->render(phase, &assets::builder.gibbing, render_bounds); + else + render->render(phase, &assets::builder.dead, render_bounds); + } + + unit_t::render_to(render); +} + +void unit_builder_t::render_late_to(render::state_t *render) +{ + if (selected == selection_cookie) + render->render(0.0, &assets::unit_selected_halo, cmodel.bounds, selection_color); +} + +} diff --git a/src/game/unit_repl.cpp b/src/game/unit_repl.cpp index 57e18f8..6dfa005 100644 --- a/src/game/unit_repl.cpp +++ b/src/game/unit_repl.cpp @@ -55,35 +55,39 @@ void unit_repl_t::render_to(render::state_t *render) void unit_repl_t::activate(unit_t::type_t type) { world::cmodel_t cmodel; - world::entity_t *spawned; - - if (type == UNIT_SOLDIER) { - unit_soldier_t *soldier; - - soldier = new unit_soldier_t(game); - soldier->place(&game->world, x); - spawned = soldier; - } else if (type == UNIT_SCIENTIST) { - unit_scientist_t *scientist; - - scientist = new unit_scientist_t(game); - scientist->place(&game->world, x); - spawned = scientist; - } else + unit_t *unit; + + switch (type) { + case UNIT_SOLDIER: + unit = new unit_soldier_t(game); + break; + + case UNIT_SCIENTIST: + unit = new unit_scientist_t(game); + break; + + case UNIT_BUILDER: + unit = new unit_builder_t(game); + break; + + default: abort(); + } + + unit->place(world, x); - for (world::entity_t *ent : game->world.get_entities(spawned->cmodel.bounds, CF_BODY|CF_BODY_SMALL)) + for (world::entity_t *ent : game->world.get_entities(unit->cmodel.bounds, CF_BODY|CF_BODY_SMALL)) { - unit_t *unit; + unit_t *other; - if (ent == spawned) + if (ent == unit) continue; if (ent->type != ET_UNIT) continue; - unit = dynamic_cast(ent); - unit->damage(200, NULL); + other = dynamic_cast(ent); + other->damage(200, NULL); } assets::repl.sound.play_3d(x); diff --git a/src/game/unit_soldier.cpp b/src/game/unit_soldier.cpp index 221667b..d511553 100644 --- a/src/game/unit_soldier.cpp +++ b/src/game/unit_soldier.cpp @@ -19,33 +19,33 @@ along with Minitrem. If not, see . namespace game { -static const char *initials[] = { - "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", - "N", "O", "Ö", "P", "R", "S", "Ś", "T", "U", "Ü", "V", "W", "X", - "Z" -}; - static std::string soldier_name(procgen::prng_t *prng) { std::stringstream ss; static const char *names[] = { - "Kowalski", "O'Neill", "Hammond", "Mitchell", "Hitler", - "Stalin", "Wyspiański", "Bush", "Washington", "Jaruzelski", - "Jackson", "Carter", + "Heinrich", "Hans", "Ernst", "Dieter", "Werner", "Wolfgang", + "Uwe", "Klaus", "Adolf" + }; + static const char *surnames[] = { + "Kloss", "Schmidt", "Göring", "Fischer", "Müller", "Weber", + "Schulz", "Schäfer", "Klein", "Wofl", "Schröder", "Neumann", + "Zimmermann" }; - ss << initials[prng->next() % (sizeof(initials) / sizeof(initials[0]))]; - ss << ". "; ss << names[prng->next() % (sizeof(names) / sizeof(names[0]))]; + ss << " "; + ss << surnames[prng->next() % (sizeof(surnames) / sizeof(surnames[0]))]; return ss.str(); } +const float soldier_head_offset = 0.10f; + unit_soldier_t::unit_soldier_t(game::state_t *game) : unit_t(game, UNIT_SOLDIER) { size[0] = v2f_t(-0.3f, +0.0f); size[1] = v2f_t(+0.3f, +0.3f); - render_size[0] = v2f_t(-0.5f, -1.2f); + render_size[0] = v2f_t(-0.5f, -1.2f - soldier_head_offset); render_size[1] = v2f_t(+0.5f, +0.3f); cmodel.cflags = CF_BODY; move.cflags = CF_SOLID | CF_BODY | CF_WATER; @@ -240,9 +240,13 @@ void unit_soldier_t::render_to(render::state_t *render) } if (!dead) { + rectf_t rect_body; render::oriented_sprite_t *legs, *body; float body_angle; + rect_body = render_bounds; + rect_body[0][1] += soldier_head_offset; + if (move.moving && !move.blocked) legs = &assets::soldier.legs_walking; else @@ -261,8 +265,8 @@ void unit_soldier_t::render_to(render::state_t *render) body_angle = move.angle; } - render->render(game->now * 10, legs, render_bounds, move.angle); - render->render(game->now * 10, body, render_bounds, body_angle); + render->render(game->now * 10, legs, rect_body, move.angle); + render->render(game->now * 10, body, rect_body, body_angle); render->render(game->now * 10, &assets::soldier.head_idle, render_bounds, body_angle); } else { diff --git a/src/game/units.cpp b/src/game/units.cpp index 26cf808..e9abda4 100644 --- a/src/game/units.cpp +++ b/src/game/units.cpp @@ -199,6 +199,7 @@ void unit_t::damage(int points, unit_t *attacker) switch (type) { case UNIT_SOLDIER: case UNIT_SCIENTIST: + case UNIT_BUILDER: alien = false; break; @@ -220,6 +221,7 @@ void unit_t::die(unit_t *killer) switch (type) { case UNIT_SOLDIER: case UNIT_SCIENTIST: + case UNIT_BUILDER: case UNIT_SPIDER: game->interface.print(name + " died."); break; -- cgit