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

Just started using Construct 2? Post your questions here

Post » Sat Jan 10, 2015 11:37 am

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.
B
8
S
2
Posts: 59
Reputation: 686

Post » Sat Jan 10, 2015 11:40 am

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.
B
8
S
2
Posts: 59
Reputation: 686

Post » Sat Jan 10, 2015 7:01 pm

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.
You do not have the required permissions to view the files attached to this post.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Mon Jan 12, 2015 10:18 am

Thanks for your help, R0j0hound; it works well.
B
8
S
2
Posts: 59
Reputation: 686


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests