# Check if imagepoints are facing

Get help using Construct 2

### » 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
2
G
1
Posts: 25
Reputation: 851

### » 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
57
S
15
G
11
Posts: 912
Reputation: 12,656

### » 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

### » 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
2
G
1
Posts: 25
Reputation: 851

### » Fri Jan 04, 2013 9:01 pm

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: 876
Reputation: 5,650

### » 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?

B
7
S
2
G
1
Posts: 25
Reputation: 851

### » 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

### » 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
57
S
15
G
11
Posts: 912
Reputation: 12,656

### » 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
255
S
65
G
34
Posts: 907
Reputation: 41,611

### » 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.
B
178
S
50
G
206
Posts: 8,686
Reputation: 127,715

Next