Neat, simple flash game...

Miscellaneous Forums/General Discussion/Neat, simple flash game...

This could either be a little competition of a community project... I opt for the latter personnaly... but then I would because I like to learn how to code!

Anyway... here's a starter for 10...

[edit] Updated! [/edit]

Graphics3D 800,600,32,1

SetBuffer BackBuffer()
camera = CreateCamera()
MoveEntity camera,0,0,-30

Global tBlob = BlobTexture()

Type Blob
	Field Mesh,xs#,ys#,Rad#,Exploding,Timer,r#,g#,b#,tr#,tg#,tb#
End Type

; Create some blobs
Global Cursor = 0 
Global Finished = False



; The Game!


Data 1,5,2,10,3,15,5,20,7,25,10,30,15,35,21,40,27,45,33,50,44,55,55,60,99,0


gmid = GraphicsWidth() / 2
score = 0

Repeat

Read Target,Blobs

If Target <> 99 Then
	Repeat
	
	Repeat
	Cls
	
	Text gmid ,20, "Total Blobs: " + Blobs,True
	Text gmid ,50, "Target : " + Target,True

	Text gmid ,150, "Click to start",True
	
	Flip
	
	If KeyHit(1) Then End
	Until MouseHit(1)
		
	BlobsLeft = Game(Blobs) 
	
	score = score + (blobs - BlobsLeft)
	
	
	Repeat
	Cls
	Text gmid ,20,"Total Blobs : " + blobs,True
	Text gmid ,40,"Blobs Left : " + BlobsLeft,True
	Text gmid ,60,"Blobs Blobbed : " + (blobs - BlobsLeft) + " / " + target,True
	Text gmid ,100, "Score : " + score,True
	
	Text gmid ,150,"Click to Continue",True
	
	Flip
	If KeyHit(1) Then End
	Until MouseHit(1)	
	
	
	Until target - (blobs-blobsleft) <= 0
EndIf

Until Target = 99	


; End of the game!


Function Game(Blobs)

	Finished = False
	Cursor = BlobCreate(0,0,1,True)
	
	For n=1 To Blobs
		BlobCreate(Rnd(-20,20),Rnd(-20,20),Rnd(1,2))
	Next
	
	ups=120
	period=1000/ups
	time=MilliSecs()-period
	
	; Main Loop
	Repeat
	Repeat
	elapsed=MilliSecs()-time
	Until elapsed
	tic=elapsed/period
	For k=1 To tic
		time=time+period
		ticks=ticks+1
	
		BlobUpdate()
		
		
		mx# = MouseXSpeed() / 20.0
		my# = -MouseYSpeed() / 20.0
		MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
		
		
		
		If Not finished Then
			b.blob = First blob
			If Not b\exploding Then TranslateEntity Cursor,mx,my,0
			If MouseHit(1) Then b\exploding = True
		Else 
			found = False
			For b.blob = Each blob
				If b\exploding Then found = True:Exit
			Next
			If Not found Then tick = True
		EndIf
		
		If tick Then timer = timer + 1
	Next
		
	RenderWorld
	
	Flip
	Until KeyHit(1) Or Timer = 500
	
	count = 0
	For b.blob = Each blob
		count = count + 1
		FreeEntity b\mesh
		Delete b
	Next
	
	Return count
	
End Function


Function BlobUpdate()
	Delta# = .01
	For b.blob = Each Blob
		If b\exploding Then
			b\ys = b\ys * .99
			b\xs = b\xs * .99
			b\timer = b\timer + 1
			
			If b\timer < 360 Then b\rad = b\rad + (Sin(b\timer)/50)
			If b\timer > 360 Then b\rad = b\rad * .9
					
			For bb.blob = Each blob
				If bb\exploding = False Then
					ed# = EntityDistance(bb\mesh,b\mesh)
					If ed < (b\rad + bb\rad) Then
						bb\exploding = True
						bb\tr = b\r
						bb\tg = b\g
						bb\tb = b\b
					EndIf
				EndIf
			Next
		EndIf
		
		
		TranslateEntity b\mesh,b\xs * Delta,b\ys * Delta,0
		If Abs(EntityX(b\mesh)) > 20 Then b\xs = - b\xs
		If Abs(EntityY(b\mesh)) > 20 Then b\ys = - b\ys
		
		b\r = b\r + ((b\tr - b\r) / 100)
		b\g = b\g + ((b\tg - b\g) / 100)
		b\b = b\b + ((b\tb - b\b) / 100)


		ScaleSprite b\mesh,b\rad,b\rad
		EntityColor b\mesh,b\r,b\g,b\b
		
		If b\exploding And b\rad < .1 Then
			FreeEntity b\mesh
			If b\mesh = cursor Then Finished = True
			Delete b
		EndIf
	Next
End Function

Function BlobCreate(x#,y#,size#,Cursor=False)
	b.blob = New Blob
	b\Mesh = CreateSprite()
	EntityTexture b\Mesh,tBlob
	b\xs = Rnd(-5,5) ;Units per second
	b\ys = Rnd(-5,5)
	b\rad = size
	b\r = 100 + (Rand(0,3)*50)
	b\g = 100 + (Rand(0,3)*50)
	b\b = 100 + (Rand(0,3)*50)
	If Cursor Then
		b\r  = 255
		b\g = 0
		b\b = 0
		b\xs = 0
		b\ys = 0
	EndIf
	
	EntityColor b\mesh,b\r,b\g,b\b
	
	b\tr = b\r
	b\tg = b\g
	b\tb = b\b
	
	EntityBlend b\mesh,3
	EntityFX b\mesh,1
	ScaleSprite b\mesh,b\rad,b\rad
	PositionEntity b\mesh,x,y,0
	b\exploding = False
	Return b\mesh
End Function

Function BlobTexture()

	i = CreateImage(256,256)
	t = CreateTexture(256,256)
	LockBuffer ImageBuffer(i)
	For x=-128 To 128
	For y=-128 To 128
		r = Sqr((x*x) + (y*y))
		If r<128 Then
			c = 255- (r*2)
			WritePixelFast x+128,y+128,(c Or (c Shl 8) Or (c Shl 16) Or ($ff000000)),ImageBuffer(i)
		EndIf
	Next
	Next
	UnlockBuffer ImageBuffer(i)
	
	CopyRect 0,0,256,256,0,0,ImageBuffer(i),TextureBuffer(t)
	FreeImage i
	
	Return t
End Function