REM *********************************************** REM Title: Energy Meter REM Author: Phaelax REM Downloaded from: http://dbcc.zimnox.com/ REM *********************************************** rem current amount of hit points current = 37 rem maximum number of hit points max = 78 sync on sync rate 40 do cls energyBar(mousex()-100, mousey()-8, current, max, 200, 16) rem control current health amount if rightkey() then inc current if leftkey() then dec current if current > max then current = max if current < 0 then current = 0 sync loop REM ================================================ REM X,Y = position of health meter REM Current = current number of hit points REM Max = maximum number of hit points REM MeterLength = width of the health meter REM MeterHeight = height of the health meter REM ================================================ function energyBar(x, y, current#, max, meterLength, meterHeight) ink rgb(30,30,30),0 box x,y,x+meterLength,y+meterHeight T# = current#/max C = meterLength*T# ink rgb(255,0,0),0 color1 = rgb(255,0,0) color2 = getTransitionalColor(color1,rgb(0,255,0),T#) box x, y, x+C, y+meterHeight,color1,color1,color2,color2 ink rgb(255,255,255),0 text x, y, str$(current#) text x+meterLength-16, y, str$(max) endfunction REM ************************************************** REM Returns a linear interpolated color between base REM color and target color. Percent ranges from 0 to 1 REM ************************************************** function getTransitionalColor(base, target, percent#) br = rgbr(base) bg = rgbg(base) bb = rgbb(base) tr = rgbr(target) tg = rgbg(target) tb = rgbb(target) tr = br + (tr-br)*percent# tg = bg + (tg-bg)*percent# tb = bb + (tb-bb)*percent# color = rgb(tr,tg,tb) endfunction color