From 637eed1eb827be70b7f7f6b330708191a648cd61 Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sun, 26 Jan 2025 01:06:37 -0800 Subject: [PATCH] autofire and three guns --- vacuum_gambit.p8 | 63 ++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/vacuum_gambit.p8 b/vacuum_gambit.p8 index c650044..513471b 100644 --- a/vacuum_gambit.p8 +++ b/vacuum_gambit.p8 @@ -363,8 +363,8 @@ function drawhud() line(127,1,127,127,5) line(113,127) - draw_gun_info("❎",1,116,3,primary_ship.main_gun) - draw_gun_info("🅾️",1,116,29,primary_ship.special_gun) + draw_gun_info("❎",1,116,3,1) + draw_gun_info("🅾️",1,116,29,2) inset(114,57,119,118) rectfill(119,57,124,58,13) @@ -404,25 +404,26 @@ function drawhud() fillp(0) end -function draw_gun_info(lbl,fgc,x,y,gun) +function draw_gun_info(lbl,fgc,x,y,gn) dropshadow(lbl,x,y,fgc) inset(114,y+7,125,y+18) inset(114,y+20,125,y+24) - if(gun) then - spr(gun.icon,116,y+9,1,1) - --115 to 124 - ammo bar. round up - if gun.ammo == nil then - fillp(0xa5a5) - rectfill(115,y+21,124,y+23,0xea) - fillp(0) - elseif gun.ammo > 0 then - rectfill( - 115,y+21, - 115+flr(9*gun.ammo/gun.maxammo), - y+23,10) - else - line(118, y+22, 121, y+22, 2) - end + if (not primary_ship.special_guns) return + local gun = primary_ship.special_guns[gn] + if (not gun) return + spr(gun.icon,116,y+9,1,1) + --115 to 124 - ammo bar. round up + if gun.ammo == nil then + fillp(0xa5a5) + rectfill(115,y+21,124,y+23,0xea) + fillp(0) + elseif gun.ammo > 0 then + rectfill( + 115,y+21, + 115+flr(9*gun.ammo/gun.maxammo), + y+23,10) + else + line(118, y+22, 121, y+22, 2) end end @@ -554,11 +555,12 @@ end function ship_m:move() self:refresh_shield() - local dx, dy, shoot_spec, shoot_main = self:act() + local dx, dy, shoot_spec1, shoot_spec2 = self:act() dx = self:constrain(self.x, self.xmomentum, self.xmin, self.xmax, dx) dy = self:constrain(self.y, self.ymomentum, self.ymin, self.ymax, dy) - if (shoot_main) self:maybe_shoot(self.main_gun) - if (shoot_spec) self:maybe_shoot(self.special_gun) + self:maybe_shoot(self.main_gun) + if (shoot_spec1 and self.special_guns) self:maybe_shoot(self.special_guns[1]) + if (shoot_spec2 and self.special_guns) self:maybe_shoot(self.special_guns[2]) if (dx ~= 0 or dy ~= 0) spark(self.sparks, self.x + 4*self.size, self.y + 4*self.size, dx*2.5, dy*2.5, self.sparkodds) self.xmomentum = self:calc_velocity(self.xmomentum, dx) self.ymomentum = self:calc_velocity(self.ymomentum, dy) @@ -970,7 +972,7 @@ player = mknew(ship_m.new{ -- gun main_gun = nil, -- assign at spawn time - special_gun = nil, + special_guns = nil, fire_off_x = 4, -- offset where bullets come from fire_off_y = 0, @@ -1744,7 +1746,16 @@ function spawn_spec_gun_at(x, y, gunt) gun = gunt.new(), hitship = function(self, ship) if (ship ~= primary_ship) return false - ship.special_gun = self.gun + local specs = ship.special_guns + if specs == nil then + specs = {self.gun} + elseif #specs == 1 then + add(specs, self.gun) + else + specs[1]=specs[2] + specs[2]=self.gun + end + ship.special_guns = specs return true end, draw = function(self) @@ -1951,7 +1962,11 @@ function rearm_mode:update() -- todo: sound: rearm primary_ship.shield = primary_ship.maxshield -- todo: rewrite for three guns - if (primary_ship.special_gun) primary_ship.special_gun.ammo = primary_ship.special_gun.max_ammo + local specs = primary_ship.special_guns + if specs then + specs[1].ammo = specs[1].max_ammo + if (specs[2]) specs[2].ammo = specs[2].max_ammo + end primary_ship.hp = min(primary_ship.maxhp, primary_ship.hp + primary_ship.maxhp/2) primary_ship.xp -= primary_ship.xptarget / 2 else