I didn't find anything like this posted here, so:
Rem Project: Sprite Score
Rem Created: 1/19/2008 11:25:04 AM
rem Updated: 1/19/2008 05:40:00 PM
rem Updated: 1/19/2008 09:47:00 PM
rem Updated: 1/23/2008 10:57:00 AM multi players
sync on : sync rate 0
color backdrop rgb(0,0,128) : hide mouse
set text font "arial" : set text size 12 : set text transparent
autocam off
rem variables used in calling the score functions
rem explanations for these variables precede the function calls
score_max_digits=6
score_players=4
score_size=96
score_padcr=12
score_digit_color=RGB(255,255,0)
score_background_color=RGB(0,0,0)
score_translucent=128
score_digit_blur=3
rem arrays used to store score digits, score sprite pointers and the digit images
dim Digit_pointer(score_max_digits,score_players+1)
dim Score_digits(12)
rem variables used in demo to position and limit the score
rem with score_xpos<0 the score will center on the screen
rem else the score will position using the first two variables
score_xpos=-1
score_ypos=0
demo_limit=9999
astrisk=11
rem test for bad values in demo variables
rem this test is for the demo only, I don't want it to crash
rem this probably is not a complete test
n=demo_limit
p=0
while n>0
inc p
n=n/10
endwhile
if p=0 or p+1>score_max_digits or score_padcr>12 or score_size>128
cls
center text screen width()/2,screen height()/2, "Re-set your parameters and try again"
sync:sync
wait key
end
endif
rem center the score if score_xpos<0
if score_xpos<0
score_xpos=(screen width()-((score_size/2)*score_max_digits))/2
score_ypos=(screen height()-((score_size+4)*score_players))/2
endif
rem this is the call to the function that creates the digit images
rem and the digit sprites.
rem calling variables:
rem score_size is the font size of the score images
rem score_max_digits is the number of digits in your score
rem score_players is the number of scores to display
rem score_digit_color is the color of your score digits
rem score_background_color is the background color of your score digit
rem if all rgb numbers of this variable are less than 16 the background will be transparent
rem score_digit_blur is an attempt to give your score a little texture
rem 0=no effect. Larger numbers will make the image softer
rem values greater than 9 seem to have no effect
rem general rule: smaller digit use less blur
rem score_translucent is the transparency of your score
rem 0=invisible
rem 255=solid
rem
Make_score_digits(score_size,score_max_digits,score_players,score_digit_color,score_background_color,score_digit_blur,score_translucent)
rem something to show the transparency feature
make object sphere 1,10
color object 1,rgb(127,0,127)
position camera 0,0,0,-25
point camera 0,0,0,0
rem need a least one player
player=1
rem lets start with a negative score
rem to show how it can be handled
score_00=-1*demo_limit
leading=score_padcr
rem demo loop - show some digits
repeat
inc score_00,1
rem in this demo, minus scores are padded with astrisks
rem numbers zero and up are padded with spaces
score=abs(score_00)
score_padcr=leading*(score_00=>0)+astrisk*(score_00<0)
rem now call the function that shows the score
rem calling variables:
rem player
rem score is the score you wish to display
rem score_padcr is the pointer to the pad character for leading zeros
rem 1 points to "0"
rem 11 points to "*"
rem 12 points to " "
rem score_size is the font size of the score images
rem score_max_digits is the number of digits in your score
rem score_xpos is the x position of your score on the screen
rem score_ypos is the y position of your score on the screen
rem
`Show_score(player,score,score_padcr,score_size,score_max_digits,score_xpos,score_ypos)
rem the original function call has been commented out and a new call put in a loop to
rem show all players
for i=1 to score_players
player=i
Show_score(player,score/i,score_padcr,score_size,score_max_digits,score_xpos,score_ypos+((i-1)*(score_size+4)))
next i
text 0,0,"fps: "+str$(screen fps())
sync
until score=>demo_limit
end
function Make_score_digits(fsize,digits,players,scolor,bcolor,blr,strans)
rem save some existing conditions
cls
b=text background type()
t=text size()
dot 1,1
ct=point(1,1)
cb=point(1,2)
rem image creation starts here
bm=0
repeat
inc bm,1
until bitmap exist(bm)=0
create bitmap bm,fsize/2,fsize
set text size fsize
set text opaque
for i=1 to 12
cls rgb(0,0,0)
ink bcolor,bcolor `have to force the background color because
box 0,0,fsize/2,fsize `the astrisk and space won't fill image area
ink scolor,bcolor
set cursor 0,0
print mid$("0123456789* ",i)
blur bitmap bm,blr
p=0
repeat
inc p,1
until image exist(p)=0
Score_digits(i)=p
get image Score_digits(i),0,0,fsize/2,fsize
next i
delete bitmap bm
rem restore previous conditions
ink ct,cb
set text size t
if b=0
set text transparent
endif
cls
rem create sprites here so they won't have to be created on the fly
for plrs=2 to players+1
for i=1 to digits
p=0
repeat
inc p,1
until sprite exist(p)=0
Digit_pointer(i,plrs)=p
sprite Digit_pointer(i,plrs),i*fsize/2,screen height()/2,Score_digits(1)
set sprite priority Digit_pointer(i,plrs),1
set sprite alpha Digit_pointer(i,plrs),strans
next i
next plrs
endfunction
function Show_score(player,score,pad,fsize,digits,xpos,ypos)
rem reset digit pointers just incase of a large subtraction
rem set to zero
for i=1 to digits
Digit_pointer(i,1)=0
next i
rem put the score digits into array
n=score
p=0
while n>0
inc p,1
Digit_pointer(p,1)= n mod 10
n=n/10
endwhile
rem display the score
for i=1 to digits
if (digits+1)-i>p
rem pad
sprite Digit_pointer(i,player+1),xpos+(i-1)*(fsize/2),ypos,Score_digits(pad)
else
rem digit
sprite Digit_pointer(i,player+1),xpos+(i-1)*(fsize/2),ypos,Score_digits(Digit_pointer((digits+1)-i,1)+1)
endif
next i
endfunction
I hope someone finds this useful.
Update: translucent score
Update 2: Changed a variable name for clarity. Additions to demo to show astrisks padding negative numbers. Fixed a potential crash problem in sprite creation.
Update 3: Multi-player
Whatever...