From 0f7c7a810b01ea3e22ba4f0f3c05b81f3ce9ea32 Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sun, 1 Oct 2023 15:41:58 -0700 Subject: [PATCH] remove gradients from meters, make vertmeter segmented --- updatedshmup.p8 | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/updatedshmup.p8 b/updatedshmup.p8 index f318c33..cb28c6c 100644 --- a/updatedshmup.p8 +++ b/updatedshmup.p8 @@ -136,23 +136,8 @@ function once_next_frame(f) } end --- health gradients for 1..5 hp --- exactly, then all "more". -hpcols_lut = csv[[36 -34, 136 -34, 130, 136 -34, 34, 130, 136 -34, 34, 130, 130, 136]] - --- call after any change to maxhp --- configures health gradient -function init_hpcols() - hpcols = hpcols_lut[min(primary_ship.maxhp,6)] -end - function wipe_level() primary_ship = player.new() - init_hpcols() pships = linked_list.new() pships:push_back(primary_ship) eships = linked_list.new() @@ -321,7 +306,6 @@ function drawgame() drawhud() end -powcols=split"170,154,153,148,68" function drawhud() -- 112-and-right is hud zone rectfill(112, 0, 127, 127,0x56) @@ -334,17 +318,15 @@ function drawhud() dropshadow("pwr",114,59,1) inset(114,66,125,92) - fillp(0x5a5a) - vertmeter(115,67,124,91,primary_ship.power, primary_ship.max_power, powcols) + vertmeter(115,67,124,91,primary_ship.power, primary_ship.max_power, 9,8) dropshadow("h s",114,97,1) inset(114,104,125,125) line(119,105,119,124,119) line(120,105,120,125,85) - vertmeter(115,105,118,124,primary_ship.hp, primary_ship.maxhp, hpcols) - vertmeter(121,105,124,124,primary_ship.shield, primary_ship.maxshield,{204,220,221}) - fillp(0) + vertmeter(115,105,118,124,primary_ship.hp, primary_ship.maxhp, 8,3) + vertmeter(121,105,124,124,primary_ship.shield, primary_ship.maxshield,12,3) end function draw_gun_info(lbl,fgc,x,y,gun) @@ -369,20 +351,17 @@ function draw_gun_info(lbl,fgc,x,y,gun) end end -function vertmeter(x0,y0,x1,y1,val,maxval,cols) +function vertmeter(x0,y0,x1,y1,val,maxval,col,seg) if (val <= 0) return - local h = y1-y0 - local px = -flr(-(h*val)\maxval) - local ncols = #cols - local firstcol = ((h-px)*ncols\h)+1 - local lastbottom = y0+(h*firstcol\ncols) - rectfill(x0, y1-px, x1, lastbottom, cols[firstcol]) - for i=firstcol+1,ncols do - local bottom = y0+h*i\ncols - rectfill(x0,lastbottom,x1,bottom,cols[i]) - lastbottom = bottom - end + local h = y1-y0+1 + local per_seg = ceil((h+1)/seg) - 1 + local px = (h-seg+1)*val\maxval + while px > 0 do + rectfill (x0, y1-min(px, per_seg)+1, x1, y1, col) + px -= per_seg + y1 -= per_seg+1 end + end function inset(x0,y0,x1,y1) rectfill(x0,y0,x1,y1,0)