side-scrolling tutorials?

Blitz3D Forums/Blitz3D Beginners Area/side-scrolling tutorials?


Function draw_block_map(x,y)	
	bmap_blocktlx=x/bmap\tileSide	;Index of top left block that needs pasting
	bmap_blocktly=y/bmap\tileSide	;Index of top right block
	If bmap_blocktlx<0 Then bmap_blocktlx=0
	If bmap_blocktly<0 Then bmap_blocktly=0
	bmap_drawxpos=bmap_blocktlx*bmap\tileSide-x
	bmap_offy=bmap_blocktly*bmap\tileSide-y
	bmap_drawypos=bmap_offy
		
	bmap_lx_max=bmap_blocktlx+bmap\screenxblksminus1
	bmap_ly_max=bmap_blocktly+bmap\screenxblksminus1
		
	If bmap_lx_max>bmap\blocksx-1 Then bmap_lx_max=bmap\blocksx-1
	If bmap_ly_max>bmap\blocksy-1 Then bmap_ly_max=bmap\blocksy-1
		
	For bmap_lx=bmap_blocktlx To bmap_lx_max
		For bmap_ly=bmap_blocktly To bmap_ly_max
			DrawBlock bmap_blocks,bmap_drawxpos,bmap_drawypos,block_map(bmap_lx,bmap_ly)
			bmap_drawypos=bmap_drawypos+bmap\tileSide
		Next
		bmap_drawypos=bmap_offy
		bmap_drawxpos=bmap_drawxpos+bmap\tileSide
	Next
End Function

Function dotMapCollide(dotx,doty) ; Must have a global 'dot' graphic defined
	bmap_blocktlx=dotx/bmap\tileSide	;x index of block dot is in
	bmap_blocktly=doty/bmap\tileSide	;y index of block dot is in
	Select (bmap_blocktlx>-1 And bmap_blocktlx<bmap\blocksx And bmap_blocktly>-1 And bmap_blocktly<bmap\blocksy)
	Case 0
		Return 0
	Case 1
		Return ImagesCollide(dot,dotx,doty,0,bmap_blocks,bmap_blocktlx*bmap\tileSide,bmap_blocktly*bmap\tileSide,block_map(bmap_blocktlx,bmap_blocktly))
	End Select
End Function

Function imMapCollide(image,x,y,frame) ;optimiZE!!!!!!!!!!!
	;imtlx=x-ImageXHandle(image)
	;imtly=y-ImageYHandle(image)
	;imbrx=imtlx+ImageWidth(image)
	;imbry=imtly+ImageHeight(image)
	
	;blocktlx=imtlx/bmap\tileSide
	;blocktly=imtly/bmap\tileSide
	;blockbrx=imbrx/bmap\tileSide
	;blockbry=imbry/bmap\tileSide
	
	col=0
	;For bx=blocktlx To blockbrx
	;	For by=blocktly To blockbry
	;		If ImagesCollide (image,x,y,frame,bmap_blocks,bx*bmap\tileSide,by*bmap\tileSide,block_map(bx,by)) Then col=1	
	;	Next
	;Next
	Return col
End Function



There you go - you'll have to do a bit of figuring out to work it into a running piece of software. Designed only to work with square map blocks as it stands. May need a few globals defining. block_map array holds the tile values. You have collision testing for both points and images with the terrain. Can't remember why the image map collision was all commented out - it will probs work if you uncomment it.