ShapeEntity System

Blitz3D Forums/Blitz3D Beginners Area/ShapeEntity System

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.

Hi, there!

I am currently working on a ShapeEntity System that will simplify (hopefully) the creation of vector games.

Here are the engine files (kline.bb, kShape.bb, glow.png, no example):
http://www.kochonet.com/kSES/kSES.zip

This is an alpha version with lot of missing functions, surely a bunch of bugs and no help files. The best way to learn it is to download separate examples and post your questions here.

latest example showing you how it's easy to make a simple asteroids clone:


The source:
Include "kShape.bb"

; FrameTiming Globals
;=========================================================================
Global fps
Global fps_count
Global fps_mil

; Initialisation
;=========================================================================
Graphics3D 640, 480, 32, 2
SetBuffer BackBuffer()

Global cam = CreateCamera()
Global dl = kDL_Create(cam, True, True, "glow.png")
kDL_Area(dl, 660, 500)

SeedRnd MilliSecs()

; Shapes Creation
;=========================================================================
Global shp_ship.kShape = kCreateShape() 
kBeginShape(shp_ship)
kShapeAdd(0, -10)
kShapeAdd(10, 10)
kShapeAdd(0, 0)
kShapeAdd(-10, 10)
kEndShape(True)

Global shp_grid.kShape = kCreateGridShape(0, 0, 640, 480, 10, 10)
Global shp_bullet.kShape = kCreatePixShape(0, 0)

Global shp_ast_big.kShape = kCreateCircleShape(0, 0, 40, 7)
Global shp_ast_medium.kShape = kCreateCircleShape(0, 0, 30, 6)
Global shp_ast_small.kShape = kCreateCircleShape(0, 0, 20, 5)

Global shp_planet.kShape = kCreateCircleShape(0, 0, 300, 32)

; ShapeEntities Creation and Settings
;=========================================================================
Global timer% ; timer = kSE_Create(null, dl) -> kSE_LifeTime(timer, 150) -> kSE_Exists(timer)
			  ; This way you can easily create and control timers.

Global ship = kSE_Create(shp_ship, dl)
kSE_WrapMode(ship, 3)
kSE_Thickness(ship, 1.8)
kSE_Position(ship, 320, 240)
kSE_SetFriction(ship, 0.995)
kSE_Alpha(ship, 0)

Global grid = kSE_Create(shp_grid, dl)
kSE_Color(grid, 0, 0, 255)
kSE_Thickness(grid, 0.35)

Global planet = kSE_Create(shp_planet, dl)
kSE_Position(planet, 0, 0)
kSE_Color(planet, 255, 128, 255)
kSE_Thickness(planet, 0.5)
kSE_RotSpeed(planet, 0.01)

; Tag Lists
;=========================================================================

Global taglist1 = kSE_CreateTagList()
Global taglist2 = kSE_CreateTagList()

