Check if imagepoints are facing

Get help using Construct 2

Post » Fri Jan 04, 2013 8:32 pm

So I have a pipe based game, where the idea is to rotate the pipes so they join together. Each pipe obviously has two ends and rotates 90 degrees each time.

I have the rotation working and have set an Imagepoint for each end of the pipe (End1 and End2).

If I have let's say a 4x4 grid, each containing an instance of my Pipe sprite how can I check if at any point their ImagePoints are facing each other (in otherwords we can connect the two pipes). This method would need to work as I scale up the grid to say 50 x 50.

Does anyone have any idea? This forum rocks btw, always get a quick answer!

Many thanks
B
7
S
1
G
1
Posts: 25
Reputation: 701

Post » Fri Jan 04, 2013 8:46 pm

I'd suggest that you create a very small, invisible block that is stuck to each image point on each pipe object. Testing to see if they're facing each other then just becomes a matter of testing whether a block is overlapping another block.

capx, without the grid system implemented.GeometriX2013-01-04 20:55:01
B
56
S
15
G
10
Posts: 910
Reputation: 11,942

Post » Fri Jan 04, 2013 8:47 pm

You could always check the angle of the sprite. If you have one straight pipe sprite you rotate, the object's angle would tell you exactly which way the pipe is pointing.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Fri Jan 04, 2013 8:49 pm

[QUOTE=Nimtrix] You could always check the angle of the sprite. If you have one straight pipe sprite you rotate, the object's angle would tell you exactly which way the pipe is pointing.[/QUOTE]

How would this work for a pipe that is curved at one end?
B
7
S
1
G
1
Posts: 25
Reputation: 701

Post » Fri Jan 04, 2013 9:01 pm

I saw your other thread earlier but didn't have time to reply.

If you're making it the same as the game in the youtube video, as in, the pieces are already on the board just ready to be rotated, then it's quite simple.

You place all the pieces in the layout editor to make the final result. Place them in the order you want the flow.

Use an array to store the angle of each object (ordered).

On start of layout, go through each piece and assign a random angle - choose(0,1,2,3) * 90. This will jumble the angles.

To check if they're connected, loop through each object and see if it's the correct angle as its array counterpart. Stop looping at the first wrong angle. That's where the water will be up to so just change the frame of each object that is correct, to that of the water filled piece. Do this everytime a shape is rotated. Shouldn't be that much of a performance hit, if any.

You'll need to have rules based on which way the water will flow (you'll most likely need 2 different animations showing the flow of water from edge A to edge B, and one to show edge B to edge A).

It's a little bit more work than that, but that's the method that pops into my head when I watch the video.

My mind is a bit foggy otherwise I'd have a crack at it. Maybe tomorrow.. ;)

Hopefully that gives you some ideas.
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Fri Jan 04, 2013 9:02 pm

[QUOTE=GeometriX] I'd suggest that you create a very small, invisible block that is stuck to each image point on each pipe object. Testing to see if they're facing each other then just becomes a matter of testing whether a block is overlapping another block.

https://dl.dropbox.com/u/14522925/PipeConnections.capx, without the grid system implemented.[/QUOTE]

Thanks Geometrix that's awesome, this is how I envisaged ImagePoints working but obviously not! Sorry I'm new!

Thanks for the capx that's exactly what I need. So is pinning the way to go for this or do I add a box to the actual image?

Thanks for your help guys
B
7
S
1
G
1
Posts: 25
Reputation: 701

Post » Fri Jan 04, 2013 9:44 pm

[QUOTE=GeometriX] I'd suggest that you create a very small, invisible block that is stuck to each image point on each pipe object. Testing to see if they're facing each other then just becomes a matter of testing whether a block is overlapping another block.

https://dl.dropbox.com/u/14522925/PipeConnections.capx, without the grid system implemented.[/QUOTE]

Nicely done... I like this solution as well.
B
13
S
4
G
3
Posts: 75
Reputation: 3,425

Post » Fri Jan 04, 2013 11:25 pm

[QUOTE=curv]Thanks Geometrix that's awesome, this is how I envisaged ImagePoints working but obviously not! Sorry I'm new![/QUOTE]
@curv My pleasure :) I've only been using Construct for a few months so I know what it's like when you're just starting out. The thinking behind image points seems to be purely as pre-designated XY values for images, usually used for spawning new objects or when moving objects. So they're perfectly suited as particle spawn locations, for example. I've been using multiple image points extensively in my current project and they're a godsend.

[QUOTE=curv]Thanks for the capx that's exactly what I need. So is pinning the way to go for this or do I add a box to the actual image?[/QUOTE]
Yup, you'll need to pin the collision boxes to each image piece so that they follow along when the pipes are moved or rotated. Pinning is always relative to its location before it's pinned, so position it first, then pin it.
B
56
S
15
G
10
Posts: 910
Reputation: 11,942

Post » Sat Jan 05, 2013 1:47 am

There's always several ways to do things.
Actually I wouldn't pin objects to every imagepoint, I would just move it to the point I'm scanning, check for overlap, and move it to the next. (less overhead, if it isn't already done.)

Actually I just remembered, I did a pipe game once, (way back in Amiga days,) I believe it checked against a list, pipes 1 to 4 had openings on the left, 2-6 had openings on the top, etc.

(It didn't flow water though, it was just legal places to drop your next pipe.)Paradox2013-01-05 02:10:09
B
200
S
51
G
30
Posts: 896
Reputation: 36,494

Post » Sat Jan 05, 2013 2:58 am

Why not just use an array?
All you have to do is create an angle value either 0,90,180 or, 270, and then test if the "cells" around the object match up.
Just remember that the array coordinates would be multiplied by the grid size. IE array at x1,y1 would be x32, y32 if the individual cells are 32x32.
So you would check if array at this x, and this y has a value of 0, and the value of this x +1, and this y is 180 then you would have two pipes horizontally.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Next

Return to How do I....?

Who is online

Users browsing this forum: BinaryPanda, MarkThomas and 18 guests