Moving objects down after objects have been deleted

Started by
7 comments, last by Greenbird 14 years, 3 months ago
Hey, sorry if my subject title doesn't make any sense but i am making a puyo puyo game and recently with the help of other forum members i was able to delete puyos of the same color. Now that they delete how would i go about having the puyos that are left over fall down to the bottom of the board or onto another puyo. I was able to come up with a solution but it ended up just deleting everything instead of moving things down. How exactly would i go about referencing the puyos that are left over after deletion and move them down? Id appreciate any help thanks again.
Advertisement
I think you have an array of puyos. If so, you should be able to start at the bottom of the board, scan the board from left-to-right (or right-to-left if you prefer), checking whether the position below each puyos is empty. If it's empty, move the puyos down. Scan from bottom to top of the board doing the same for each position.

Clear a flag, and if any puyos is moved, set the flag. After the entire board is scanned, if the flag is set, clear the flag and continue rescanning the entire board until a scan results in no moves.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Hey thanks for the great advice i did pretty much exactly what you suggested but I havnt been able to get it to work. I check the board top to bottom, bottom to top, and left to right. I create to variable top and bottom and then I set them to equal the board height and either increment or decrement in order to go from top to bottom or bottom to top.

I then check to see if top is less then bottom I then set (j) to equal the bottom and set it to less then top and then I increment (j). Then I set puyolist my puyo array to equal it self plus one in order to move the puyos down. I then set puyolist with the parameters of (i) and top to null and return.

Essentially after the puyos are deleted the puyos should fall and then it should print in what column it was that the puyos had fallen. What happens is that it always prints out the columns even before deleting but it is not reading anything on the board it constantly prints zero for the columns top and bottom. Not sure if this makes sense but let me know if you need clarification any way here is what i have. Thanks.

 public boolean freeFall(){      	    	int i, j;    	    	boolean freeFall = false;    	    	for(i=0;i<board_width;i++){    	    		int bottom = 0; int top = 0;    	            for(j=0;j<board_height;j++)    	                if(puyolist[j] == null){    	                	j = bottom;    	                    break;    	                }    	                	            for(j=board_height;j<0; j--){    	            	if(puyolist[j]!=null){    	            		if(i<0||j>MAX_X||i<0||j>MAX_Y)    	            		{    	            		if(puyolist[current[0].x/image_width][current[0].y/image_height + 1] == null &&    	            			 puyolist[current[1].x/image_width][current[1].y/image_height + 1] == null)    	            			j = top;    	            		break;    	            		}    	               }    	           }    	            System.out.println(""+top+""+bottom);    	          if(top <= bottom){    	        	  continue;    	          }    	          for(j=bottom;j<top;j++){    	        	  puyolist[j] = puyolist[j + 1];    	    	}    	          puyolist[top] = null;    	          freeFall = true;    	         }    	    return freeFall;    	    }
I'm afraid I don't understand your logic, Greenbird. It seems much more complicated than it needs to be.

Is puyolist[j] the puyo at position column i, row j on the board?

If so, why not:
bool swap = true; // ensure while loop is enteredwhile(swap) {   swap = false; // ensure while loop is exited if no swaps   for(int row = 1; row < boardheight; row++) { // from next-to-bottom to top      for(int column=0; column < boardwidth; column++) { // from left to right         if( puyolist[column][row] != NULL && puyolist[column][row-1]==NULL ) {            // move puyo down            puyolist[column][row-1] = puyolist[column][row];            // leave empty space where puyo was before move down            puyolist[column][row] = NULL;            // indicate a swap was made            swap = true;         }      }   }   // if desired, display entire board here and continue looping}

That's off the top of my head. You may have to adjust the row, column limits

EDIT: change NULL to null as required. I'm a C++ guy.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Hey thanks for the advice i was able to come up with a solution, it works but im having a problem. When the puyos delete the puyos that were not of the same color move down but there color is passed to the coordinates (0,0) the top left corner of the screen. So when another puyo falls into that space it stops on top of a blank puyo. I am not sure why this is happening i feel like there might be something wrong with my logic but if not then there is something else wrong with my program. Would you have any ideas as to why this could be happening?

 int temp = 1;                        while(y - temp > 0 )            {            	if(puyolist[x][y-temp]!= null)            	{            		puyolist[x][y] = new Puyo(puyolist[x][y-temp].color,x,y);            		            		puyolist[x][y-temp] = null;             	}            	temp++;            }            repaint();       }
I don't really understand what you're trying to do in your last post. But the line:
puyolist[x][y] = new Puyo(puyolist[x][y-temp].color,x,y);

keeps loading a new puyo in the same location (x,y) over and over. Is that what you want to be doing? Maybe you want to be changing the y value somewhere?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Hey this is what my code is doing its moving whatever puyos where left over after deletion down but for some reason after deletion the puyo that was left over becomes invisible but it is still there so when something falls on top of it, it looks as if it is floating.

      //create a temp piece and initialize it to 1       int temp = 1;                 //check while y - the temp is  greater than zero in other words while we are still        // in bounds of the board            while(y - temp > 0 )            {               //check is there is something on the board            	if(puyolist[x][y-temp]!= null)            	{                        // move the puyo down            		puyolist[x][y] = new Puyo(puyolist[x][y-temp].color,x,y);            		                         //leave an empty space where the puyo was before it was                        //moved down            		puyolist[x][y-temp] = null;             	}                //change state-move the puyo down            	temp++;            }            repaint();       }


Here is a screen cap to show specifically what is going on in my game please click on the link below Thanks again for the help:

Puyo Puyo

[Edited by - Greenbird on January 11, 2010 3:05:53 PM]
See my previous posts. Your loop doesn't move puyos down. It creates new puyos at (x,y) over and over without changing the y-value.

Again, your line of code:

puyolist[x][y] = new Puyo(puyolist[x][y-temp].color,x,y);

moves all the puyos in column x down to the same y.

I think you want to move [y-temp] to [y-temp+1].

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Hey i took your suggestion and my code still works but now instead of new puyos being made at the same location, after puyos are deleted the puyos that are left over stay in the same position they where before anything was deleted, but when moving a puyo over them the puyo goes right through it and lands at the bottom on top of an invisible puyo piece. So now what happens is, is that the puyo moves down but the color stays at its previous location. Any suggestions on how i could go about fixing this? Id appreciate the help.

This topic is closed to new replies.

Advertisement