Pieces on Grid Help
Plokiju
Member Posts: 4
I am trying to remake the game Khet ( http://en.wikipedia.org/wiki/Khet_(game) ) but I have encountered a problem. The game pieces are arranged on a grid like chess. I am trying to find a way so that a piece cannot be moved onto a space occupied by another piece, but it will not work.
I have it so that when the move button is pressed, the attribute self.Position.(X/Y) changes by 40 so that it occupies the adjacent space. To avoid two pieces occupying the same space, I made it so that when two pieces collide, the move is undone and the piece moves 40 in the opposite direction to return to its starting place. However, when they collide the pieces move apart and they move off the grid. Is there any way that they can be snapped into the grid so they don't drift away on collision? or is there a different solution to my problem?
I hope that made sense, it can be hard to describe.
I have it so that when the move button is pressed, the attribute self.Position.(X/Y) changes by 40 so that it occupies the adjacent space. To avoid two pieces occupying the same space, I made it so that when two pieces collide, the move is undone and the piece moves 40 in the opposite direction to return to its starting place. However, when they collide the pieces move apart and they move off the grid. Is there any way that they can be snapped into the grid so they don't drift away on collision? or is there a different solution to my problem?
I hope that made sense, it can be hard to describe.
Comments
http://gamesalad.com/wiki/how_to_gsc_track_if_actor_is_over_another
Using that method plus some global attributes that keep track if there is a piece there or not, you may be able to solve your issue.
Also, in the rule that verifies the center of your piece is over the board position square you can do a constrain attribute to the position of the board position square.
Instances can be individually modified, but my proposed solution would have probably taken a lot more time in that situation.