summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-12-15 18:07:16 +0100
committerPaweł Redman <pawel.redman@gmail.com>2017-12-15 18:07:16 +0100
commit4dd7ac29fe0132b9f5896a84ccfe8d05363dfa74 (patch)
tree4abbd9e3aa4403020d7ece46dc4736f67730e2eb /src
parentcd9b7052f07291e3975bad5dcfe9ad0338c17e74 (diff)
Add the blood effect (not yet finished).
Diffstat (limited to 'src')
-rw-r--r--src/game/assets.cpp3
-rw-r--r--src/game/effects.cpp20
-rw-r--r--src/game/game.hpp14
-rw-r--r--src/game/units.cpp15
4 files changed, 47 insertions, 5 deletions
diff --git a/src/game/assets.cpp b/src/game/assets.cpp
index dddd447..1b57800 100644
--- a/src/game/assets.cpp
+++ b/src/game/assets.cpp
@@ -4,6 +4,7 @@ namespace game::assets {
human_assets_t human;
alien_assets_t alien;
+fx_assets_t fx;
void load(void)
{
@@ -19,6 +20,8 @@ void load(void)
alien.walking.load("assets/units/alien/walking", 2, 2, 2);
alien.dead.load("assets/units/alien/dead_", 1);
+ fx.blood.load("assets/units/blood_", 4);
+
world::register_tile(TILE_DIRT, 0);
world::register_tile(TILE_WALL, CF_SOLID);
render::register_tile(TILE_DIRT, "assets/tiles/dirt.png");
diff --git a/src/game/effects.cpp b/src/game/effects.cpp
index 99c8be8..e80623e 100644
--- a/src/game/effects.cpp
+++ b/src/game/effects.cpp
@@ -17,6 +17,8 @@ fx_tracer_t::fx_tracer_t(state_t *game_, v2f_t x0_, v2f_t x1_) : effect_t(game_)
render_bounds[0] = x0;
render_bounds[1] = x1;
render_bounds = render_bounds.norm();
+ cmodel.bounds = render_bounds;
+ cmodel.cflags = 0;
}
void fx_tracer_t::render_to(render::state_t *render)
@@ -34,4 +36,22 @@ void fx_tracer_t::render_to(render::state_t *render)
render->render_line(x0l, x1l, sf::Color::Yellow);
}
+fx_blood_t::fx_blood_t(state_t *game_, v2f_t x_, bool alien_) : effect_t(game_)
+{
+ ttl = game->now + 1.0f;
+
+ x = x_;
+ alien = alien_;
+
+ render_bounds[0] = x - v2f_t(0.2, 0.2);
+ render_bounds[1] = x + v2f_t(0.2, 0.2);
+ cmodel.bounds = render_bounds;
+ cmodel.cflags = 0;
+}
+
+void fx_blood_t::render_to(render::state_t *render)
+{
+ render->render(&assets::fx.blood, render_bounds);
+}
+
} // namespace game
diff --git a/src/game/game.hpp b/src/game/game.hpp
index 0a1d0ca..8949911 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -37,8 +37,13 @@ namespace game {
render::animated_texture_t dead;
} alien_assets_t;
+ typedef struct {
+ render::animated_texture_t blood;
+ } fx_assets_t;
+
extern human_assets_t human;
extern alien_assets_t alien;
+ extern fx_assets_t fx;
void load(void);
}
@@ -157,4 +162,13 @@ namespace game {
fx_tracer_t(game::state_t *game_, v2f_t x0_, v2f_t x1_);
void render_to(render::state_t *render);
};
+
+ class fx_blood_t : public effect_t {
+ bool alien;
+ v2f_t x;
+
+ public:
+ fx_blood_t(game::state_t *game_, v2f_t x_, bool alien_);
+ void render_to(render::state_t *render);
+ };
};
diff --git a/src/game/units.cpp b/src/game/units.cpp
index c50a3fb..65f0a2c 100644
--- a/src/game/units.cpp
+++ b/src/game/units.cpp
@@ -182,6 +182,11 @@ bool unit_t::start_moving(v2f_t dst, world::cflags_t cflags)
void unit_t::damage(int points, unit_t *attacker)
{
+ fx_blood_t *blood;
+
+ blood = new fx_blood_t(game, x, type == UNIT_ALIEN);
+ game->add_effect(blood);
+
health -= points;
if (health < 0) {
game->interface->print(name + " " + text::get(text::UNIT_DEATH) + ".");
@@ -294,16 +299,16 @@ void human_t::think(void)
if (last_attack + 1.5 < game->now) {
world::trace_t trace;
+ fx_tracer_t *tracer;
+
+ tracer = new fx_tracer_t(game, x, target->x);
+ game->add_effect(tracer);
+ std::cout << tracer->cmodel.bounds << std::endl;
trace = world->trace(x, target->x, CF_SOLID);
if (!trace.hit) {
- fx_tracer_t *tracer;
-
last_attack = game->now;
try_attack(target);
-
- tracer = new fx_tracer_t(game, x, target->x);
- game->add_effect(tracer);
}
}