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

2019/4/25

Checking if something is in the way

CodeTime CodeTime

2019/4/25

#
So I am making a chess game and just finished the portion on how pieces can move. Simply, they move through set location and through checks if the piece is following the rules. However, I am now stuck at a problem. How do I check if the piece would be colliding with another piece on its way to its location? Since it's not technically moving, but rather more like disappearing and reappearing, the normal collision checks don't seem to work, so I was wondering if there was another way? I can provide code if needed
danpost danpost

2019/4/25

#
Possible things you could try are: (1) use a for loop to move the actor one square at a time toward its destination, checking for collision at each square; (2) add an object the stretches between the origin and destination squares, not including the two squares and ensure it has no intersecting objects; (3) represent the position of the board in an array and iterate between the two positions looking for a non-empty position; There are probably other ways as well, but one of these should work for you.
You need to login to post a reply.