How do I collision check for same the object at offset?

0 favourites
  • 4 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Hi forums,

    I am creating a mining game where you use touch controls to tap blocks to destroy them. At the moment I am using a simple function which identifies the block that was tapped by UID and feeds it to a function that destroys the block.

    These blocks are all in a grid next to each other and none of them overlap. They are all the same sprite but different animation frames (which gives them a different appearence).

    I want to make the function destroy blocks ONLY if there is not completely surrounded by other blocks, i.e.

    010

    121

    010

    If you imagine that the numbers are all blocks of the same sprite. If the user tapped the '2' block it would NOT be destroyed because the game, ideally, chcked and found that it was surrounded.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • And some more examples (please consider a 0 as a non existent block):

    000

    021

    111

    Clicking the two in this example should destroy the block, because it has found that there are no blocks directly above it, or directly to the left.

    000

    121

    111

    Clicking the two in this example should also destroy the block because it has found that there are no blocks directly above it.

    111

    121

    000

    And one again, clicking 2 is fine because there are no blocks below it this time.

  • You can do this:

    1. save the x,y of the clicked object in some variables.

    2. pick all the sprites and check if the points overlap a sprite at offsets x+32,y x-32,y x,y+32 x,y-32

    3. If all four offsets pick a sprite then don't destroy the clicked object.

  • Thanks for your help, R0j0hound; it works well.

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