2d collision

Blitz3D Forums/Blitz3D Beginners Area/2d collision

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.

Anyone have a RPG stile collision routine to share? Better yet how about one for sliding collision. I have started on one below:
Function PlayerToWallCollision(p.tPlayer)
;Find four corners of Player and check
;them For collision with the walls.
;
;Also steer around corners automaticly
; +---+
; | P |
; +---+
	Local TL=0,BL=0,TR=0,BR=0
	If Walls((p\Sprite\X)/TileSize,(p\Sprite\OldY)/TileSize)=1 Then TL=1
	If Walls((p\Sprite\OldX)/TileSize,(p\Sprite\Y)/TileSize)=1 Then TL=1

	If Walls((p\Sprite\X+p\Sprite\Width)/TileSize,(p\Sprite\OldY)/TileSize)=1 Then TR=1
	If Walls((p\Sprite\OldX+p\Sprite\Width)/TileSize,(p\Sprite\Y)/TileSize)=1 Then TR=1

	If Walls((p\Sprite\X)/TileSize,(p\Sprite\OldY+p\Sprite\Height)/TileSize)=1 Then BL=1
	If Walls((p\Sprite\OldX)/TileSize,(p\Sprite\Y+p\Sprite\Height)/TileSize)=1 Then BL=1

	If Walls((p\Sprite\X+p\Sprite\Width)/TileSize,(p\Sprite\OldY+p\Sprite\Height)/TileSize)=1 Then BR=1
	If Walls((p\Sprite\OldX+p\Sprite\Width)/TileSize,(p\Sprite\Y+p\Sprite\Height)/TileSize)=1 Then BR=1
	If 1=1 Then;p\Jump= False Then
	If TL+BL+TR+BR > 0 Then
		Select p\Sprite\WalkDir
			Case UPDIR
				If TL+TR < 2 Then
					If TL > 0 Then 
						If BR <> 1 Then p\Sprite\X=p\Sprite\OldX+p\Speed:p\Sprite\Y=p\Sprite\OldY
					End If
					If TR > 0 Then 
						If BL <> 1 Then p\Sprite\X=p\Sprite\OldX-p\Speed:p\Sprite\Y=p\Sprite\OldY
					End If
				Else
					p\Sprite\Y=p\Sprite\OldY
				End If
			Case DOWNDIR
				If BL+BR < 2 Then
					If BL > 0 Then 
						If TR <> 1 Then p\Sprite\X=p\Sprite\OldX+p\Speed:p\Sprite\Y=p\Sprite\OldY
					End If
					If BR > 0 Then 
						If TL <> 1 Then p\Sprite\X=p\Sprite\OldX-p\Speed:p\Sprite\Y=p\Sprite\OldY
					End If
				Else
					p\Sprite\Y=p\Sprite\OldY
				End If
			Case LEFTDIR
				If BL+TL < 2 Then
					If BL > 0 Then 
						If BR <> 1 Then p\Sprite\Y=p\Sprite\OldY-p\Speed:p\Sprite\X=p\Sprite\OldX
					End If
					If TL > 0 Then 
						If BL <> 1 And BR <> 1 Then p\Sprite\Y=p\Sprite\OldY+p\Speed:p\Sprite\X=p\Sprite\OldX
					End If
				Else
					p\Sprite\X=p\Sprite\OldX
				End If
			Case RIGHTDIR
				If BR+TR < 2 Then
					If BR > 0 Then 
						If TL <> 1 Then p\Sprite\Y=p\Sprite\OldY-p\Speed:p\Sprite\X=p\Sprite\OldX
					End If
					If TR > 0 Then 
						If BL <> 1 Then p\Sprite\Y=p\Sprite\OldY+p\Speed:p\Sprite\X=p\Sprite\OldX
					End If
				Else
					p\Sprite\X=p\Sprite\OldX
				End If
		End Select
		If TL+BL+TR+BR >=3 Then p\Sprite\X=p\Sprite\OldX:p\Sprite\Y=p\Sprite\OldY
	End If
	EndIf
End Function