This site requires JavaScript, please enable it in your browser!
Greenfoot back
theVeritas_
theVeritas_ wrote ...

2021/12/9

Collisions not working properly

1
2
danpost danpost

2021/12/14

#
theVeritas_ wrote...
<< Code Omitted >>
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_ theVeritas_

2021/12/14

#
Oh, ye, that was the problem :'D Thanks, I don't know why I put dir in act(), but I think I moved the change of dir because there was some error? I think? And yeah, that was probably because dir wasn't as class variable, but local in act() method. Thanks again!
You need to login to post a reply.
1
2