Single shot ?

Blitz3D Forums/Blitz3D Beginners Area/Single shot ?

Ok a new problem :)

How can i get the enemy to respawn every new level?

I start off with 2 enemy's and start on level 1.
I would like to increase the amount of enemy by 2 every new level.

Graphics 800,600,16,2

Type player
	Field x#,y#
	Field ang#,speed#
	Field img
	Field hp
End Type

Type grenade
	Field x#,y#
	Field ang#,speed#
	Field img
	Field life#
	Field ammo
End Type

Type shrap
    Field x#,y#,dx#,dy#
	Field timer
	Field size#
	Field r,g,b
End Type

Type enemy
	Field enx#,eny#
	Field life
	Field img
	Field hp
	Field state
	Field m_time
	Field dir
End Type

Const Gunsize = 8

Global me.player = New player
Global clickedx = MouseX()
Global clickedy = MouseY()
;Global sndExplode=LoadSound("explode.wav")

Global nme = 2
Global hp = 100
Global gammo=6
Global level=1

me\x=400
me\y=300
me\img=CreateImage(9,9)
SetBuffer ImageBuffer(me\img)
Color 100,255,100
Oval 0,0,8,8 
MidHandle me\img

SeedRnd MilliSecs()

;enemy/gfx-----------

For i=1 To nme
	en.enemy=New enemy
	en\enx=Rand(0,800)
	en\eny=Rand(0,600)
	en\img=CreateImage(9,9)
	en\hp=100
	SetBuffer ImageBuffer(en\img)
	Color 255,100,100
	Oval 0,0,8,8 
	MidHandle en\img	
Next

;--------------------

HidePointer
SetBuffer BackBuffer()

;MAIN LOOP----------------------------------------

While Not KeyDown(1)

	Cls

		Color 150,150,150
		Oval MouseX(),MouseY(),4,4 

		Color 255,255,255
		Text 0,0,"LMB = Move / RMB = Grenade"
		
		Text 100,15,"G-Ammo "+gammo
		
		Text 200,15,"Level "+level
				
		DrawPlayer()
		
		DrawEnemy()
		
		UpdatePlayer()
		
		Moveshrap()
			
	Flip

Wend

FreeImage me\img

End

;FUNCTIONS-----------------------------------------

Function DrawPlayer()
	
	DrawImage me\img,me\x,me\y 
	
End Function

;--------------------------------------------------

Function DrawEnemy()

For en.enemy = Each enemy

		Text 0,15,"Enemy = "+nme
		
		DrawImage en\img,en\enx,en\eny

		
	Next

End Function

;--------------------------------------------------

Function UpdatePlayer()
		
		If MouseHit(1)
	
			clickedx=MouseX()
			clickedy=MouseY()
			me\ang=ATan2(clickedx-me\x,clickedy-me\y)
			me\speed=2
		
		EndIf
	
		If Sqr((me\x-clickedx)^2+(me\y-clickedy)^2)<3
   			me\speed=0
		EndIf
	
		me\y=me\y+(Cos(me\ang)*me\speed)
		me\x=me\x+(Sin(me\ang)*me\speed)

		dX = MouseX() - me\x
		dY = MouseY() - me\y

		Gunang = ATan2(dY,dX)

		Gundx# = Cos(Gunang)
		Gundy# = Sin(Gunang)
	
		GunendX = me\x + gundx*Gunsize
		GunendY = me\y + gundy*Gunsize
	
		Color 100,255,100
		Line(me\x,me\y,gunendx,gunendy)
			
		If MouseHit(2) And gammo > 0
			g.grenade = First grenade
			If g = Null Then  		
				g.grenade = New grenade 
				g\x = gunendx : g\y = gunendy
				g\ang= ATan2(MouseX()-g\x,MouseY()-g\y)
				g\speed=4+me\speed
				g\life=150
				gammo=gammo-1
				
				If gammo <= 0
				gammo=0
				End If
				
			EndIf
		End If
		
		For g.grenade = Each grenade
		
				MoveGrenade(g)
				
		
		Next

End Function

;--------------------------------------------------

Function MoveGrenade(g.grenade)

		g\y=g\y+(Cos(g\ang)*g\speed)
		g\x=g\x+(Sin(g\ang)*g\speed)
		
		gw=4
		gh=4
		
		Color 100,100,100		 		
		Oval g\x,g\y,gw,gh,1
		
		g\life=g\life-1
		
		If g\life<150 
			
			g\speed=3
			
		End If
		
		If g\life<100 
			
			g\speed=1.5
					
		End If

		If g\life<50
		
			g\speed=0
			Color Rnd(48,228),Rnd(48,228),0	 		
			Oval g\x,g\y,gw,gh,1
	
		End If
			
		If g\life<1
			
			PlaySound sndExplode
		
			For i=1 To 20
				s.shrap = New shrap
				s\x = g\x
				s\y = g\y
				s\dx = Rnd(-4,4):s\dy=Rnd(-4,4)
				s\size = Rnd(2,4)
				
				col# = Rnd(48,128)
				s\r = col: s\g = col: s\b = col
			
			If i>10 Then
				
				s\r=255: s\g=300-s\size*40: s\b=0
				s\dx=s\dx/2
				s\dy=s\dy/2
			
			End If
		
			Next
			
			Delete g
		
		End If
	
End Function

;--------------------------------------------------

Function Moveshrap()

	For s.shrap = Each shrap
       	s\x = s\x + s\dx
    	s\y = s\y + s\dy
    	s\timer=s\timer+1
    	If s\timer>30 Then Delete s 
	Next

	For s.shrap = Each shrap
		Color s\r,s\g,s\b
		Oval s\x-s\size/2,s\y-s\size/2,s\size,s\size
	Next
	
	;Collision check
	For s.shrap = Each shrap
		For en.enemy=Each enemy
		
		If Sqr((s\x-en\enx)^2+(s\y-en\eny)^2)<8
			
			en\hp=en\hp-20
			
			If en\hp < 0
				nme = nme-1 : Delete en.enemy
				hp=100
				
				If nme <=0
					gammo=gammo+1
					level=level+1
				End If
				
			End If
			
	
		End If
		
		Next
	Next

End Function



Thanks

Destroyer :)