Seite 1 von 1

Bunte Prozentualleite (schlecht definierbar)

Verfasst: 05.01.2005 21:52
von Kekskiller
Hab mal was aus meinem recht beliebten Blitzbasicspiel Tricorne einen
kleinen Code für bunte prozentuale Leisten, oder wie auch immer gemacht
und ihn in PB umportiert. Jetzt nicht erschwinglich, aber mir sehr wichtig für
ein alternatives, einfaches, aber doch ansprechendes Design mit Stil ^_^ .
Mag ich jedenfalls, verwende ich auch ganz gerne. Aber egal, hier der Code
mit Beispiel:

Code: Alles auswählen

;/ Comment
;Kleine Prozentleistenfunktion, fix, praktisch, pfiffig, frisch.
;Ok, das war jetzt gelogen, aber ist dennoch imho relativ brauchbar.
;- DrawBar(x,y, Breite,Höhe, Maximum,Anteil, Vordergrund,Hintergrund, Zentriert, Mudos)
; Die Leiste wird dem Modus entsprechend dargestellt (X=ausgefüllt O=leer):
;
;- Modus 0:
;  XXXOO
;- Modus 1:
;  X
;  X
;  X
;  O
;  O
;
; Falls man die Anzeigen spiegeln will, müsste man Vorder- und Hintergrundfarbe
; vertauschen und als Anteilwert nur vom Maximun den Anteil abziehen, siehe:
;- Ungespiegelt: Maximum, Anteil
;- Gespiegelt: Maximum, Maximum - Anteil
; Habe ich auch unten im Beispiel so dargestellt.

InitSprite()
InitKeyboard()
OpenScreen(640,480, 16, "Bar test")

;/ -- Declarations --

Declare DrawBar(x,y, width,height, max.f,part.f, fore,back, center, vertikal)
Declare UpdateBars()

#ScreenWidth = 640
#ScreenHeight = 480

Structure Bar
  value.l
  speedup.l
  dir.l
  speeddown.l
EndStructure

Global light.l
Global Font.l

Font = LoadFont(0, "Lucida Console", 9)

;/ -- Init --

Dim RgbValue.Bar(3)

RgbValue(0)\value = 200
RgbValue(0)\speedup = 20
RgbValue(0)\speeddown = 10

RgbValue(1)\value = 100
RgbValue(1)\speedup = 10
RgbValue(1)\speeddown = 5

RgbValue(2)\value = 50
RgbValue(2)\speedup = 5
RgbValue(2)\speeddown = 20

;/ -- Mainloop

Repeat
  ExamineKeyboard()
  UpdateBars()
  light = Int(255 * ( (RgbValue(0)\value + RgbValue(1)\value + RgbValue(2)\value) / (255 * 3) ))
  ClearScreen(0,0,0)
  
  StartDrawing(ScreenOutput())
  DrawBar(5,5, 100,5, 255,RgbValue(0)\value, RGB(255,100,100),RGB(100,0,0), 0, 0)
  DrawBar(5,12, 100,5, 255,RgbValue(1)\value, RGB(100,255,100),RGB(0,100,0), 0, 0)
  DrawBar(5,19, 100,5, 255,RgbValue(2)\value, RGB(100,100,255),RGB(0,0,100), 0, 0)
  DrawBar(110,5, 5,19, 255,255-light, RGB(100,100,100),RGB(255,255,255), 0,1)
  
  DrawingMode(1)
  FrontColor(200,200,200)
  BackColor(0,0,0)
  DrawingFont(Font)
  Locate(5,26)
  DrawText(Str(light))
  StopDrawing()
  
  FlipBuffers()
  Delay(5)
Until KeyboardPushed(#PB_Key_Escape)

End

;/ --  Procedures --

;-- Update --

Procedure UpdateBars()
For z = 0 To 2
  Select RgbValue(z)\dir
    Case 0
      RgbValue(z)\value + RgbValue(z)\speedup
      If RgbValue(z)\value >= 255
        RgbValue(z)\value = 255
        #RgbValue(z)\speedup = Random(19) + 1
        RgbValue(z)\dir = 1
      EndIf
    Case 1
      RgbValue(z)\value - RgbValue(z)\speeddown
      If RgbValue(z)\value <= 0
        RgbValue(z)\value = 0
        RgbValue(z)\speedup = Random(19) + 1
        RgbValue(z)\dir = 0
      EndIf
  EndSelect
Next
EndProcedure

;-- Bar --

Procedure DrawBar(x,y, width,height, max.f,part.f, fore,back, center, vertikal)
  If center = 1
    x = x - (width / 2)
    y = y - (height / 2)
  EndIf
  
  If x <= 0 : x = 0 : EndIf
  If y <= 0 : y = 0 : EndIf
  
  If x + width >= #ScreenWidth-1
    x = #ScreenWidth-1 - width
  EndIf
  If y + height >= #ScreenHeight-1
    y = #ScreenHeight-1 - height
  EndIf
  
  Select vertikal
    Case 0
      partw = (part * width) / max
      Box(x,y, width,height, back)
      Box(x,y, partw,height, fore)
    Case 1
      parth = (part * height) / max
      Box(x,y, width,height, back)
      Box(x,y, width,parth, fore)
  EndSelect
EndProcedure

Verfasst: 05.01.2005 22:46
von vonTurnundTaxis
Aha.. das schaut ja interessant aus! Wenn man das jetzt grafisch (irgendwie) aufbereiten würde...
Klasse! :allright:

Verfasst: 05.01.2005 22:58
von Kekskiller
Ich hatte ja schon die Überlegung, abgerundete Ecken und ein wenig AA reinzumachen,
aber das ist nicht wirklich so sinnvoll bei solch kleinen Boxen :D .
Hatte die Dinger mal bei Metroid Prime entdeckt und wollte daher kopieren,
die benutzen aber 3D-Sprites, also wird das nichts...

Verfasst: 05.01.2005 23:21
von Kaeru Gaman
wirklich schick, schön einfach...

mir sprites kann man sowas auch machen:
einen sprite für den background, vielleicht auch mit rahmen,
den anderen spriten clippen und darüber.
wenn man rechtsbündig clipped, und linksbündig darstellt,
verschiebt sich die texture mit...