Author Topic: Grid Interactivity Help  (Read 9595 times)

TwistyD

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 10
    • View Profile
Grid Interactivity Help
« on: May 07, 2014, 06:35:21 PM »
Hello,

I posted on here earlier about a project that I'm working on. Thanks to a moderator who knew NGUI well I was able to get part of the functionality working, but after a few days of trying to attack the next problem I'm at a state where I need to call for help again.

To set up the problem. I have a match three game where the player fires blocks upwards at a grid of blocks. The layout is arranged like so:




The player can move left and right with the arrow keys and fire blocks upward using the spacebar.

With the help of this forum I'm able to have the player fire blocks at the grid, however I need be able to add blocks to the grid and create matches.

For instance, ideally, when I fire a block up, I would think that the block would simply add itself to the grid at the exact place where it was stopped. However I'm finding implementation of this type of functionality difficult.

I'm going to post my project (Without NGUI of course don't want to break the rules). I was wondering if someone could help me implement this functionality and explain what needs to go on for it to work.

Link to Project zip: https://drive.google.com/file/d/0BzzyvgUvdDcFaWJnSWdLblloLTQ/edit?usp=sharing

LightSky

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 2
  • Posts: 56
    • View Profile
Re: Grid Interactivity Help
« Reply #1 on: May 07, 2014, 07:02:13 PM »
NGUI's grid wouldn't add it directly below where the block was hit.  It will add it in a linear fashion as such to what you begin with.   

At quick glance would it be more effective to have the grid already pre-populated with blank squares and then read in which square was hit and then activate/set the blank square below it?  That way you won't have to call the Grid's reposition method which would "mess up" the ordering you were going for.

TwistyD

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Grid Interactivity Help
« Reply #2 on: May 07, 2014, 07:20:18 PM »
I have somewhat of an idea about how to set it up but I need help with the interactivity portion, specifically what the script should do when a fired block collides with a block that's already filled in, or how to remove a matched set of blocks from the grid.

LightSky

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 2
  • Posts: 56
    • View Profile
Re: Grid Interactivity Help
« Reply #3 on: May 07, 2014, 07:37:49 PM »
I have somewhat of an idea about how to set it up but I need help with the interactivity portion, specifically what the script should do when a fired block collides with a block that's already filled in, or how to remove a matched set of blocks from the grid.

Create a two dimensional to keep track of all the elements in your grid. 
You will have to write a custom script to parse through the array.  Just create a function that will take a direction you want to move based on the element's position you are checking.  Using this you can easily parse through nearby elements and check if they are the same color.

Ex:  If you fire a square and it hits another square,  call the function to check if the one above/left/right of it are the same color.  If that returns true then check further on as needed.  If lets say, three are matching colors, then "remove" (deactivate the elements) and add points to the player.

TwistyD

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Grid Interactivity Help
« Reply #4 on: May 07, 2014, 08:05:52 PM »
I don't know what a 2 dimensional is I'm sorry...Is it like a list or a 2D array?

Also if I removed the elements wouldn't that make it harder to add a block there sense there wouldn't be a collider for it to check against?

LightSky

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 2
  • Posts: 56
    • View Profile
Re: Grid Interactivity Help
« Reply #5 on: May 07, 2014, 08:15:36 PM »
I don't know what a 2 dimensional is I'm sorry...Is it like a list or a 2D array?

Also if I removed the elements wouldn't that make it harder to add a block there sense there wouldn't be a collider for it to check against?

Yes a two dimensional array. I forgot a word  :P

Don't "remove" the blocks, instead have a Boolean variable to check to see if they are active.  If you set a element as inactive then set the sprite to be transparent or just disable it.  For activating it you will just check to see what the incoming object is and set it to those properties.  This way you still maintain a perfect grid.