Graphics3D 800,600,16,2
SetBuffer BackBuffer()


light=CreateLight()
RotateEntity light,90,0,0
camera=CreateCamera()

PositionEntity camera,320,400,240
RotateEntity camera,90,0,0

boden=CreatePlane()

Type gegner
Field mesh,pivot						;mesh=gegnerobjekt pivot=festerdrehpunkt zum pointentity
Field x,z,aktiv							;x,z=koordinaten aktiv=gegner gesichtet-->größerer aufpassradius
Field zielx,zielz,wegzeit				;zielx,zielz=neue koordinaten wegzeit=wenn neuer weg berechnet werden soll
End Type

For i= 1 To 30

	n.gegner=New gegner
	n\mesh=CreateCube()	
	n\pivot=CreatePivot()
	z=20+Rnd(440)
	n\x=20+Rnd(600)
	n\z=z
	n\aktiv=0
	n\zielx=30+Rnd(30)
	n\zielz=z+(Rnd(60)-30)
	n\wegzeit=MilliSecs()+(Rnd(2000)-1000)
	ScaleEntity n\mesh,4,2,2
	EntityColor n\mesh,0,0,100
	EntityType n\mesh,1
	PositionEntity n\pivot,n\zielx,1,n\zielz
	PositionEntity n\mesh,n\x,1,n\z
	PointEntity n\mesh,n\pivot

Next

wand1=CreateCube()
EntityType wand1,2
ScaleEntity wand1,100,3,2
EntityColor wand1,10,10,10

Collisions 1,2,2,2

Global mauscube=CreateCube()
ScaleEntity mauscube,2,2,2
EntityColor mauscube,200,0,0
Global mausx=400
Global mausy=300


radius150=CreateCylinder(32)
EntityColor radius150,255,0,0
ScaleEntity radius150,150,1,150
radius50=CreateCylinder(32)
EntityColor radius50,0,0,0
ScaleEntity radius50,50,1,50

max_fps=100
norm=15
fps_last=MilliSecs
HidePointer
MoveMouse 400,300
While Not KeyHit(1)
		PositionEntity radius150,mausx,0,mausy
		PositionEntity radius50,mausx,0,mausy
		;Framelimiter
		While FPS_LAST>(MilliSecs()-(1000./MAX_FPS)):Delay FPS_LAST-(MilliSecs()-(1000./MAX_FPS))-1:Wend 
			make=-(FPS_LAST-MilliSecs())/norm

;Programmroutinen
;Start
	For k=1 To make 

			
			
	Next
	PositionEntity mauscube,mausx,1,mausy
	ki()
	
	mausx=mausx+MouseXSpeed()
	mausy=mausy-MouseYSpeed()
	fps_last=MilliSecs()
	
	UpdateWorld()
	RenderWorld()
	
	
	
Flip 0

MoveMouse 400,300

Wend

ShowPointer


Function ki()

For n.gegner=Each gegner
neuerweg=Rnd(600)
		
		
		If n\x<n\zielx Then n\x=n\x+1
		If n\x>n\zielx Then n\x=n\x-1
		If n\z<n\zielz Then n\z=n\z+1
		If n\z>n\zielz Then n\z=n\z-1
		If (n\wegzeit+1000)<MilliSecs() Then 
				n\zielx=n\x+(Rnd(20)-10)
				n\zielz=n\z+(Rnd(20)-10)
				n\wegzeit=MilliSecs()+(Rnd(200)-100)
		End If
		If n\zielx<10 Then n\zielx=10
		If n\zielx>630 Then n\zielx=630
		If n\zielz<10 Then n\zielz=10
		If n\zielz>470 Then n\zielz=470
		
		Select n\aktiv
		Case 0
				If EntityDistance(n\mesh,mauscube)<50 Then 
					n\zielx=mausx
					n\zielz=mausy
					n\aktiv=1
				End If
		Case 1
				If EntityDistance(n\mesh,mauscube)<150 Then 
					n\zielx=mausx
					n\zielz=mausy
				Else 
					n\aktiv=0
				End If
		End Select
		
		If EntityDistance(n\mesh,mauscube)<10 Then 
			EntityColor n\mesh,0,255,0
			Else
			EntityColor n\mesh,0,0,100
		End If
		If  neuerweg=1 Then
		 
				n\x=n\x+Rnd(10)-5
		       n\z=n\z+Rnd(10)-5
		End If
		
		PositionEntity n\mesh,n\x,0,n\z
		PositionEntity n\pivot,n\zielx,1,n\zielz
		If n\x<>n\zielx  And n\z<> n\zielz Then PointEntity n\mesh,n\pivot

Next

End Function