; include file



;**********************************************************************************************
tile_checks

	move.b	#0,ground	;no ground check
	move.b	(22,a0),ladder1	;ladder collision

; collision checks
; y first
	move.l	#0,d5
	move.l	#0,d6

	move.w	(6,a0),d5	;old x
	move.w	(4,a0),d6	;y
	move.w	d5,d0	;save
	move.w	d6,d1


	sub.w	#120,d5
	sub.w	#116,d6

	lsr.w	#4,d5
	lsr.w	#4,d6

	move.w	d5,tilex
	move.w	d6,tiley

	lea	world_map,a1	;map check
	mulu.w	#512,d6
	add.w	d5,d6
	lea	(a1,d6),a1
	move.w	#0,d7
	move.b	(a1),d7
	move.w	d7,tile


	if	b,ladder1=#0
; collision trials y first
	if	w,tile<#28	ws,tile>#10


	move.l	#0,d3

	move.w	tiley,d3
	mulu.w	#16,d3
	add.w	#122,d3


	if	w,d3=>d1
	move.w	d3,(4,a0)
	sub.w	#8,(4,a0)
	move.b	#1,ground
	endif


	if	w,d3<d1
	move.w	d3,(4,a0)
	add.w	#10,(4,a0)

	move.w	#0,(16,a0)	;no mo gravity

	endif

	endif


;elevator
	if	w,tile=#9


	move.l	#0,d3

	move.w	tiley,d3
	mulu.w	#16,d3
	add.w	#122,d3


	if	w,d3=>d1
	move.w	d3,(4,a0)
	sub.w	#8,(4,a0)
	move.b	#1,ground

	add.w	#2,(2,a0)

	endif


	if	w,d3<d1
	move.w	d3,(4,a0)
	add.w	#10,(4,a0)

	move.w	#0,(16,a0)	;no mo gravity

	endif

	endif
;elevator 2
	if	w,tile=#10


	move.l	#0,d3

	move.w	tiley,d3
	mulu.w	#16,d3
	add.w	#122,d3


	if	w,d3=>d1
	move.w	d3,(4,a0)
	sub.w	#8,(4,a0)
	move.b	#1,ground
	sub.w	#2,(2,a0)



	endif


	if	w,d3<d1
	move.w	d3,(4,a0)
	add.w	#10,(4,a0)

	move.w	#0,(16,a0)	;no mo gravity

	endif

	endif



; modify to kill at some point
;spikes
	if	w,tile=#8


	move.l	#0,d3

	move.w	tiley,d3
	mulu.w	#16,d3
	add.w	#122,d3


	if	w,d3=>d1
	move.w	d3,(4,a0)
	sub.w	#8,(4,a0)

	move.w	#4,(16,a0)
;jump
	move.b	#0,(10,a0)	;off ground

	else


	move.w	d3,(4,a0)
	add.w	#16,(4,a0)

	move.w	#65531,(16,a0)
;jump
	move.b	#0,ground	;off ground


	endif


	endif



;*******************************************************************************************
;slant calcs
	if	w,tile!#255	w,tile<#8


	if	w,tile=#7



	move.l	#0,d3

	move.w	tiley,d3
	mulu.w	#16,d3
	add.w	#122,d3


	if	w,d3<d1
	move.w	d3,(4,a0)
;	add.w	#10,(4,a0)
	move.b	#1,ground
	endif



	endif




	if	w,tile=>#5	w,tile=<#6




	move.l	#0,d3

	move.w	tiley,d3
	mulu.w	#16,d3
	add.w	#126,d3	;122




	if	w,d3<d1
	move.w	d3,(4,a0)
;	add.w	#10,(4,a0)
	move.b	#1,ground
	endif



	endif




	if	w,tile=>#1	w,tile=<#2




	move.l	#0,d3

	move.w	tiley,d3
	mulu.w	#16,d3
	add.w	#118,d3	;122





	if	w,d3<d1
	move.w	d3,(4,a0)
;	add.w	#10,(4,a0)
	move.b	#1,ground
	endif




	endif


;push up transition hi
	if	w,tile=#3




	move.l	#0,d3

	move.w	tiley,d3
	mulu.w	#16,d3
	add.w	#114,d3	;122




	if	w,d3<d1
	move.w	d3,(4,a0)
;	add.w	#10,(4,a0)
	move.b	#1,ground
	endif



	endif


