CollideImage Function?

BlitzMax Forums/BlitzMax Beginners Area/CollideImage Function?

Collisions are based on 'layers' which is quite different from how other versions of Blitz does it.

Basically you do it like this:
1 - Write everything you want your image to collide with to a collision layer.
2 - Check the image against the collision layer.

It's quite simple.

Here's a small example:
Graphics 640,480,0

Global tList:TList = New TList

Type img
	Field image:timage
	Field x:Float,y:Float
	Field sx:Float,sy:Float
	Field r:Float,sr:Float
	
	Function Create:img(f:String)
		i:img = New img
		i.image = LoadImage(f)
		i.x		= Rnd(20,620)
		i.y		= Rnd(20,460)
		i.sx	= Rnd(-3,3)
		i.sy	= Rnd(-3,3)
		i.r		= Rnd(0,360)
		i.sr	= Rnd(-5,5)
		tList.Addlast i
		Return i
	End Function
	
	Method Update()
		x :+ sx
		y :+ sy
		r :+ sr
		If x>620 And sx>0
			sx = -sx
		ElseIf x<20 And sx<0
			sx = -sx			
		EndIf
		If y>460 And sy>0
			sy = -sy
		ElseIf y<20 And sy<0
			sy = -sy
		EndIf
		
		SetBlend ALPHABLEND
		SetScale 3,3
		SetRotation r
		SetColor 255,255,255
		
		' Draw this image in collision layer 1
		CollideImage(image,x,y,0,0,1)
		' Test all other images with collision layer 1
		For Local i:img = EachIn tList
			If i<>Self
				' This tests i.image for collision with layer 1
				If CollideImage(i.image,i.x,i.y,0,1,0)
					' We have a collision so let's make it red!
					SetColor 255,0,0
				EndIf
			EndIf
		Next
		' Clear all collision layers
		ResetCollisions()
		DrawImage image,x,y
	End Method
	
End Type

For j = 0 To 9
	i:img = img.create("E:\Programmer\BlitzMax\samples\firepaint\bullet.png")
Next

Repeat
	
	Cls
	
	For i:img = EachIn tList
		i.Update()
	Next
	
	Flip
	FlushMem
	
Until KeyHit(KEY_ESCAPE)