do something for 10 seconds

Blitz3D Forums/Blitz3D Programming/do something for 10 seconds

Matty: This is what I had done... after the initial spinage you hit the spacebar and it does it again...
Graphics3D 800,600,32,1
SetBuffer BackBuffer()
Cls
SeedRnd MilliSecs()
; ########   SETUP PLACE HOLDERS FOR EULER ANGLES
Dim pit(10) ; PITCH
Dim rol(10) ; ROLL
Dim ya(10) ; YAW
Dim TurnRate#(4)
Dim WheelMesh(4)

Global stillspinning
Global turns
Global wheelnumber
; ########   LOAD THE ACCORDING EULER ANGLES FOR EACH NUMBER 0 - 9
pit(0)=72
pit(1)=71
pit(2)=38
pit(3)=0
pit(4)=-40
pit(5)=-70
pit(6)=-69
pit(7)=-39
pit(8)=0
pit(9)=39

rol(0)=180
rol(1)=0
rol(2)=0
rol(3)=0
rol(4)=0
rol(5)=0
rol(6)=180
rol(7)=180
rol(8)=180
rol(9)=-180

ya(0)=-180
ya(1)=0
ya(2)=0
ya(3)=0
ya(4)=0
ya(5)=0
ya(6)=-180
ya(7)=-180
ya(8)=-180
ya(9)=180
; ########   Create a camera so we can see it
camera=CreateCamera()
PositionEntity camera,21,0,-60
; ########   add some lightage
sun = CreateLight()
PositionEntity sun,835,1456,502
RotateEntity sun,80,0,-900
; ########   Load and position the meshes for the wheels already covered in Ult. Unwrap
Global mesh=LoadMesh( "wheel2.b3d" )
Global mesh2=CopyEntity(mesh)
Global mesh3=CopyEntity (mesh)
Global mesh4=CopyEntity (mesh)
PositionEntity mesh,0,0,0
PositionEntity mesh2,11,0,0
PositionEntity mesh3,22,0,0
PositionEntity mesh4,33,0,0
frame=LoadMesh("frame.b3d")
ScaleEntity frame,1.4,1,1
PositionEntity frame,21.5,1,-32

WheelMesh(1)=mesh
WheelMesh(2)=mesh2 ;this is using your already defined mesh/mesh2/mesh3/mesh4 entities but storing their handles in an array instead, easier to manipulate
WheelMesh(3)=mesh3
WheelMesh(4)=mesh4
; ########  Randomly position the wheel
wheel1=Rnd(0,9)
wheel2=Rnd(0,9)
wheel3=Rnd(0,9)
wheel4=Rnd(0,9)
	RotateEntity mesh,pit(wheel1),rol(wheel1),ya(wheel1)
	RotateEntity mesh2,pit(wheel2),rol(wheel2),ya(wheel2)
	RotateEntity mesh3,pit(wheel3),rol(wheel3),ya(wheel3)
	RotateEntity mesh4,pit(wheel4),rol(wheel4),ya(wheel4)
; ########  degrees per frame to turn higher number mean faster initial spin.
TurnRate#(1)=10.0+Rnd(-3.0,3.0) ;do the same for indexes 2-4
TurnRate#(2)=10.0+Rnd(-3.0,3.0)
TurnRate#(3)=10.0+Rnd(-3.0,3.0)
TurnRate#(4)=10.0+Rnd(-3.0,3.0)

Decay#=0.995  ;adjust to any value between 0.0 and 1.0 to change the rate at which they slow down, and therefore changing the amount of time taken for the wheels to come to rest.

; ################################################## START OF GAME LOOP
; While Not KeyHit(1)

Repeat


If HaveWheelsStopped = False Then
	For i=1 To 4
		TurnEntity WheelMesh(i),TurnRate#(i),0,0
			TurnRate#(i)=TurnRate#(i)*Decay
			If TurnRate#(i)<0.1 Then TurnRate#(i)=0
		If TurnRate#(i)<>0 Then HaveWheelsStopped=False
	Next
EndIf

If KeyHit(57)=True Then ; ########   WHACK THE SPACEBAR
TurnRate#(1)=10.0+Rnd(-3.0,3.0) ;do the same for indexes 2-4
TurnRate#(2)=10.0+Rnd(-3.0,3.0)
TurnRate#(3)=10.0+Rnd(-3.0,3.0)
TurnRate#(4)=10.0+Rnd(-3.0,3.0)

HaveWheelsStopped=False


	
EndIf

UpdateWorld()
RenderWorld()



numbershow=EntityPitch(mesh)
numberroll=EntityRoll(mesh)
numberyaw=EntityYaw(mesh)

If numberroll = 0 Then
   Select True
          Case ( numbershow > -17 And numbershow < 17)
               wheelnumber = 3
          Case ( numbershow > 18 And numbershow < 53)
               wheelnumber = 2

          End Select
EndIf

;wheelnumber = numbershow + numberroll + numberyaw / 90 + 90
;Text 0,0,"TrisRendered "+TrisRendered()
Text 0,10,"RUMBLE: "+wheel1+ " " +wheel2+" "+wheel3+" "+wheel4
Text 0,30,"Wheel1: "+EntityPitch#(mesh,True)
Text 0,42,"Wheel2: "+EntityRoll#(mesh,True)
Text 0,54,"Wheel3: "+EntityYaw#(mesh,True)
Text 0,66,"Wheel: "+wheelnumber



Flip

Until KeyDown(1)
; Wend     HaveWheelsStopped=True
End
; ############################################################ FUNCTIONS START
I like you new idea but you have to wait until the wheel slows down to almost 0 to get the number to pop up. I am going to work onm that. Have to read how you did it.

Looks FANTASTIC!!! Thank you.

{{ EDIT}} I did it by setting the turnrate like this:
For i=1 To 4
TurnEntity WheelMesh(i),TurnRate#(i),0,0 
If TurnRate#(i)>=0.1 Then TurnRate#(i)=TurnRate#(i)*Decay
yohoo = turnrate(1)
If TurnRate#(i)<2 Then 
That way it stops a little faster and results in much less heart attack causing stress waiting for your number to come up. : )
-RZ