; Main Loop
;=========================================================================
While Not KeyDown(1)
	kDL_Clear(dl)
	
	If KeyDown(203) Then
		kSE_Rotate(ship, kSE_GetAngle(ship) - 2.5)
	EndIf
	If KeyDown(205) Then
		kSE_Rotate(ship, kSE_GetAngle(ship) + 2.5)
	EndIf
	If KeyDown(200) Then
		kSE_PushByAngle(ship, kSE_GetAngle(ship), 0.03)
	EndIf
	If KeyHit(57) Then
		If kSE_Exists(ship) Then
			tmp = kSE_Create(shp_bullet, dl)
			kSE_MoveTo(tmp, ship)
			kSE_Color(tmp, 255, 0, 0)
			kSE_LifeTime(tmp, 50)
			kSE_Dir(tmp, kSE_GetAngle(ship))
			kSE_Speed(tmp, 8)
			kSE_MoveFront(tmp, 10)
			kSE_Thickness(tmp, 3)
			kSE_WrapMode(tmp, 3)
			kSE_SetTag(tmp, "BULLET")
		Else
			If kSE_Exists(timer) = False Then
				ship = kSE_Create(shp_ship, dl)
				kSE_WrapMode(ship, 3)
				kSE_Thickness(ship, 1.8)
				kSE_Position(ship, 320, 240)
				kSE_SetFriction(ship, 0.995)
				kSE_Alpha(ship, 0)
			EndIf
		EndIf
	EndIf
	
	kSE_FillTagList(taglist1, "ASTEROID")
	If kSE_TagListSize(taglist1) <> 0 Then
		kSE_FillTagList(taglist2, "BULLET")
	
		For n = 1 To kSE_TagListSize(taglist2)
			bullet_tmp = kSE_TagItem(taglist2, n)
			For o = 1 To kSE_TagListSize(taglist1)
				ast_tmp = kSE_TagItem(taglist1, o)
				If kSE_PointInShape(ast_tmp, kSE_GetPosX(bullet_tmp), kSE_GetPosY(bullet_tmp)) = True Then 	
					kSE_Free(bullet_tmp)
					Select kGetParam(kSE_GetTag$(ast_tmp))
						Case "BIG"
							kSE_Thickness(ast_tmp, 10)
							kSE_SubDivide(ast_tmp)
							kSE_TrailMode(ast_tmp, True)
							For i= 1 To 3
								tmp = kSE_Create(shp_ast_medium, dl)
								kSE_MoveTo(tmp, ast_tmp)
								kSE_Alpha(tmp, kSE_GetAlpha(ast_tmp))
								kSE_Dir(tmp, Rnd(360))
								kSE_Speed(tmp, Rnd(0.75, 1.25))
								kSE_RotSpeed(tmp, Rnd(0.75, 1.25))
								kSE_WrapMode(tmp, 3)
								kSE_Thickness(tmp, 3)
								kSE_Color(tmp, 255, 128, 0)
								kSE_SetTag(tmp, "ASTEROID(MED)")
							Next
							kSE_Explode(ast_tmp, 50, 20)	
						Case "MED"	
							kSE_Thickness(ast_tmp, 10)
							kSE_SubDivide(ast_tmp)
							kSE_TrailMode(ast_tmp, True)
							For i= 1 To 3
								tmp = kSE_Create(shp_ast_small, dl)
								kSE_MoveTo(tmp, ast_tmp)
								kSE_Alpha(tmp, kSE_GetAlpha(ast_tmp))
								kSE_Dir(tmp, Rnd(360))
								kSE_Speed(tmp, Rnd(1, 1.5))
								kSE_RotSpeed(tmp, Rnd(1, 1.5))
								kSE_WrapMode(tmp, 3)
								kSE_Thickness(tmp, 2.8)
								kSE_Color(tmp, 255, 0, 0)
								kSE_SetTag(tmp, "ASTEROID(SMALL)")
							Next
							kSE_Explode(ast_tmp, 50, 15)	
						Case "SMALL"
							kSE_Thickness(ast_tmp, 10)
							kSE_SubDivide(ast_tmp)
							kSE_TrailMode(ast_tmp, True)
							kSE_Explode(ast_tmp, 100, 5)
					End Select		
					Exit
				EndIf
			Next
		Next
	Else
		For n = 1 To 3
			tmp = kSE_Create(shp_ast_big, dl)
			kSE_Position(tmp, Rnd(640), Rnd(480))
			kSE_Alpha(tmp, 0)
			kSE_Dir(tmp, Rnd(360))
			kSE_Speed(tmp, Rnd(0.5, 1))
			kSE_RotSpeed(tmp, Rnd(0.5, 1))
			kSE_WrapMode(tmp, 3)
			kSE_Thickness(tmp, 3.2)
			kSE_Color(tmp, 255, 255, 0)
			kSE_SetTag(tmp, "ASTEROID(BIG)")
		Next
	EndIf
	
	kSE_FillTagList(taglist1, "ASTEROID")
	
	alpha# = kSE_GetAlpha(ship)
	If alpha# < 1 Then
		alpha# = alpha# + 0.01
		kSE_Alpha(ship, alpha#)
	EndIf
	
	For n = 1 To kSE_TagListSize(taglist1)
		ast_tmp = kSE_TagItem(taglist1, n)
		alpha# = kSE_GetAlpha(ast_tmp)
		If alpha# < 1 Then
			alpha# = alpha# + 0.01
			kSE_Alpha(ast_tmp, alpha#)
		Else
			If kSE_GetAlpha(ship) >= 1 Then
				col = False
				If kSE_PointInShape(ast_tmp, kSE_GetPosX(ship), kSE_GetPosY(ship)) = True Then
					col = True
				ElseIf kSE_Intersects(ship, ast_tmp) = True Then
					col = True
				EndIf
				If col = True Then
					kSE_Thickness(ship, 5)
					kSE_SubDivide(ship)
					kSE_Explode(ship, 200, 1)
					timer = kSE_Create(Null, dl)
					kSE_LifeTime(timer, 150)
				EndIf
			EndIf
		EndIf
	Next
	
	kSE_Update()
	lr = kSE_Render()
	RenderWorld
	
	; Info Output
	;---------------------------------------------------------------------
	FpsUpdate()
	Text 0, 0, "FPS: " + fps
	Text 0, 15, "Lines Rendered: " + lr
	Flip
Wend

; End of Program
;=========================================================================
End

; FrameTiming Function
;=========================================================================
Function FpsUpdate()
	If MilliSecs() > fps_mil + 1000 Then
		fps_mil = MilliSecs()
		fps = fps_count
		fps_count = 0
	Else
		fps_count = fps_count + 1
	EndIf
End Function


Link to the demo - exe/main source (library not yet included):
http://www.kochonet.com/kSES/vectoroids_example.zip

Previous examples:
- http://www.kochonet.com/kSES/trails_example.zip
- http://www.kochonet.com/kSES/usershape_example.zip
- http://www.kochonet.com/kSES/basic_example.zip

Working on more examples...