Improved Starfield !!

BlitzMax Forums/BlitzMax Programming/Improved Starfield !!

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.

It's really the same suggestion as SSwift :
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(2,8)
		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
		myrnd:Float=Rnd(0.8,1.4)
		SetScale myrnd,myrnd
		SetBlend lightblend
		SetAlpha rnd(0.2,0.8)
		DrawOval x,y,size,size
	End Method
	'----------------------------------------
	Method update()
	End Method
	'----------------------------------------
	Function generate()
		For star% = 1 To 1000
			New TStar.Create() 
		Next
	End Function
End Type


Thought it would look better than that though.