Space Invaders help

Blitz3D Forums/Blitz3D Beginners Area/Space Invaders help

GameCoder(Posted 2004) [#1]
I have my invaders being drawn on screen in relation to a pattern i set in a data statement. The thing is I cant seem to get them to collide with bullets. I thought this would be simple but its buggin me.

heres da codezz for da loop dat deals wid it.

Thx for any help :)


Function read_zoiks_pattern()
	
	Restore level1
	
	For y = 0 To 13

		Read level$
		
			If level$ = "0" Then Exit
		
				For x = 0 To 11
			
					pos(x,y) = Mid$(level,x+1,1)
									
				Next
	Next
	

End Function

Function update_zoiks()
	
For y = 0 To 2
	
	For x = 0 To 7
			
		 	If pos(x,y) = "-"
				
				z.zoik = New zoik
				z\zx# = mapx#+(x*65)
				z\zy# = mapy#+(y*45)
				DrawImage zoikoidgreen,z\zx,z\zy,zoikoidgreen_frame		
										
		EndIf
		
	Next
	
Next

	
		If change_direction = 1 Then
			
			mapx# = mapx# + zoik_speed

				For y = 0 To 2
					
					For x = 0 To 7
					
						If mapx#+(x*65) >= 580 Then change_direction = 0
						
					Next
					
				Next
			
		EndIf

				
		If change_direction = 0 Then
			
			mapx# = mapx# - zoik_speed

				For y = 0 To 2
					
					For x = 0 To 7
					
						If mapx#+(x*65) < 0 Then change_direction = 1
						
					Next
					
				Next
			
		EndIf
								
			If MilliSecs() > zoikoidframe + 100 Then
				
					zoikoidframe = MilliSecs()
						
						zoikoidgreen_frame = zoikoidgreen_frame + 1
				
							If zoikoidgreen_frame >=3 Then zoikoidgreen_frame = 0
			
			EndIf
	

End Function

Function update_rebellion()
	

	
		DrawImage rebellion,rebelx,rebely
	
			If KeyDown(203) = True
				
					rebelx = rebelx - rebelspeed
					
			ElseIf KeyDown(205) = True
			
					rebelx = rebelx + rebelspeed
					
			EndIf
			
			If KeyHit(29) = True
				
				If MilliSecs() >= btimerreb + 500 Then
				
					btimerrb = MilliSecs()
					
						b.bulletr = New bulletr
						b\bx = rebelx
						b\by = rebely
				
				EndIf
										
			EndIf
			
		For b.bulletr = Each bulletr
			
			DrawImage bulletr,b\bx,b\by
			
			b\by = b\by - 4
			
				If b\by <0 Then Delete b
			
		Next
	
	If rebelx >= 590 Then rebelx = 590
	If rebelx <= 0   Then rebelx = 0
	
End Function

Function collision()
	For b.bulletr = Each bulletr
	
		For z.zoik = Each zoik
		
		;If ImagesCollide(bulletr,b\bx,b\by,0,zoikoidgreen,mapx#+(x*65),mapy#+(y*45),zoikoidgreen_frame)
		If ImagesCollide(bulletr,b\bx,b\by,0,zoikoidgreen,z\zx*65,z\zy*45,zoikoidgreen_frame)
			
			Delete z
			Delete b
			
		EndIf
		
		Next
		
	Next
			
End Function


.level1

Data "--------"
Data " ------ "
Data "--    --"
Data "0"




GameCoder(Posted 2004) [#2]
Ok I can get a reaction now by using the following below for the collision. The error message I get is "Object Does Not Exist" when a bullet hits an enemy.

What does that mean?




StOrM3(Posted 2004) [#3]
are the bullets getting deleted before you check for collision ? If so, that may be your problem. I can't really tell without your main game loop.


GameCoder(Posted 2004) [#4]
I have sorted it. it was a matter of putting "Exit" in the loop so as to avoid the object does not exist error.

Thx anyway :)


StOrM3(Posted 2004) [#5]
your welcome.. I suspected it was something like that, since I have had that issue more than once while coding on my current engine.