Doubble Functions?

Blitz3D Forums/Blitz3D Beginners Area/Doubble Functions?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

http://www.blitzbasic.com/faq/faq_entry.php?id=2

Graphics 640,480,0,2
SetBuffer BackBuffer()

Global Timer, Finish
Global GameTime = 60000 ; 1 minute
Global EndGame = False

Global ball1 = CreateImage(32,32)
	SetBuffer ImageBuffer(ball1)
		Color 255,0,0
		Oval 0,0,32,32,True
		Color 255,255,255
	SetBuffer BackBuffer()

Type player
	Field X
	Field Y
	Field XOffset#
	Field YOffset#
End Type

Global Player1.Player = New Player
	Player1\X = 100
	Player1\Y = 100
	Player1\XOffset = 0
	Player1\YOffset = 0


;Start
Flip
Cls

Text 0,0,"Press any key to start"

Flip
FlushKeys()
WaitKey


;INITIALIZE VARIABLES
Finish = MilliSecs() + GameTime

Timer = 0




;MAIN LOOP
While Not EndGame

CheckControls()
UpdatePlayer()
DrawPlayer()
Timer()

Flip ;flip the current drawing buffer to the front and set current buffer to the other (i.e. if current buffer is back then switch to front, and vice versa)
Cls  ;clear the current buffer

Wend 


;END MAIN LOOP




Flip
Cls

Text 0,0,"The game has ended, press any key to quit"

Flip
FlushKeys()
WaitKey

End 
;END PROGRAM







;FUNCTION CheckControls
Function CheckControls()


;Player1 controls
If KeyDown(200) ;up
	Player1\YOffset = Player1\YOffset -.5
	If Player1\YOffset <-10 Then Player1\YOffset= -10
EndIf

If KeyDown(208) ;down
	Player1\YOffset = Player1\YOffset + .5
	If Player1\YOffset >10 Then Player1\YOffset= 10
EndIf

If KeyDown(203) ;left
	Player1\XOffset = Player1\XOffset -.5
	If Player1\XOffset < -10 Then Player1\XOffset= -10
EndIf

If KeyDown(205) ;right
	Player1\XOffset = Player1\XOffset + .5
	If Player1\XOffset >10 Then Player1\XOffset = 10
EndIf



If KeyDown(1) Then EndGame = True

End Function



;FUNCTION DrawPlayer
Function DrawPlayer()
	For p.Player = Each Player
		DrawImage ball1, p\X, p\y
	Next
End Function



;FUNCTION UpdatePlayer
Function UpdatePlayer()
	For p.Player = Each Player

		;Check bounds
		If p\Y < 0 Then 
			p\YOffset = -p\YOffset
			p\Y = 0
		EndIf
		
		If p\Y > GraphicsHeight()-32 Then 
			p\YOffset = -p\YOffset
			p\Y = GraphicsHeight()-32
		EndIf
		
		If p\X < 0 Then 
			p\XOffset = -p\XOffset
			p\X = 0
		EndIf
		If p\X > GraphicsWidth()-32 Then
			p\XOffset= -p\XOffset
			p\X = GraphicsWidth()-32
		EndIf


		p\X = p\X + p\XOffset
		p\Y = p\Y + p\YOffset


		If p\XOffset > 0 Then 
			p\XOffset = p\XOffset - 0.1
		EndIf

		If p\XOffset < 0 Then
			p\XOffset = p\XOffset + 0.1
		EndIf

		If p\YOffset > 0 Then 
			p\YOffset = p\YOffset - 0.1
		EndIf

		If p\YOffset < 0 Then
			p\YOffset = p\YOffset + 0.1
		EndIf


	Next
End Function




;FUNCTION Timer
;---------------------------------------------------------------------
Function Timer()

minutes = Floor((Finish - MilliSecs() )/60000)
seconds = Ceil(((Finish - MilliSecs() ) - minutes*60000)/1000)

If seconds < 10 Then
	Text 0 , 0 , minutes + ":0" + seconds
Else
	Text 0 , 0 , minutes + ":" + seconds
End If

If MilliSecs() > Finish Then EndGame = True

End Function 


It's not the same code you posted, but it demonstrates the steps necessary to get it functioning correctly.