image collision/deletion problem

Blitz3D Forums/Blitz3D Beginners Area/image collision/deletion problem

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.

Oh, also, i notice you aren't actually deleting the bullets once they've hit something. Add in:

			If bullet\alive = 0 Then
				Delete bullet.bullet
			End If


In the "PlayerCollisions()" function, just below where you check the Y position of the bullet. :o) To make the function read:

Function PlayerCollisions()

	;Reset the collisions variables
	playerup = False
	playerleft = False
	playerright=False
	playerdown = False
	;Start Collision Detection
	;solid
	For x = 0 To mapsizex
		For y = 0 To mapsizey
			If map(0,x,y)>0 Then;if there is something occupying the current x,y position in the Map array
				If ImagesCollide(player\image ,player\x+collisioncheck ,player\y ,player\imagehandle ,gfx_tiles,x*32,y*32,map(0,x,y)) Then playerright = True ;IF the player collided with the current tile on his right
				If ImagesCollide(player\image ,player\x-collisioncheck ,player\y ,player\imagehandle ,gfx_tiles,x*32,y*32,map(0,x,y)) Then playerleft = True ;IF the player collided with the current tile on his left
				If ImagesCollide(player\image ,player\x ,player\y+collisioncheck ,player\imagehandle ,gfx_tiles,x*32,y*32,map(0,x,y)) Then playerdown = True;IF the player collided with the current tile below him
				If ImagesCollide(player\image ,player\x ,player\y-collisioncheck ,player\imagehandle ,gfx_tiles,x*32,y*32,map(0,x,y)) Then playerup = True;IF the player collided with the current tile Above Him
			EndIf
		Next
	Next
	
	;check collision for the pickups
	For pickup.pickup=Each pickup
	
		If pickup\alive =1 Then
			If ImagesCollide(player\image,player\x,player\y,player\imagehandle ,pickup\image ,pickup\x,pickup\y ,pickup\imagehandle ) Then
				pickup\alive =0 ;remove the pickup
				pickupid=pickupid-1
				player\score=player\score+10	
			EndIf
		End If

	Next
	
	Local bullet_dead = 0
	
		;check collision for the bullets
	For bullet.bullet=Each bullet
	
		If bullet\alive =1 Then
		
			bullet\y =bullet\y -5 ;move the bullet upwards if not hit anything
			
			For enemy.enemy=Each enemy
			

				If enemy\alive =1 Then
				
					If ImagesCollide(enemy\image,enemy\x,enemy\y,enemy\imagehandle ,bullet\image ,bullet\x,bullet\y ,bullet\imagehandle ) Then

						enemy\alive =0 ;remove the enemy
						bullet\alive =0 ; remove the bullet
						player\score=player\score+10	
					
					End If
					
				EndIf
			
			Next

			If bullet\y=<0 Then
				;if bullet off top of screen then delete and dont show
				bullet\alive =0
			End If

			If bullet\alive = 0 Then
				Delete bullet.bullet
			End If
		
		End If
		
	Next

End Function


I also moved the part where you move the bullets, to before the collision check is done, to make sure it doesn't miss.