Move line 18 outside the method. It should be an instance field (not a local variable) as its previous value has to be checked during the current execution of the act method. Also, move line 33 to line 41, so you do not overwrite the previous value before checking it. These are apparently changes you did on your own after applying my bomberman movement codes given above. Also, note that you cannot set the value of dir until you are guaranteed that one of the two, either dx or dy, is zero; otherwise, you may not set an accurate value for the field. So, that is another reason why it is set after the block that checks if (dx*dy != 0), which executes if neither is zero and sets one of the two to zero (first).
theVeritas_ wrote...<< Code Omitted >>