# Not sure how to go about allowing points on a grid to talk to each other?

This topic is 2584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a grid setup and need to draw squares on it, which I am currently doing... But the problem is I only allow the user to select two points per turn and that should draw a line and it does.

Now the problem starts...
e.g.
Player selects top two points, and bottom two points, I end up rendering a square when the player has only selected the top and bottom lines, and they still need to select the right and left sides also before they gain the whole square.

I don't know what kind of data structure would work best for this, but I am using vectors and a 2D array to get the data setup so far... Seems like a simple problem but now sure about the logic on what I am missing to fix this issue. Do I need to have each square with its own 4 points? If so then each square needs to talk to each other square next to it to see if those points have been taken and if not allow them to be claimed or denied....

Thanks

##### Share on other sites
Your problem is most likely that you are drawing a line to every position in the array like so:
 for (int i;i<size-1;i++) { draw_line(array.x,array.y,array.x+1,array.y+1); } 
When it should be doing like this:
 for (int i;i<size-2;i+=2) { draw_line(array.x,array.y,array.x+2,array.y+2); } 

If you are using OpenGL your problem could be you are using
GL_LINE_STRIP

GL_LINES

Do I need to have each square with its own 4 points?[/quote]
This is up to you, a program can do whatever you want it to.

i+=2

i++

Good Luck,
Coder Walker

##### Share on other sites

Your problem is most likely that you are drawing a line to every position in the array like so:
 for (int i;i<size-1;i++) { draw_line(array.x,array.y,array.x+1,array.y+1); } 
When it should be doing like this:
 for (int i;i<size-2;i+=2) { draw_line(array.x,array.y,array.x+2,array.y+2); } 

If you are using OpenGL your problem could be you are using
GL_LINE_STRIP

GL_LINES

Do I need to have each square with its own 4 points?

This is up to you, a program can do whatever you want it to.

i+=2

i++

Good Luck,
Coder Walker
[/quote]

Thanks for the reply Coderwalker, what I ended up having to do is, instead of having a conditional variable for each point, I moved it to each line segment and that solved my issue. But I understand your point and will keep that in mind if I run into that issue. Thanks!

• 41
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631371
• Total Posts
2999614
×