Health Percentage Function by Whyillohw26th Jun 2004 5:46
|
---|
Summary A Function to help with Health Bars ect. in DBPro Description This function is a very simple and flexible little addition to any program requiring percentage feedback of some sort or another. All the variables are simple a-b-c-a$-b# and so on. Feel free to use this code whenever and wherever. Its all yours for free. Oh yeah and by the way, the stuff above the function was how it all started so I figured it might come in handy if you run into problems understanding my function. It is also to show the usage of color I added to it. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com black=rgb(0,0,0) red=rgb(255,0,0) yellow=rgb(255,255,0) white=rgb(255,255,255) start: cls randomize timer() hp2#=rnd(9998)+1 hp1#=rnd(hp2#) hpper#=hp1#/hp2# hpper=percent(hpper#) hpper$=str$(hpper)+"%" hp1$=str$(hp1#) hp2$=str$(hp2#) hp12$=hp1$+"/"+hp2$ if hpper<25 or hpper=25 then ink yellow,black if hpper>20 then ink white,black if hpper<=0 then ink red,black center text screen width()/2,2,hp12$ center text screen width()/2,15,hpper$ ink white,black line (screen width()/2)-55,30,(screen width()/2)+55,30 line (screen width()/2)-55,30,(screen width()/2)-55,50 line (screen width()/2)-55,50,(screen width()/2)+55,50 line (screen width()/2)+55,30,(screen width()/2)+55,51 ink red,black box (screen width()/2)-50,35,((screen width()/2)-50)+hpper,45 suspend for key if inkey$()="q" then exit goto start function percent(a#) a$=str$(a#) b$=mid$(a$,1) b=val(b$) if b<1 a=len(a$) a$=right$(a$,a-2) b$=mid$(a$,1) if b$="0" b$=mid$(a$,2) b=val(b$) if b>4 then goto notzero b$=mid$(a$,3) b=val(b$) if b>4 then goto notzero perval=0 goto funcend endif notzero: b$=mid$(a$,3) a$=left$(a$,2) a=val(a$) b=val(b$) if b>4 a=a+1 endif b$=mid$(a$,4) b=val(b$) if b>4 a=a+1 endif a$=str$(a) perval=val(a$) goto funcend endif if b>1 or b=1 hund$=str$(b) a=len(a$) a$=right$(a$,a-2) b$=mid$(a$,3) a$=left$(a$,2) a=val(a$) b=val(b$) if b>4 a=a+1 endif b$=mid$(a$,4) b=val(b$) if b>4 a=a+1 endif a$=str$(a) a$=hund$+a$ perval=val(a$) endif funcend: endfunction perval |