whats wrong here

Blitz3D Forums/Blitz3D Beginners Area/whats wrong here

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.

Type Player
Field x
Field y
End Type

Type Enemy
Field x
Field y
Field destroy ; <<<<------------------ add to check
End Type

Type Bullet
Field x
Field y
End Type

SeedRnd MilliSecs()
Graphics 600,400
SetBuffer BackBuffer()

Global BulletTimer=MilliSecs()

create_player()
create_enemy()

While Not KeyHit(1)

update_player()
update_enemy()
update_bullet()
kills()

Flip
Cls
Wend
End

Function kills() ;NEEDS WORK... BAD REAL BAD
For e.enemy=Each enemy
	For b.bullet=Each bullet
		If RectsOverlap(e\x,e\y,10,10,b\x,b\y,10,10)
			e\destroy=1 ;<<<<<< ----------------------
		End If
	Next
	If e\destroy=1 Delete e; <<<<< ------ destroy 'safely'
Next
End Function

Function create_player()
p.Player=New Player
p\x=300
p\y=350
End Function
Function update_player()
For p.Player=Each Player
Color 100,100,100
Rect p\x,p\y,20,20
If KeyDown(203) p\x=p\x-2
If KeyDown(205) p\x=p\x+2
If KeyHit(57) And MilliSecs()>BulletTime Then Create_Bullet(p\x,p\y)
Next
End Function

Function create_enemy()
For i=1 To 5
e.Enemy=New Enemy
e\x=Rnd(10,500)
e\y=Rnd(10,100)
Next
End Function
Function update_enemy()
Color 200,200,200

	For e.Enemy=Each Enemy
	num=num+1
	Rect e\x,e\y,10,10
	Text e\x,e\y+10,num
	Next
End Function

Function create_bullet(x,y)
b.Bullet=New Bullet
b\x=x+5
b\y=y-15
BulletTimer=MilliSecs()
End Function
Function update_bullet()
	Color 200,0,0

	For b.Bullet=Each Bullet
		Rect b\x,b\y,10,10
		b\y=b\y-3
		If b\y<1 Then Delete b
	Next
End Function 

I add a new field to check the 'destroy' of the enemy, and the last check in the last loop will destroy 'safely' the type.
In your example you destroyed the type and THEN it will be looked for the next loop...