its wrong... you put if ymax>0 then ymax=0 and the same for xmax, its really, IF Y>YMAX THEN Y=YMAX IF X>XMAX THEN X=XMAX there you go! :)