countdown timer
Blitz3D Forums/Blitz3D Programming/countdown timer
| ||
| anyone know how to create a visible countdown timer in B3D??? You know like a stopwatch? I mean:
game_start=millisecs()
if game_end>=game_start+60000 then ; one minute lets say
;do something
endif
But how can you show this... Do you update the angle of the clock hand with some sort of math???-RZ |
| ||
| Displaying a stopwatch will require some hand made graphics plus some maths. If you make a full turn of the clock equal your allowed game time, then divide the time elapsed so far by 360 to get your angle. Thats just the maths, you will also need to create graphics for your stopwatch plus a hand that can be moved and overlayed on the watch. A simpler method would be a progress bar overlayed as 2D, with the length of the bar equal to the time into the game. GameEnd = Millisecs + (60 * 1000) While ... Renderworld() length = ( GameEnd - Millisecs() ) / 1000 Color(255,0,0) rect(10,10, 10, length, True) Flip Wend Errr, you would need to finese that code a bit - like add a border by using an unfilled (not solid) rectangle etc. Also, not tested or anything, just a basic outline!! Rhy Out |
| ||
| ..an even easier method would to display the timer as a number!! Rhy Out |
| ||
| EDITT### I fixed it... works well now... counts off the seconds (360 radius circle / 60 seconds = 6 degrees... Lookie!
; countdown clock
; by Ralph Dunn
Graphics3D 800,600,16,2
SetBuffer BackBuffer()
SeedRnd(MilliSecs())
player=CreatePivot()
camera=CreateCamera(player)
light=CreateLight()
RotateEntity light,45,45,0
AmbientLight 48,48,48 ; was 32,32,32
EntityType camera,1
PositionEntity camera,0,90,8
RotateEntity camera,90,0,0
Global clock=LoadSprite("clock1.png",4) ; essentially a circle but I made mine cool
ScaleSprite clock,8,8
Global hand=LoadSprite("clock3.png",4) ; the hand of the clock... made an arrow
ScaleSprite hand,7,7
; ##### Both images were created as PNGs with BLACK backgrounds so they would be ignored
; by Blitz3D did that for my game
PositionEntity clock,0,0,0 ; for now pop it in the middle
PositionEntity hand,0,0,0
start=MilliSecs()+1000 ; get initial clock value
ang=6 ; get initial angle to rotate hands
While Not KeyDown(1)
UpdateWorld
RenderWorld
; note where code is... I may try to function this later
Text 0,10,""+MilliSecs()
Flip
If MilliSecs() >= start Then ; check if 1 second has passed
RotateSprite hand,ang ; if so... rotate the hand
ang=ang+6 ; IF ang = ang -6 clock goes other direction
start=MilliSecs()+1000 ; get new value for checking
EndIf
Wend
End
I hope this helps everyone else. :]-Rook Zimbabwe |