summaryrefslogtreecommitdiff
path: root/src/game/grenade.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-04-25 17:52:18 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-04-25 17:52:18 +0200
commit4fa5f46575e545437ab774c97f9dc88ec304251d (patch)
treefe18d39cd490bb788f787b08dfcf00f93a1c24e5 /src/game/grenade.cpp
parent273abc7c37e9bcdb7cf8d092ed356de01b906146 (diff)
Remake rockets into grenades.
Diffstat (limited to 'src/game/grenade.cpp')
-rw-r--r--src/game/grenade.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/game/grenade.cpp b/src/game/grenade.cpp
new file mode 100644
index 0000000..e6a44c9
--- /dev/null
+++ b/src/game/grenade.cpp
@@ -0,0 +1,103 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+
+#include "game.hpp"
+
+namespace game {
+
+void grenade_t::compute_bounds(void)
+{
+ v2f_t x_p3d;
+
+ x_p3d = x + v2f_t(0.0f, -0.3f * z);
+ cmodel.bounds[0] = x_p3d - size[0];
+ cmodel.bounds[1] = x_p3d - size[1];
+ render_bounds[0] = x_p3d - render_size[0];
+ render_bounds[1] = x_p3d - render_size[1];
+}
+
+grenade_t::grenade_t(game::state_t *game, v2f_t x_, v2f_t target, unit_t *shooter_) : entity_t(game, ET_ROCKET)
+{
+ x = x_;
+ v = (target - x) * 1.5f;
+
+ z = 0.7f;
+ v_z = 5.0f;
+
+ size = rectf_t(v2f_t(-0.1f, -0.1f), v2f_t(0.1f, 0.1f));
+ render_size = size;
+ cmodel.cflags = CF_BACKGROUND;
+
+ explosion_time = game->time + SEC(3);
+
+ wake();
+}
+
+void grenade_t::on_spawn(void)
+{
+}
+
+void grenade_t::on_think(void)
+{
+ v2f_t end;
+ world::trace_t trace;
+
+ if (game->time >= explosion_time) {
+ cmodel.ignore = true;
+ game->explosion(x);
+ delete this;
+ return;
+ }
+
+ if (z + pow(v_z, 2) < 0.01f)
+ return;
+
+ end = x + v * game->dt;
+
+ trace = world->ray_v_all(x, end, CF_SOLID, shooter);
+ x = trace.end;
+
+ v_z += -10.0f * game->dt;
+ z += v_z * game->dt;
+ if (z < 0.0f) {
+ trace = world->ray_v_tiles(x, x, CF_WATER);
+ if (trace.hit) {
+ fx_bullet_miss_t *bullet_miss;
+
+ bullet_miss = new fx_bullet_miss_t(game, trace.end, true);
+ bullet_miss->place(world);
+
+ delete this;
+ return;
+ }
+
+ z *= -1.0f;
+ v_z *= -0.4f;
+
+ assets::soldier.grenade_bounce.play_3d(x);
+ }
+
+ compute_bounds();
+ place(world);
+}
+
+void grenade_t::render_to(render::state_t *render)
+{
+ render->render(game->now, &assets::soldier.grenade, render_bounds);
+}
+
+} \ No newline at end of file