Tuesday, May 13, 2014

Snake Bit.


I have been struggling off and on with a pretty simple problem with the puzzle game I am creating.  I had it working pretty well at the beginning of last week.  Touch a square and if there are available nearby flows, then start pushing those flows into the square.  Touch all the squares on the board and get them all filled up and you have completed the puzzle.  Pretty simple concept.  I was really digging the interaction, but about 5 days ago I decided to make some changes to show the 'flows' a little better.  I thought little arrows showing the active flow channels would be handy to the player and also help me to confirm everything is working correctly.  I also thought the arrows would help me explain the concept of flows to my family.  This was my solution to showing how the game works, but it was also the root of my struggles.   I did not realize it until about 10 minutes ago.
  Since the squares are all adjacent to each other, I setup up the squares to notify the main game board when they have been touched.  "Hey, you touched me and I am Square (4,5)!"  The the game board checks the square's neighbors and determines the appropriate actions, etc...    This was working pretty well early last week.  Then about the same time that I decided to move the game board squares onto an actual game board sized widget, the squares started overlapping each other.  Click on square (1,2) and you might get (1,2) or you could get the neighbor (1,3).  "Wait a minute!  This was working before I added the underlying game board graphic!"  The squares looked the same, but seemed confused about which square was touched.  I assumed it was putting everything on the new board graphic and proceeded to debug the heck out of everything associated with that layout.  It was a problem for the better part of the last 5 days for me.  I could not figure out this simple problem and it was frustrating.  After a bit of this, I would switch to another aspect of the game and vow to fix the problem later.    Maybe work on the button layout, flow graphics, and game screens for a bit and then come back to this issue.  No luck.  Frustrated again.
  In the end, it was not the board graphic or repositioning the squares.  It was the darn flow arrows I had added to the square.  They were created, but invisible until needed.  I did not get much chance to really debug them before I discovered this square problem, but I did notice that they were not always positioned inside the square they belonged to.  No problem, I will adjust them later I thought.  Well as you can probably guess, it was the stray arrows that were causing the bad square identification.  Move those arrows back into their respective square or remove them completely, and the squares worked fine.
    I guess the take away for this was that I chewed up a lot of time and thought trying to fix the wrong part of the code.  Heck, I could even see the arrows were not located in the right square when they worked.  As my Dad would say, "If it was a snake it would have bit me."  Moving the squares around before getting the arrows working right bit me real good.  Programming can be a joy, but occasionally, it can also slap you in the face with your own stupidity.  
   

No comments:

Post a Comment