;push up transition lo
	if	w,tile=#4



	move.l	#0,d3

	move.w	tiley,d3
	mulu.w	#16,d3
	add.w	#110,d3	;122



	if	w,d3<d1
	move.w	d3,(4,a0)
;	add.w	#10,(4,a0)
	move.b	#1,ground
	endif



	endif




;end slant checks
	endif
;*****************************************************************************************************



;now x tiles

; x 

	move.l	#0,d5
	move.l	#0,d6

	move.w	(2,a0),d5	;new x
	move.w	(4,a0),d6	;y
	move.w	d5,d0	;save
	move.w	d6,d1


	sub.w	#120,d5
	sub.w	#116,d6

	lsr.w	#4,d5
	lsr.w	#4,d6

	move.w	d5,tilex
	move.w	d6,tiley

	lea	world_map,a1	;map check
	mulu.w	#512,d6
	add.w	d5,d6
	lea	(a1,d6),a1
	move.w	#0,d7
	move.b	(a1),d7
	move.w	d7,tile

	
; collision trials y first
	if	w,tile<#28	ws,tile>#7

	move.l	#0,d2

	move.w	tilex,d2
	mulu.w	#16,d2
	add.w	#128,d2


	if	w,d2=>d0
	move.w	d2,(2,a0)
	sub.w	#9,(2,a0)
	endif


	if	w,d2<d0
	move.w	d2,(2,a0)
	add.w	#8,(2,a0)
	endif



	endif


;water check
	move.l	#0,d5
	move.l	#0,d6

	move.w	(2,a0),d5	; x
	move.w	(4,a0),d6	;y
	sub.w	#120,d5
	sub.w	#116,d6
	lsr.w	#4,d5
	lsr.w	#4,d6
	move.w	d5,tilex
	move.w	d6,tiley



	lea	world_map,a1	;map check
	mulu.w	#512,d6
	add.w	d5,d6
	lea	(a1,d6),a1
	move.w	#0,d7
	move.b	(a1),d7
	move.w	d7,tile

; in water?
	if	w,tile=>#30	w,tile=<#31
	move.b	#1,(21,a0)	;in water

; check gravity max

	move.w	(16,a0),d6
	if	ws,d6<#65534
	move.w	#65534,(16,a0)
	endif


	else

	move.b	#0,(21,a0)	;out water

	endif


	move.b	(22,a0),d6	;ladder
	move.b	(24,a0),d5	;pressing u or d
	if	w,tile=#29	b,d6=#0	b,d5=#1	or	w,tile=#28	b,d6=#0	b,d5=#1	
	move.b	#1,(22,a0)	;grab ladder
	move.b	#1,ground
	endif

	endif





;************************ladder c
	if	b,ladder1=#1
; not 28 or 29
	if	w,tile!#29	w,tile!#28

	move.l	#0,d3
	move.b	#1,ground
	move.w	tiley,d3
	mulu.w	#16,d3
	add.w	#122,d3


	if	w,d3=>d1
	move.w	d3,(4,a0)
	sub.w	#8,(4,a0)

	endif


	if	w,d3<d1
	move.w	d3,(4,a0)
	add.w	#10,(4,a0)
	move.w	#0,(16,a0)	;no mo gravity
	endif
	endif

;now x tiles

; x 

	move.l	#0,d5
	move.l	#0,d6

	move.w	(2,a0),d5	;new x
	move.w	(4,a0),d6	;y
	move.w	d5,d0	;save
	move.w	d6,d1


	sub.w	#120,d5
	sub.w	#116,d6

	lsr.w	#4,d5
	lsr.w	#4,d6

	move.w	d5,tilex
	move.w	d6,tiley

	lea	world_map,a1	;map check
	mulu.w	#512,d6
	add.w	d5,d6
	lea	(a1,d6),a1
	move.w	#0,d7
	move.b	(a1),d7
	move.w	d7,tile

	
; collision trials y first
	if	w,tile!#29	w,tile!#28

	move.l	#0,d2

	move.w	tilex,d2
	mulu.w	#16,d2
	add.w	#128,d2


	if	w,d2=>d0
	move.w	d2,(2,a0)
	sub.w	#9,(2,a0)
	endif


	if	w,d2<d0
	move.w	d2,(2,a0)
	add.w	#8,(2,a0)
	endif
	endif
	move.b	#1,ground

	endif

	move.b	ground,d7
	move.b	d7,(10,a0)	;save ground

	rts
;********************************************************************************************************************************


def	ladder1	byte
def	ladder2	byte

