How do I add pre-determined grid movement?

0 favourites
  • 6 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • Like Chess, where you have set predetermined moves for each space. In this case though, I would have a character on a grid that can move predetermined directions and finite amount of spaces depending on the input.

    I’ve been trying to figure it out based on past forum posts and google searches, but the .capx files I’m having a hard time opening and I wanted to get the community’s opinion.

    Tagged:

  • I think I know what you mean, but your question isn't so specific.

    Maybe you can tell what exactly your problem is? Is it trying to evaluate the valid moves, or highlighting them, or limiting the clickable area's?

  • This is not terribly complex, but there are some quirks you must be aware.

    First of all there are 2 (or 1, depending on the perspective) types of moves in chess:

    1. Queens, Bishops and Rooks move in "infinite" straight lines.

    2. Pawns, Kings and Knights have cell-dependent movement.

    I will explain further down how Qs, Bs and Rs can actually move like Ps, Ks and Ns, but for now imagine they are different.

    In a simple matrix system the QBR movement is pretty obvious, you test diagonals and/or horizontals until you cannot move further and display the possible moves to the player, but PKN movement can be a little tricky, and this is how I implement it.

    The A is the actor and the dots around are the cells of the board.

    The case above represents for example how a knight moves. You can clearly see the radial symmetry happening. You can simplify the symmetry notation so it's easier to read and write like below.

    In the image above you can see how we just have to flip the matrix to get the other side, and you can do it again, this time mirroring.

    There is a last mirror we can do in 45 degrees and then you'll have the primordial move matrix.

    Now that you can know you can get the full movement from just this simple matrix, and you can give out addresses to each cell like below.

    In this notation the PKN moves would look like this: "knight: [3]", "king: [0, 1]" and "pawn: [0, 1, 2]". In the pawn case, the 1 and 2 would be conditional, but you can check for yourself any special or situational needs your pieces may have.

    You can also expand this matrix to whichever number you want as long as you want radial symmetry. Any time you do NOT want radial symmetry you have to unfold the matrix to address your needs.

    This is just a general idea that helps to visualize the movements, but I hope it helps. Feel free to continue this thread if you have any questions about it.

  • And I forgot to mention in the last comment (but won't edit it, because sometimes I have to reupload the images) is that by those definitions you can clearly see how a big enough matrix could solve also the QBR movements. Cheers.

  • I think I know what you mean, but your question isn't so specific.

    Maybe you can tell what exactly your problem is? Is it trying to evaluate the valid moves, or highlighting them, or limiting the clickable area's?

    Thank you for answering! The technical problem is mostly highlighting and limiting the clickable/movable areas.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • And I forgot to mention in the last comment (but won't edit it, because sometimes I have to reupload the images) is that by those definitions you can clearly see how a big enough matrix could solve also the QBR movements. Cheers.

    Your last comment makes a lot of sense! I didn’t think of it in this way, but it makes sense in regards to what I’ve already seen. It is fascinating in a way. I appreciate it a lot!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)