Pieces on Grid Help

PlokijuPlokiju Member Posts: 4
edited November -1 in Working with GS (Mac)
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.

Comments

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    You may want to take a look at the wiki I just created.
    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.
  • PlokijuPlokiju Member Posts: 4
    That solution wouldn't really work in this situation because there are multiple instances of the same actor, but I came up with a different solution. I put invisible walls around the spaces to keep the pieces in place.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Cool. Glad you found your own way to solve it. Can't wait to see the finished game.

    Instances can be individually modified, but my proposed solution would have probably taken a lot more time in that situation.
Sign In or Register to comment.