diff options
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/assets.cpp | 6 | ||||
| -rw-r--r-- | src/game/game.cpp | 5 | ||||
| -rw-r--r-- | src/game/game.hpp | 17 | ||||
| -rw-r--r-- | src/game/units.cpp | 50 | 
4 files changed, 63 insertions, 15 deletions
diff --git a/src/game/assets.cpp b/src/game/assets.cpp index c20d77b..b9b1289 100644 --- a/src/game/assets.cpp +++ b/src/game/assets.cpp @@ -3,8 +3,7 @@  namespace game::assets {  human_assets_t human; -sf::Texture tile_dirt; -sf::Texture tile_wall; +alien_assets_t alien;  void load(void)  { @@ -13,6 +12,9 @@ void load(void)  	human.legs_idle.load("assets/units/human/legs_idle", 2, 2);  	human.legs_walking.load("assets/units/human/legs_walking", 2, 2); +	alien.idle.load("assets/units/alien/idle", 2, 2, 2); +	alien.walking.load("assets/units/alien/walking", 2, 2, 2); +  	world::register_tile(TILE_DIRT, 0);  	world::register_tile(TILE_WALL, 1);  	render::register_tile(TILE_DIRT, "assets/tiles/dirt.png"); diff --git a/src/game/game.cpp b/src/game/game.cpp index e58b8d5..71d24ac 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -7,12 +7,17 @@ size_t selection_cookie = 1;  void state_t::start(void)  {  	human_t *human; +	alien_t *alien;  	world.generator = worldgen;  	human = new human_t;  	human->place(&world, v2f_t(0.5, 0.5));  	units.insert(human); + +	alien = new alien_t; +	alien->place(&world, v2f_t(5.5, 5.5)); +	units.insert(alien);  }  void state_t::stop(void) diff --git a/src/game/game.hpp b/src/game/game.hpp index fa75da1..f45aecf 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -22,9 +22,12 @@ namespace game {  			render::oriented_sprite_4M2_t legs_idle, legs_walking;  		} human_assets_t; +		typedef struct { +			render::oriented_sprite_4M_t idle, walking; +		} alien_assets_t; +  		extern human_assets_t human; -		extern sf::Texture tile_dirt; -		extern sf::Texture tile_wall; +		extern alien_assets_t alien;  		void load(void);  	} @@ -59,9 +62,10 @@ namespace game {  		const wchar_t *say_text;  		double say_time = -INFINITY; +		void render_to(render::state_t *render);  		void say(const wchar_t *wstr, double now);  		void place(world::world_t *world_, v2f_t x_); -		void keep_moving(double now, double dt); +		bool keep_moving(double now, double dt);  		bool start_moving(v2f_t dst_, double now);  	}; @@ -69,5 +73,12 @@ namespace game {  	public:  		human_t();  		void render_to(render::state_t *render); +		bool keep_moving(double now, double dt); +	}; + +	class alien_t : public unit_t { +	public: +		alien_t(); +		void render_to(render::state_t *render);  	};  }; diff --git a/src/game/units.cpp b/src/game/units.cpp index 7dc2d84..d695050 100644 --- a/src/game/units.cpp +++ b/src/game/units.cpp @@ -24,6 +24,15 @@ unit_t::unit_t() : entity_t(ET_UNIT)  {  } +void unit_t::render_to(render::state_t *render) +{ +	if (selected == selection_cookie) +		render->render_hlrect(render_bounds, sf::Color::Blue); + +	if (move.moving && debug_draw_paths) +		render->debug_path(&move.path); +} +  void unit_t::say(const wchar_t *wstr, double now)  {  	say_text = wstr; @@ -44,15 +53,15 @@ void unit_t::place(world::world_t *world_, v2f_t x_)  	link(world);  } -void unit_t::keep_moving(double now, double dt) +bool unit_t::keep_moving(double now, double dt)  {  	float time;  	if (!move.moving) -		return; +		return false;  	if (move.blocked && now < move.next_attempt) -		return; +		return false;  	time = dt * 10; @@ -97,10 +106,10 @@ void unit_t::keep_moving(double now, double dt)  		break;  	} -  	unlink();  	compute_bounds();  	link(world); +	return true;  }  bool unit_t::start_moving(v2f_t dst_, double now) @@ -136,13 +145,15 @@ human_t::human_t()  	render_size[1] = v2f_t(+0.5f, +0.5f);  } +bool human_t::keep_moving(double now, double dt) +{ +	unit_t::keep_moving(now, dt); +} +  void human_t::render_to(render::state_t *render)  {  	bool moving; -	if (selected == selection_cookie) -		render->render_hlrect(render_bounds, sf::Color::Blue); -  	moving = move.moving && !move.blocked;  	render->render((moving ? &assets::human.legs_walking : @@ -150,9 +161,6 @@ void human_t::render_to(render::state_t *render)  	render->render(&assets::human.body_idle, render_bounds, move.angle);  	render->render(&assets::human.head_idle, render_bounds, move.angle); -	if (move.moving && debug_draw_paths) -		render->debug_path(&move.path); -  	if (say_time + 5.0 > render->now) {  		v2f_t text_pos;  		float height; @@ -163,6 +171,28 @@ void human_t::render_to(render::state_t *render)  				    render::ALIGN_CENTER_BOTTOM,  				    sf::Color::White);  	} + +	unit_t::render_to(render); +} + +alien_t::alien_t() +{ +	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); +	render_size[1] = v2f_t(+0.3f, +0.3f); +} + +void alien_t::render_to(render::state_t *render) +{ +	bool moving; + +	moving = move.moving && !move.blocked; + +	render->render((moving ? &assets::alien.walking : +		       &assets::alien.idle), render_bounds, move.angle); + +	unit_t::render_to(render);  }  } // namespace game  | 
