diff options
Diffstat (limited to 'player.c')
| -rw-r--r-- | player.c | 36 | 
1 files changed, 30 insertions, 6 deletions
| @@ -8,6 +8,8 @@  #include "render.h"  #include "world.h" +const Rect player_rect = { 5, 4, 5, 12 }; +  void init_player(Player* p) {  	p->anim = asset_id_guy_run_right_anm;  	p->x = 0; @@ -22,6 +24,8 @@ void init_player(Player* p) {  	p->cooldown = 0;  	p->slashing = 0;  	p->face = face_right; +	p->inv = 0; +	p->hp = player_health;  }  void update_player_anim(Player* p) { @@ -30,12 +34,11 @@ void update_player_anim(Player* p) {  }  void update_player_phys(Player* p, const Map* map) { -	const Rect r = { -		5  << fbits, -		4  << fbits, -		5  << fbits, -		12 << fbits -	}; +	Rect r = player_rect; +	r.x <<= fbits; +	r.y <<= fbits; +	r.w <<= fbits; +	r.h <<= fbits;  	update_body(  		map,  		&p->x, @@ -151,6 +154,26 @@ void update_player_move(Player* p, const App* a, World* w) {  	}  } +void update_player_hurt(Player* p, World* w) { +	int i; +	Rect r = player_rect; +	r.x += p->x >> fbits; +	r.y += p->y >> fbits; +	if (p->inv) { +		p->inv--; +		return; +	} +	for (i = 0; i < w->deathzone_count; i++) { +		const Deathzone* dz = &w->deathzones[i]; +		if (!dz->friendly && rects_overlap(&r, &dz->r)) { +			p->hp -= dz->hp; +			p->vx -= dz->vx; +			p->vy -= dz->vy; +			p->inv = enemy_inv_frames; +		} +	} +} +  void update_player(  	Player* p,  	World* w, @@ -158,6 +181,7 @@ void update_player(  	const Map* map  ) {  	update_player_move(p, app, w); +	update_player_hurt(p, w);  	update_player_phys(p, map);  	update_player_anim(p);  } |