Nicholas Eckstein
​Game Programmer
contact@nicholaseckstein.com
​​linkedin.com/in/nicholaseckstein
​(860) 671-1769

First Blog Post. New puzzle game Progress.
August 17, 2018

Started working on a new puzzle game for mobile and web about a week ago. Not sure what I will call it, but it involves a grid of "nodes". Each level includes a certain amount of "input nodes", "output nodes", and wires placed on the board. The goal is to move the wires so that power can be transferred to the outputs. To win a level, all outputs have to be powered. To complicate things, wires cannot cross, wire's have a maximum length they can be stretched, and some wires have 1 or both ends "locked" to the board.
​​
You move wires around by clicking 1 end and dragging it to a new (valid) node.

The hardest part for me so far in development was figuring out the math behind preventing the wires from crossing. I basically had to find the intersection between 2 line segments defined by 2 sets of 2D vectors. I then ran into the another issue which was that if a wire were to touch another wire on the end whether by connecting 2 ends or in a 'T' formation, it would count as an intersection, and would therefore be invalid. I solved this by just checking to see if the intersection was equal to one of the positions of the "wire ends".

When the player is dragging a wire, I wanted the game to turn any node that couldn't be reached (whether it was out of reach or being blocked by another wire) red. Which wasn't hard at all, but I was worried that it might affect performance, since in order to figure out which nodes could be reached, it had to loop through every node, and every iteration it had to loop through every wire. First it would use the pythagorean theorem to test to weed out any nodes that were out of reach from the wire being stretched. Then out of the nodes that are left, it would do the intersection test against every wire (except the wire being stretched obviously). It try to find intersections between the wires and the line segment going from the anchored side of the wire being dragged and the current potential node.

When dragging a wire’s end, it looks exactly how you’d expect. One end is locked to the grid, and the other end stretching towards and following the mouse. This was great, but I also thought it would be cool if it would clamp to its max length, not go past any intersections, or the grid’s border. This wasn’t hard though, since clamping a vector’s magnitude is pretty trivial and is a built in function in Unity. Not allowing the end to go past any intersections wasn’t hard either since while you are dragging the wire, it is already checking for intersections. All I had to do was store the intersection point, and change the wire’s “end” position to be that instead of the mouse’s position. Then clamping the position to the grid’s border was as simple as clamping its x and y positions to the grid’s minimum and maximum points, which is equal to whatever the grid size is.

Check out my progress here: https://nicholaseckstein.itch.io/power-grid
Password: d93klsf48j