Check if imagepoints are facing

0 favourites
  • 11 posts
From the Asset Store
Fully animated four directional dungeon guards pack
  • 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

  • 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.

  • 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.

  • 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.

    How would this work for a pipe that is curved at one end?

  • 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.

  • 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.

    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

  • 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.

    Nicely done... I like this solution as well.

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

    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.

    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?

    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.

  • 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.)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • Thanks all i think array is the way to go although i have read the array tutorial I'm still struggling to understand how an array object works with a foreach (ordered) loop on my pipes.

    can someone explain to me what exactly happens when you run this function on a layout with say 2 rows of pipes with one pipe on the top and two pipes on the bottom? How should the array look if its a 2d array

    sorry hope this makes sense

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