How do I make the engine compare the size and appearance of free cells with the size and appearance?

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
75 vehicle sound effects, from real looping car engines to jet aircraft and sci-fi engines.
  • Hello everyone!

    Can you tell me how you can compare the shape of 2 or more objects by image points or in some other way?

    I'm making a kind of Block Puzzle. We have shapes and cells on which these shapes are placed. How do I make the engine compare the size and appearance of free cells with the size and appearance of shapes?

    I need to compare the shape of the figure and the shape formed by the free cells.

    For example, 4 free cells form a square, but the shapes that we have are not square in shape, respectively - game over.

  • Here’s one possible solution.

    First step is to find the lowest x and y of each group of blocks and subtract that from the xy of each block. Next you can add the xy pairs to dictionary for one group, and remove them with the other. If it’s empty both sets of blocks are in the same shape.

    Var xmin=0
    Var ymin=0
    
    Every tick
    — dictionary: clear
    
    For each block1
    — set xmin to loopindex=0?block1.x:min(xmin,block1.x)
    — set ymin to loopindex=0?block1.y:min(ymin,block1.y)
    
    For each block1
    — dictionary: add key (block1.x-xmin)&”,”&(block1.y-ymin) with value 0
    
    For each block2
    — set xmin to loopindex=0?block2.x:min(xmin,block2.x)
    — set ymin to loopindex=0?block2.y:min(ymin,block2.y)
    
    For each block2
    — dictionary: remove key (block2.x-xmin)&”,”&(block2.y-ymin)
    
    Dictionary: is empty
    — blocks are in same configuration

    Only time that wouldn’t work is if multiple block1’s were in the same position.

    Another option is to convert both sets of blocks to arrays. You’ll need the bounding box (min,max xy) of both, then populate the arrays. Then you could loop over the arrays and check if each is identical in both. As a quick easy out you can check the sizes first.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There is also this plugin.

    construct.net/en/make-games/addons/538/rexsequencematcher-c3runtime

    Not sure if its sdk 2 though.

  • OP told me that he's making a block puzzle game, similar to this:

    So the simplest solution is to loop through each unoccupied cell on the grid and try placing the shape there, checking if it overlaps with any occupied cells.

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