diff options
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/game.hpp | 2 | ||||
| -rw-r--r-- | src/game/units.cpp | 34 | 
2 files changed, 31 insertions, 5 deletions
diff --git a/src/game/game.hpp b/src/game/game.hpp index 0ad0614..f6687dc 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -86,7 +86,7 @@ namespace game {  		bool dead = false;  		double death_time = -INFINITY; -		int health = 1; +		int health = 1, max_health = 1;  		void damage(double now, int points);  		virtual void die(double now) = 0; diff --git a/src/game/units.cpp b/src/game/units.cpp index c416dd7..b4cb333 100644 --- a/src/game/units.cpp +++ b/src/game/units.cpp @@ -29,6 +29,32 @@ void unit_t::render_to(render::state_t *render)  	if (selected == selection_cookie)  		render->render_hlrect(render_bounds, sf::Color::Blue); +	if (!dead && health < max_health) +	{ +		rectf_t bar; +		float frac; +		sf::Color color; + +		bar[0][0] = (render_bounds[0][0] + render_bounds[1][0]) / 2; +		bar[0][1] = render_bounds[0][1] - 0.05f; +		bar[0][0] -= 0.3f; +		bar[1][0] = bar[0][0] + 0.6f; +		bar[1][1] = bar[0][1] + 0.05f; +		render->render_rect(bar, sf::Color::Black); + +		frac = (float)health / max_health; + +		if (frac < 0.3f) +			color = sf::Color::Red; +		else if (frac < 0.75f) +			color = sf::Color::Yellow; +		else +			color = sf::Color::Green; + +		bar[1][0] = lerp(bar[0][0], bar[1][0], frac); +		render->render_rect(bar, color); +	} +  	if (move.moving && debug_draw_paths)  		render->debug_path(&move.path);  } @@ -151,7 +177,7 @@ void unit_t::damage(double now, int points)  human_t::human_t() : unit_t(UNIT_HUMAN)  {  	cflags = CF_HUMAN; -	health = 20; +	health = max_health = 20;  	size[0] = v2f_t(-0.4f, -0.4f);  	size[1] = v2f_t(+0.4f, +0.4f);  	render_size[0] = v2f_t(-0.5f, -1.0f); @@ -212,7 +238,7 @@ void human_t::render_to(render::state_t *render)  alien_t::alien_t() : unit_t(UNIT_ALIEN)  {  	cflags = CF_SOLID; -	health = 4; +	health = max_health = 4;  	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); @@ -281,9 +307,9 @@ void alien_t::attack(double now, unit_t *target, float range)  	trace = world->trace(x, target->x, CF_SOLID);  	if (!trace.hit) -		target->damage(now, 12); +		target->damage(now, rand() % 6 + rand() % 6 + 2); -	next_attack = now + 1.0; +	next_attack = now + 0.4;  }  void alien_t::think(double now, double dt)  | 
