diff options
Diffstat (limited to 'src/game/game.cpp')
-rw-r--r-- | src/game/game.cpp | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp index 66bf237..6e8ea78 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -19,6 +19,12 @@ along with Minitrem. If not, see <http://www.gnu.org/licenses/>. namespace game { +bool load_assets(void) +{ + assets::load(); + return true; +} + size_t selection_cookie = 1; entity_t::entity_t(game::state_t *game_, int type_) : world::entity_t(type_) @@ -28,13 +34,8 @@ entity_t::entity_t(game::state_t *game_, int type_) : world::entity_t(type_) entity_t::~entity_t(void) { -} - -void entity_t::destroy(void) -{ + sleep(); unlink(); - game->awake_entities.erase(this); - delete this; } void entity_t::place(world::world_t *world_) @@ -48,9 +49,6 @@ void entity_t::place(world::world_t *world_) if (do_spawn) on_spawn(); - - if (!ignore_waking) - wake(); } void entity_t::place(world::world_t *world, v2f_t x_) @@ -168,7 +166,7 @@ enum { COMMAND_FIRE, COMMAND_STOP, - COMMAND_REPL + COMMAND_REPL, }; bool state_t::populate_pie_menu(std::vector<interface::pie_item_t> &items) @@ -303,11 +301,16 @@ void state_t::tick(ntime_t time_) now = time * 1.0e-9; dt = TIME_DELTA * 1.0e-9; + for (entity_t *ent : deletion_list) + delete ent; + deletion_list.clear(); + // on_think can insert/erase elements of awake_entities so iterate // over a copy of it. auto copy = awake_entities; for (entity_t *ent : copy) - ent->on_think(); + if (awake_entities.find(ent) != awake_entities.end()) + ent->on_think(); frames++; frames_since_t0++; @@ -384,10 +387,39 @@ void state_t::compute_ambience(render::state_t *render) } } -bool load_assets(void) +void state_t::explosion(v2f_t x) { - assets::load(); - return true; + fx_explosion_t *explosion; + + explosion = new fx_explosion_t(this, x); + explosion->place(&world); + + for (size_t i = 0; i < 30; i++) { + v2f_t end; + world::trace_t trace; + unit_t *unit; + int damage; + + end = x + prng.unit_vec2() * 6.0f; + trace = world.ray_v_all(x, end, CF_SOLID|CF_BODY|CF_BODY_SMALL, NULL); + if (!trace.hit) + continue; + + if (!trace.ent) + continue; + + if (trace.ent->type != ET_UNIT) + continue; + + unit = dynamic_cast<unit_t*>(trace.ent); + + if (unit->dead) + continue; + + damage = pow(1 - trace.frac, 2.0f) * 40.0f; + printf("frac=%f, damage=%i\n", trace.frac, damage); + unit->damage(damage, nullptr); + } } } //namespace game |