From 4d94823a1523db6dc218bdc0d86689616c13599d Mon Sep 17 00:00:00 2001 From: quou Date: Wed, 2 Oct 2024 18:47:37 +1000 Subject: Gun special --- config.h | 1 + obj.h | 10 ++++++++++ player.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ world.c | 5 +++++ world.h | 1 + 5 files changed, 75 insertions(+) diff --git a/config.h b/config.h index 5ab7597..7dcf8d7 100644 --- a/config.h +++ b/config.h @@ -39,6 +39,7 @@ #define player_attack_frames 10 #define player_lunge_force (f1) #define player_slash_damage 1 +#define player_gun_damage 10 #define player_health 8 #define player_special_hits 4 #define player_hurt_freeze 4 diff --git a/obj.h b/obj.h index 4f7d57e..ad7098c 100644 --- a/obj.h +++ b/obj.h @@ -44,6 +44,16 @@ void update_player( ); void ren_player(const Player* p, struct Renderer* r); +typedef struct { + int x, y, w; + int life; +} Laser; + +void init_laser(Laser* l); +void activate_laser(Laser* l, int x, int y); +void update_laser(Laser* l); +void ren_laser(const Laser* l, struct Renderer* r); + typedef struct { int x, y; int frame, anim; diff --git a/player.c b/player.c index 26a333e..b3a1d00 100644 --- a/player.c +++ b/player.c @@ -178,6 +178,25 @@ void update_player_hurt(Player* p, World* w) { } } +void update_player_special(Player* p, const App* a, World* w) { + if (p->charge < player_special_hits) return; + if (!btn_just_pressed(a, btn_special)) return; + if (p->spec == special_gun) { + int sx; + Rect dz = { 0, 0, 500, 16 }; + if (p->face == face_left) + sx = (p->x >> fbits) - dz.w; + else + sx = (p->x >> fbits) + 16; + dz.x = sx; + dz.y = (p->y >> fbits); + inst_deathzone(w, &dz, 0, 0, player_gun_damage, 1, 1); + activate_laser(&w->laser, dz.x, dz.y); + w->freeze = 3; + } + p->charge = 0; +} + void update_player( Player* p, World* w, @@ -185,6 +204,7 @@ void update_player( const Map* map ) { update_player_move(p, app, w); + update_player_special(p, app, w); update_player_hurt(p, w); update_player_phys(p, map); update_player_anim(p); @@ -195,3 +215,41 @@ void ren_player(const Player* p, struct Renderer* r) { if (p->inv & 5) return; ren_map(r, p->x >> fbits, p->y >> fbits, &p->rect, b); } + +void init_laser(Laser* l) { + l->life = 0; +} + +void activate_laser(Laser* l, int x, int y) { + l->life = 10; + l->x = x; + l->y = y; +} + +void update_laser(Laser* l) { + l->life--; +} + +void ren_laser(const Laser* l, struct Renderer* r) { + const int h = 10; + const int hr = h - l->life; + const int hr2 = hr >> 1; + Rect re; + re.x = l->x; + re.y = l->y + hr2; + re.w = 500; + re.h = 10 - hr; + ren_rect(r, &re); + re.h = 1; + re.y = l->y - hr2; + ren_rect(r, &re); + re.h = 1; + re.y = l->y + h + hr2; + ren_rect(r, &re); + re.h = 1; + re.y = l->y - hr; + ren_rect(r, &re); + re.h = 1; + re.y = l->y + h + hr; + ren_rect(r, &re); +} diff --git a/world.c b/world.c index fc137ee..b1f73ec 100644 --- a/world.c +++ b/world.c @@ -8,6 +8,7 @@ void init_world(World* w) { w->frame = 0; w->freeze = 0; init_player(&w->player); + init_laser(&w->laser); } Particle* inst_particle( @@ -55,6 +56,8 @@ Deathzone* inst_deathzone( void update_world(World* w, const App* a) { int i; + if (w->laser.life) + update_laser(&w->laser); if (w->freeze) { w->freeze--; return; @@ -80,5 +83,7 @@ void ren_world(const World* w, struct Renderer* r) { ren_particle(&w->particles[i], r); for (i = 0; i < w->enemy_count; i++) ren_enemy(&w->enemies[i], r); + if (w->laser.life) + ren_laser(&w->laser, r); ren_hud(w, r); } diff --git a/world.h b/world.h index d691a6a..05372ae 100644 --- a/world.h +++ b/world.h @@ -17,6 +17,7 @@ typedef struct World { int particle_count, enemy_count; int deathzone_count; Player player; + Laser laser; Map map; int frame, freeze; } World; -- cgit v1.2.3-54-g00ecf