How do I make automatic coloring of neighboring cells/cells?

0 favourites
From the Asset Store
Save hours of work by resizing items on your game screens.
  • Hello everyone, help me implement the following mechanics: I have a 6 by 6 field, there are obstacles on it. I need that when clicking on an empty cell, the sprite frame of this cell changes and from it, in 4 directions, the frames of the remaining cells change, but stop if there is an obstacle ahead. I guess it's hard to explain, the screenshot should help with this.

    Tagged:

  • You could use a Tilemap for this:

    For example:

    Set the Empty tiles to (Tile = 0)

    Set the obstacles to (Tile = 1)

    -On Tile Clicked extract the X&Y into a Local variable

    -Loop in the 4 directions by using the System "For" loop:

    Dir Right ---> For "X" From (TileX +1) To ((Tilemap.Width/TileSize) -1)
    ---------> Tile at(LoopIndex("X"), Y) is not equal 1 ------> Set tile to your desire frame
    ---------> Else: Stop the loop
    
    Dir Left ---> For "X" From (TileX -1) To (0)
    ---------> Tile at(LoopIndex("X"), Y) is not equal 1 ------> Set tile to your desire frame
    ---------> Else: Stop the loop
    
    Dir Up---> For "Y" From (TileY -1) To (0)
    ---------> Tile at(X, LoopIndex("Y")) is not equal 1 ------> Set tile to your desire frame
    ---------> Else: Stop the loop
    
    Dir Down---> For "Y" From (TileY +1) To ((Tilemap.Height/TileSize) -1)
    ---------> Tile at(X, LoopIndex("Y")) is not equal 1 ------> Set tile to your desire frame
    ---------> Else: Stop the loop
    

    Probably a second condition is needed there to make you stop at the edges so you dont check outside the tilemap.

    Tile is not equal to -1

    Tile is not equal to 1

    If you really need to use sprites then you can still do all the tile checks in the tile map as I showed above and then when you need to change the frames just pick the Sprite tile that is located on that Tile by using Pick by overlapping Point XY

    or

    alternative you can do the same job by using just sprites alone if you add two variables to the sprites:

    Tx

    Ty

    At the start of the layout do a loop to set all the (Tx & Ty) variables and use the same system as the tilemaps. But this time pick tiles by comparations:

    Tile.Tx = X
    Tile.Ty = Y
    
  • You could use a Tilemap for this:

    For example:

    Set the Empty tiles to (Tile = 0)

    Set the obstacles to (Tile = 1)

    -On Tile Clicked extract the X&Y into a Local variable

    -Loop in the 4 directions by using the System "For" loop:

    > Dir Right ---> For "X" From (TileX +1) To ((Tilemap.Width/TileSize) -1)
    ---------> Tile at(LoopIndex("X"), Y) is not equal 1 ------> Set tile to your desire frame
    ---------> Else: Stop the loop
    
    Dir Left ---> For "X" From (TileX -1) To (0)
    ---------> Tile at(LoopIndex("X"), Y) is not equal 1 ------> Set tile to your desire frame
    ---------> Else: Stop the loop
    
    Dir Up---> For "Y" From (TileY -1) To (0)
    ---------> Tile at(X, LoopIndex("Y")) is not equal 1 ------> Set tile to your desire frame
    ---------> Else: Stop the loop
    
    Dir Down---> For "Y" From (TileY +1) To ((Tilemap.Height/TileSize) -1)
    ---------> Tile at(X, LoopIndex("Y")) is not equal 1 ------> Set tile to your desire frame
    ---------> Else: Stop the loop
    

    Probably a second condition is needed there to make you stop at the edges so you dont check outside the tilemap.

    Tile is not equal to -1

    Tile is not equal to 1

    If you really need to use sprites then you can still do all the tile checks in the tile map as I showed above and then when you need to change the frames just pick the Sprite tile that is located on that Tile by using Pick by overlapping Point XY

    or

    alternative you can do the same job by using just sprites alone if you add two variables to the sprites:

    Tx

    Ty

    At the start of the layout do a loop to set all the (Tx & Ty) variables and use the same system as the tilemaps. But this time pick tiles by comparations:

    > Tile.Tx = X
    Tile.Ty = Y
    

    Thanks for the reply, I will try to do so.

  • Here is an example:

    https://www.dropbox.com/scl/fi/3m29s7pco3rfd9bzguvyh/Coloring-Cells1.c3p?rlkey=8eu6iyqnivvw8qh8eoqm9fszz&dl=0

    Good afternoon, I am very ashamed that I have to write again in the hope of getting help, but...

    I'm trying to implement the mechanics of the Japanese Akari puzzle (Light Up), but I'm stuck. If you have the time/opportunity/desire to help again, I would be very grateful. I managed to add: installing another flashlight and saving the light when deleted, but I can't implement: install a marker, install another flashlight on the cage with the light (so that they would be highlighted as an error). You can get acquainted with the implemented game here: https://www.puzzle-light-up.com/ . and here is a link to the source code that I tried to make based on yours https://www.dropbox.com/scl/fi/ufvyr01ii4k28t3l2xcxm/Akari.c3p?rlkey=586oy8z3q98fklcfwjo1junfw&st=o6i6md41&dl=0

    Anyway, thanks for the help you've already provided.

  • > Here is an example:

    >

    > https://www.dropbox.com/scl/fi/3m29s7pco3rfd9bzguvyh/Coloring-Cells1.c3p?rlkey=8eu6iyqnivvw8qh8eoqm9fszz&dl=0

    Good afternoon, I am very ashamed that I have to write again in the hope of getting help, but...

    I'm trying to implement the mechanics of the Japanese Akari puzzle (Light Up), but I'm stuck. If you have the time/opportunity/desire to help again, I would be very grateful. I managed to add: installing another flashlight and saving the light when deleted, but I can't implement: install a marker, install another flashlight on the cage with the light (so that they would be highlighted as an error). You can get acquainted with the implemented game here: https://www.puzzle-light-up.com/ . and here is a link to the source code that I tried to make based on yours https://www.dropbox.com/scl/fi/ufvyr01ii4k28t3l2xcxm/Akari.c3p?rlkey=586oy8z3q98fklcfwjo1junfw&st=o6i6md41&dl=0

    Anyway, thanks for the help you've already provided.

    I'm not familiar with this game, so not sure if I understood your question correctly:

    After I tested the game from your link it seems that you are referring to the Red Error light bulbs?

    Example:

    It looks like when you put another bulb in a tile that is lighted up it will mark all the light bulbs that are on the same (Row & Column) in red as an error.

    Is that what you are referring to?

  • > > Here is an example:

    > >

    > > https://www.dropbox.com/scl/fi/3m29s7pco3rfd9bzguvyh/Coloring-Cells1.c3p?rlkey=8eu6iyqnivvw8qh8eoqm9fszz&dl=0

    >

    > Good afternoon, I am very ashamed that I have to write again in the hope of getting help, but...

    >

    > I'm trying to implement the mechanics of the Japanese Akari puzzle (Light Up), but I'm stuck. If you have the time/opportunity/desire to help again, I would be very grateful. I managed to add: installing another flashlight and saving the light when deleted, but I can't implement: install a marker, install another flashlight on the cage with the light (so that they would be highlighted as an error). You can get acquainted with the implemented game here: https://www.puzzle-light-up.com/ . and here is a link to the source code that I tried to make based on yours https://www.dropbox.com/scl/fi/ufvyr01ii4k28t3l2xcxm/Akari.c3p?rlkey=586oy8z3q98fklcfwjo1junfw&st=o6i6md41&dl=0

    > Anyway, thanks for the help you've already provided.

    I'm not familiar with this game, so not sure if I understood your question correctly:

    After I tested the game from your link it seems that you are referring to the Red Error light bulbs?

    Example:

    It looks like when you put another bulb in a tile that is lighted up it will mark all the light bulbs that are on the same (Row & Column) in red as an error.

    Is that what you are referring to?

    Yes, that's right

  • probably the main problem remains the moment when, in case of an error (two bulbs shine at each other), I remove one, and with it the light that should have remained from the first bulb disappears.

  • Yes, that's right

    I will have a look

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • probably the main problem remains the moment when, in case of an error (two bulbs shine at each other), I remove one, and with it the light that should have remained from the first bulb disappears.

    Hoh wait, you want to also remove the lights?

    That complicates quite a lot the logic

    Your first request of just setting the error lights to red is easy but removing the lights feature needs more thinking as it can get very complicated because it could be multiple sources reflecting the same tiles so you have to keep track of how many tiles are reflecting each bulb lol.

    This is gonna be a good brain cracker.

  • Yes, it's not such an easy task (to count the light, I made a variable for the family and if the light intersects with each other, but there are no lanterns, but the removal is simple, but if the light falls on someone else's lantern, that's the whole problem

  • Yes, it's not such an easy task (to count the light, I made a variable for the family and if the light intersects with each other, but there are no lanterns, but the removal is simple, but if the light falls on someone else's lantern, that's the whole problem

    Yep, I get the whole picture now. I thought it just needed to set the bulbs to red as I never played this game.

    Bu is ok I have some ideas.

    Nice puzzle to solve :)

  • I hope it doesn't bother you too much)

  • Here is one way of doing it:

    https://www.dropbox.com/scl/fi/r2ozshdnt2r4z1azd9wtc/Light-Up-Akari2.c3p?rlkey=gvjci0nhgzz211px3hkkeqarz&dl=0

    I hope I didn't miss any edge cases, as normally you need more time to think about all possibilities, though it seems to work fine for me.

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