Improved Starfield !!

BlitzMax Forums/BlitzMax Programming/Improved Starfield !!

@tonyg: Modified your version slightly.


Graphics 640,480
SeedRnd MilliSecs()
Tstar.generate()

While Not AppTerminate() And Not KeyHit(KEY_ESCAPE)
	TGameObject.updateall() 
	TGameObject.drawall( True )
Wend

Type TGameObject
	Global list:TList = CreateList()
	Field x#,y#
	Field r% , g% , b%, size%
	'----------------------------------------
	Method draw() 
	End Method
	'----------------------------------------
	Method update()
	End Method
	'----------------------------------------
	Function drawAll( clear% = False )
		If clear Then Cls
		For item:TGameObject = EachIn list
			item.draw() 
		Next
		Flip
	End Function
	'----------------------------------------
	Function updateAll() 
		For item:TGameObject = EachIn list
			item.update() 
		Next
	End Function
End Type

Type TStar Extends TGameObject
	'----------------------------------------
	Method Create:TStar() 
		x = Rand( 0, GraphicsWidth() )
		y = Rand( 0, GraphicsHeight() ) 
		r = Rand(128 , 255)
		g = Rand(128 , 255) 
		b = Rand(128 , 255)
		size = Rand(1,4)
		ListAddLast( list,Self )
	End Method
	'----------------------------------------
	Method draw() 
		SetHandle size/2,size/2
		SetScale 1.0,1.0
		SetBlend maskblend
		SetAlpha 1.0
		SetColor( r,g,b )
		DrawOval x,y,size,size

		SetHandle (size+2)/2,(size+2)/2
		myrnd:Float=Rnd(0.8,1.4)
		SetScale myrnd,myrnd
		SetBlend lightblend
		SetAlpha Rnd(0.2,0.8)
		DrawOval x,y,size+2,size+2
	End Method
	'----------------------------------------
	Method update()
	End Method
	'----------------------------------------
	Function generate()
		For star% = 1 To 1000
			New TStar.Create() 
		Next
	End Function
End Type