Awesome health bar by sneaky smith121st May 2006 22:35
|
---|
Summary This will be a simple health bar. will not work in u6 Description I have set it up to give an example. All you have to do is change variables to fit your needs. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com Remstart HEALTH BAR REVISED BY: SNEAKYSMITH12 Hold control key to make health rnd Otherwise toggle health using up and down keys This is highly based on scource code found in the codebase. remend black=rgb(0,0,0) red=rgb(255,0,0) yellow=rgb(255,255,0) white=rgb(255,255,255) green=rgb(0,255,0) hp1# = 50 Do cls randomize timer() if controlkey()=0 then gosub control if controlkey()=1 then gosub rndhealth hp2#=100 hpper#=hp1#/hp2# hpper=percent(hpper#) hp1$=str$(hp1#) hp2$=str$(hp2#) hp12$=hp1$+"/"+hp2$ gosub stats ink white,black liney(30,30) liney(50,50) linex(30,50) ink red,black box (screen width()/2)-50,35,((screen width()/2)-50)+hpper,45 suspend for key if inkey$()="q" then exit Loop End 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 function liney(y1#,y2#) line (screen width()/2)+55,y1#,(screen width()/2)-55,y2# endfunction function linex(y1#,y2#) line (screen width()/2)+55,y1#,(screen width()/2)+55,y2# line (screen width()/2)-55,y1#,(screen width()/2)-55,y2# endfunction stats: if hpper = 0 then ink white,black : Print "DEAD!" if hpper >=90 ink green,black endif if hpper<=30 and hpper>5 ink yellow,black endif if hpper<90 and hpper>30 ink white,black endif if hpper<=5 ink red,black endif center text screen width()/2,2,hp12$ return rndhealth: hp1#=rnd(hp2#) return control: if upkey() = 1 hp1# = hp1# + 1 endif if downkey() = 1 hp1# = hp1# - 1 endif return |