Code: Select all
#DarkGray = 3158064
Procedure DrawBar(X,Y,Width.f,Height,Value.f,MaxValue,Text$,FullColor,EmptyColor)
Protected Color
If Value > MaxValue: Value = MaxValue: EndIf
Color = RGB((Red(FullColor)-Red(EmptyColor))/MaxValue*Value+Red(EmptyColor), (Green(FullColor)-Green(EmptyColor))/MaxValue*Value+Green(EmptyColor), (Blue(FullColor)-Blue(EmptyColor))/MaxValue*Value+Blue(EmptyColor))
Box(X,Y,Width,Height,#Gray) ;Border
Box(X+1,Y+1,Width-2,Height-2,#DarkGray) ;Background
Box(X+1,Y+1,(Width-2) / MaxValue*Value,Height-2,Color) ;Bar
DrawText(X+Width/2-TextWidth(Text$)/2,Y+Height/2-TextHeight(Text$)/2,Text$,#White) ;Text
EndProcedure
Define Health = 200
InitKeyboard():InitSprite():OpenScreen(640,480,32,"Test")
Delay(1000)
Repeat
Delay(40): If Health: Health - 1: EndIf
FlipBuffers():ClearScreen(#Black)
If StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawBar(10,10,200,20,Health,200,"Health",#Green,#Red)
StopDrawing()
EndIf
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)