From eed7b6af8795f4a9393dd3c25ddc30d17eef4b30 Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sun, 26 Jan 2025 13:07:43 -0800 Subject: [PATCH] unique bullet base instances peel off new copies of ammo when using a new gun so we can upgrade it without screwing up the base stats --- vacuum_gambit.p8 | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/vacuum_gambit.p8 b/vacuum_gambit.p8 index 817edad..acde9a9 100644 --- a/vacuum_gambit.p8 +++ b/vacuum_gambit.p8 @@ -126,8 +126,7 @@ end function _init() mode = game_mode init_blip_pals() - wipe_level() - primary_ship.main_gun = zap_gun_p.new() -- redundant? + wipe_game() -- redundant? load_level(example_level_csv) game_state = game pal(2,129) @@ -157,7 +156,7 @@ function init_hpcols() hpcols = hpcols_lut[min(primary_ship.maxhp,6)] end -function wipe_level() +function wipe_game() xpwhoosh = nil primary_ship = player.new() init_hpcols() @@ -170,6 +169,8 @@ function wipe_level() intangibles_bg = linked_list.new() events = linked_list.new() new_events = linked_list.new() + primary_ship.main_gun = zap_gun_p.new() + primary_ship.main_gun:peel() end function _update60() @@ -689,6 +690,7 @@ gun_base = mknew{ -- themselves to the player function gun_base:action() local item = self.new() + item:peel() item.ammo = item.maxammo if not primary_ship.special_guns then primary_ship.special_guns = {item} @@ -697,6 +699,19 @@ function gun_base:action() end end +-- make shot type unique so +-- stat modifications do not +-- damage base data +function gun_base:peel() + self.munition = self.munition.new() +end + +-- default firing behavior: +-- single shot +function gun_base:actually_shoot(x, y) + self.munition.new{}:spawn_at(x, y) +end + function bullet_base:hitship(_) self:die() return true @@ -720,14 +735,6 @@ function bullet_base:draw() spr(self.sprite, self.x, self.y, self.width, self.height) end --- An `actually_shoot` factory --- for trivial guns -function spawn_one(t) - return function(gun, x, y) - t.new{}:spawn_at(x, y) - end -end - function bullet_base:spawn_at(x, y) self.x = x - self.x_off self.y = y - self.y_off @@ -780,11 +787,11 @@ zap_p = mknew(zap_e.new{ zap_gun_e = mknew(gun_base.new{ cooldown = 0x0.0020, -- frames between shots - actually_shoot = spawn_one(zap_e), + munition = zap_e, }) zap_gun_p = mknew(zap_gun_e.new{ - actually_shoot = spawn_one(zap_p), + munition = zap_p, hdr = "mAIN gUN", }) @@ -843,7 +850,7 @@ blast_gun = mknew(gun_base.new{ cooldown = 0x0.0078, -- 120 frames between shots ammo = 5, maxammo = 5, - actually_shoot = spawn_one(blast), + munition = blast, hdr = "bLASTER", body= [[plasma orb cuts through