Linepick and slowdown

Blitz3D Forums/Blitz3D Programming/Linepick and slowdown

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.

"Staggering AI updates over multiple frames "

okay but how would you code that ?

The enemy AI function is one long select, case so how would you stagger it over frames.


I wouldn't try to stagger the thought process over several frames, just the instance that gets to think it:
Const NUMBER_OF_THINGS% = 10
Const GWIDTH = 800
Const GHEIGHT = 600

Graphics GWIDTH,GHEIGHT,0,2
SetBuffer BackBuffer()

Type thing
	Field xPos%
	Field yPos%
	
	Field xModifier%
	Field yModifier%
End Type
currentThing.thing = Null
Global ai.thing = Null

Function thing_ai()
	ai.thing\xPos=ai.thing\xPos+ai.thing\xModifier
	ai.thing\yPos=ai.thing\yPos+ai.thing\yModifier
	
	If (  ai.thing\xPos>(GWIDTH-1)  ) Or (  ai.thing\xPos<0  ) Then ai.thing\xModifier = -ai.thing\xModifier
	If (  ai.thing\yPos>(GHEIGHT-1)  ) Or (  ai.thing\yPos<0  ) Then ai.thing\yModifier = -ai.thing\yModifier

	
	If (After ai.thing) = Null
		ai.thing = First thing
	Else
		ai.thing = After ai.thing
	EndIf 	
End Function

Function thing_new.thing(x_arg%,y_arg%,xMod_arg%,yMod_arg%)
	Local newThing.thing = New thing
	newThing\xPos = x_arg
	newThing\yPos = y_arg
	newThing\xModifier = xMod_arg
	newThing\yModifier = yMod_arg
	Return newThing
End Function

Function thing_drawAll()
	Local thingToDraw.thing = Null
	For thingToDraw.thing = Each thing
		Plot thingToDraw\xPos,thingToDraw\yPos
	Next
End Function

For i=1 To NUMBER_OF_THINGS
	currentThing = thing_new(  Rand(0,GWIDTH-1), Rand(0,GHEIGHT-1), Rand(5,10), Rand(5,10)  )
Next
ai.thing = First thing

While Not KeyHit(1)
	thing_ai()
	thing_drawAll()
	Flip False
	Cls
Wend

That's the basis of it.