% check if 2 squares colide by sides
col( X, Y, S, X2, Y2, S2):-
EndX is X + S, EndY is Y + S,
EndX2 is X2 + S2, EndY2 is Y2 + S2,
(
( EndX =:= X2, ( (Y >= Y2, Y =< EndY2);(EndY >= Y2, EndY =< EndY2))); % left-l side
( X =:= X2, ( (Y >= Y2, Y =< EndY2);(EndY >= Y2, EndY =< EndY2))); % left-r side
( EndX =:= EndX2, ( (Y >= Y2, Y =< EndY2);(EndY >= Y2, EndY =< EndY2))); % right-l side
( X =:= EndX2, ( (Y >= Y2, Y =< EndY2);(EndY >= Y2, EndY =< EndY2))); % right-r side
( EndY =:= Y2, ( (X >= X2, X =< EndX2);(EndX >= X2, EndX =< EndX2))); % top-t side
( Y =:= Y2, ( (X >= X2, X =< EndX2);(EndX >= X2, EndX =< EndX2))); % top-b side
( EndY =:= EndY2, ( (X >= X2, X =< EndX2);(EndX >= X2, EndX =< EndX2))); % bottom-t side
( Y =:= EndY2, ( (X >= X2, X =< EndX2);(EndX >= X2, EndX =< EndX2))) % bottom-b side
).
仅当我设置所有变量时它才能正常工作,但我想问如何更改它以便我可以使用:
col( 0,0,3,1,2,S).
甚至col( 0, 0, 3, X,Y, S).
可能吗?