Destroy an object when surrounded

Discussion and feedback on Construct 2

Post » Tue Jan 12, 2016 11:14 pm

I am trying to destroy an object when it is surrounded on four sides. I tried an event with four conditions, when object is overlapping at offset -- for four different directions.

I am probably not understanding something about how this event should work.

Event I have is:
Code: Select all
sprite is overlapping at offset(32, 0)
sprite is overlapping at offset(0, 32)
sprite is overlapping at offset(-32, 0)
sprite is overlapping at offset(0, -32)     
      action:  sprite destroy



capx is here: https://dl.dropboxusercontent.com/u/66037205/DestroyWhenSurrounded.capx
B
32
S
13
G
2
Posts: 4
Reputation: 2,863

Post » Tue Jan 12, 2016 11:33 pm

Select all 4 "is overlapping", click rmb, and select "or". And I think that should work.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
76
S
20
G
19
Posts: 1,931
Reputation: 17,159

Post » Wed Jan 13, 2016 3:51 am

Thanks for your quick reply!

What I am needing is for "Surrounded" to be true if there is an object on all four sides (and result in the object being destroyed). By using or, I think that would make the condition true if there is an object on any of the four sides.
It seems like my logic should work, but it does not. It may be due to the way overlap at offset is tested?

It could be that there is a completely different way to test for this condition that I am missing.

Basically I need to answer the question "Am I blocked in all four directions... surrounded on all four sides by something".
B
32
S
13
G
2
Posts: 4
Reputation: 2,863

Post » Wed Jan 13, 2016 4:01 am

If you want same object, then you must use families. Create two: 1st, 2nd ( just for tests ), and do events like this : 1st overlapping at offset 2nd, destroy.

Thing is... looking at the capx, this way you will destroy all, probably.

Eventing in construct s really context dependent. Again, looking at capx it's hard to know what you're after. If in your game objects that are surrounding main objects are not the same, then what you're doing right now is, sorry to say, pointless. But if they are the same object, then you mist go deeper. So you must do conditions for two situations: one is that object s surrounding same object, but only at one offset, then use or ( and families ), but you must find a way to specify that if objet os surrounded from 4 sides, it is not being destroyed. Boo ( boolean ) var ( variable) might help in achieving this.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
76
S
20
G
19
Posts: 1,931
Reputation: 17,159

Post » Wed Jan 13, 2016 4:10 am

Each condition filters the objects so I think if you add a "pick all" between each condition it should work. The object that "pick all" should use is the one the Sprite is overlapping with.
B
85
S
27
G
85
Posts: 5,070
Reputation: 57,874

Post » Wed Jan 13, 2016 4:38 am

With your help, I found one way to solve this using a family. Here is the solution that I found:
For the purpose of this test, it is done once start of layout so event looks like this:

(please excuse poor representation of actual events... I need to learn how to represent this better in text)
Code: Select all
at start of layout
for each Sprite     -> Sprite set scale 1.1
     Sprite is overlapping Surrounders (this is a family with memeber Sprite in it)
     Surrounders.PickedCount = 4                                                                                      -> Sprite.Destroy


capx here: https://dl.dropboxusercontent.com/u/66037205/DestroyWhenSurrounded_B.capx
B
32
S
13
G
2
Posts: 4
Reputation: 2,863

Post » Wed Jan 13, 2016 8:18 am

how about instead of overlapping with offset you start using dist (sprite1.x, sprite2.x, sprite1.y, sprite2.y) <32 -> destroy sprite1 ?

problem with overlapping - imagine my object is a big ">" form like this one (sprite 1). And now imagine your second sprite is a dot "."

if you check for overlapping with -32 x and y - they will never overlap and therefore your event will never fire, even though the dot is under 32 distance from <.

Also you have to take in that origin point of your sprite is the point where you calculate your stuff from. not borders. sprite x,y = origin point. So using distance from sprite 1 to sprite 2 you get this:

if ( dist (.x,.y,<.x,<.y) < 32)
destroy <
(it won't matter if left, right top or down, each will work. )

math pls.
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
39
S
14
G
12
Posts: 617
Reputation: 9,297

Post » Wed Jan 13, 2016 2:42 pm

saiyadjin wrote:how about instead of overlapping with offset you start using dist (sprite1.x, sprite2.x, sprite1.y, sprite2.y) <32 -> destroy sprite1 ?

problem with overlapping - imagine my object is a big ">" form like this one (sprite 1). And now imagine your second sprite is a dot "."

if you check for overlapping with -32 x and y - they will never overlap and therefore your event will never fire, even though the dot is under 32 distance from <.

Also you have to take in that origin point of your sprite is the point where you calculate your stuff from. not borders. sprite x,y = origin point. So using distance from sprite 1 to sprite 2 you get this:

if ( dist (.x,.y,<.x,<.y) < 32)
destroy <
(it won't matter if left, right top or down, each will work. )

math pls.


In certain circumstances distance is of no good use, for example n isometric view. But otherwise it is very useful.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
76
S
20
G
19
Posts: 1,931
Reputation: 17,159

Post » Wed Jan 13, 2016 3:11 pm

since he asked left, right, up and down i'm pretty sure isometry isn't the case here :)
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
39
S
14
G
12
Posts: 617
Reputation: 9,297

Post » Wed Jan 13, 2016 3:16 pm

you can always have 4 hidden objects in, following the object u want to be surrounded.
when all 4 are overlapped destroy the main one? u can also try it with the chess board plugin from r0j0hound i think ... considering at all time the slots around the main object ... then there is another way... similar to the first suggestion ... the same way u do match games... but that is a bit array based and slightly difficult since involves some more then usual math .... those algebra hours wold come in handy now... to bad i always did something else at the class...

another way the simple c2 way is to check for position but not for overlapping... but for the X + - y + - something and in center being the position of the main object... which i think its easier to do then the rest of the above i used something similar to create a cue stick angle position and guide line for a pool example il try find it if u dont get some more help till then i guess :P

ie: 1 event with 5 conditions inside pos x= mainobjx+mainobjwidth and so on ...considering the squares are equal to the objects width and height
Image
B
64
S
19
G
67
Posts: 1,310
Reputation: 42,005

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests