aboutsummaryrefslogtreecommitdiff
path: root/player.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-10-02 18:47:37 +1000
committerquou <quou@disroot.org>2024-10-02 18:47:37 +1000
commit4d94823a1523db6dc218bdc0d86689616c13599d (patch)
treecfc6dc5bf3cbfff9c0a31b7939441d86116eff29 /player.c
parent911f57c63ec6de6fb5704c97130b65e676b2c16e (diff)
Gun special
Diffstat (limited to 'player.c')
-rw-r--r--player.c58
1 files changed, 58 insertions, 0 deletions
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);
+}