How do I make only adjacent squares on a grid clickable?

0 favourites
  • 9 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • I am very, very new to Construct, though I understand programming fundamentals. I am trying to make a very simple game that is essentially the first of these ice puzzles from Pokemon (ignore the voice).

    Subscribe to Construct videos now

    I have a 5x5 grid of blank tiles, and each time a tile is clicked an O appears on it. Players start at the start and can only select blank tiles adjacent to the O tile they just clicked. You must click a path through all 25 tiles and end at the exit to win.

    I don't know what tools I need to make use of to check for adjacency. I have read some people say arrays but I don't understand how I would implement them in this instance.

    Here's the project link https://drive.google.com/file/d/1fMOTmdZZGxKXbd45y_2uQElvoJiTsDP0/view?usp=sharing. Again, I am very new to actually designing this stuff so excuse how messy this project must be.

    Thanks!

  • Hard to make it messy with only 2 events, I was expecting something crazy :D

    Anyway I would go about this by using Tile Movement behaviour because I've been using it recently and it's really cool. Your object would be invisible and you can use the behaviour to check if you can move to an adjacent tile. There is a condition 'can move to tile', the ones you cannot move to would be solid and the ones you can move to would be the current gridposition.x,gridposition.y with +/- 1 depending on the direction.

    You then move the invisible object (simulate control in a direction) to the next tile and mark it with the circle, and the conditions are then based on the new tile. Also a bonus for this is it works very well if you decide you want to make it a moveable character like in the video rather than clicking, so you could give control to the invisible object/player to move to only adjacent squares like in that puzzle.

  • there are a great many ways you could accomplish this...

    here is one way I have done similar things - use a "detector" sprite to check for overlapping squares, to see which ones are adjacent and then check or set their state...

    in this sample I briefly show the detector sprite so you can see which squares it is over (normally it would stay invisible).

    https://www.rieperts.com/games/forum/TileGame.c3p

  • Thank you both so much for your help. With it I was able to create my first little game! It took me... a really long time.

    My main remaining question is: how do I make the Lose text appear immediately when running back over a circle I've already placed rather than upon trying to move out of it? It's working this way because I needed it to stop being solid so Red could move out of the circle after spawning it.

    Wish it could already have triggered the Loss text.

    drive.google.com/file/d/1yfU3P9MmnJeW_M0d5ST8rKY8KGXTODPO/view

  • There were some logical mistakes in your code.. As I understand, the circle sprite with Solid=enabled was supposed to indicate an occupied cell, but you never re-enabled Solid, so the end of the game was only detected when a second circle was spawned at the same cell..

    Anyway, please see my version:

    dropbox.com/s/rdzug7useh2e6j1/finishedpoke2.c3p

    Note, that I removed Solid behavior and temporary disable collisions when a new circle is created instead. Also, I changed collision polygon of the circle.

  • dop2000 THANK YOU! That is exactly what I was looking for. I kept thinking I could solve it if I could make it wait to enable collision but since I don't really know the program I didn't know how to implement it. Now it works great!

  • Just spent another hour or so getting rid of jankiness - no weird circle spawning next to walls or the exit, no moving after losing or winning. So, with the exception of design, I think it's totally complete if anyone wants to take a look and give me what feedback is possible for something so simple. Small as it is I'm very proud of my first little puzzle lol

    https://www.construct.net/en/free-online-games/reds-adventure-5716/play

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes tile movement is powerful. I love that behaviour been using it myself for a game.

  • Congratulations on your first game! You just broke through a huge barrier that not many people can break through. Keep up the good work :)

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