Error in game need help fixing

Started by
0 comments, last by gzboli 14 years, 3 months ago
Hey guys, im creating a puyo puyo game and after hours of trying to get puyos that were not of the same color to fall after others where deleted i have found that the reason it was not working was because of an error. I found the error but im unsure on how to fix it, the error concerns rotation. If you have not played puyo puyo, puyos fall in pairs like this: (1)(2) In the game you are able to rotate them as well like this: (1) (2) (2) or (1) and also rotate them to the side like this: (1)(2) or (2)(1). In my collision detection code i check to see if only one puyo has hit a stack of puyos like this :(1)(2) (1)(2) i also check to see if only one puyo has hit a stack like this: (1)(2) (1)(2) If this one puyo case happens if there is nothing underneath the puyo that hasn't collided with anything it falls until it reaches the bottom of the board or until it collides with another puyo. My problem is, is that when i rotate my puyo to say (1) (2) if it hits a stack like this: (1) (2) (1)(2) my code assumes its a one puyo case and the top puyo is deleted and when rotated to the bottom the top puyo is moved down and the bottom puyo is deleted. My question is, is that how do i differentiate between the two cases? Meaning if i rotate the puyo to the top and or bottom how would i have it know that it is a rotated puyo and that it doesn't meet the criteria of only one puyo hitting a stack of puyos. So that is would leave it alone and not delete the puyo either on top and or bottom. I appreciate any help i apologize for the lengthy question. Here is my code:

// Here i check if whether underneath the puyo is not null meaning that there is something underneath it.

if(puyolist[current[0].x/image_width][(current[0].y+DELTA_Y)/image_height] != null)
        	{
        	
  //i then check if there is nothing underneath the puyo connected to the other puyo
  // it should move down.	
            while(puyolist[current[1].x/image_width][(current[1].y+DELTA_Y)/image_height] == null 
&& current[1].y + DELTA_Y + image_height < MAX_Y)
            	   {
            		   
            		   current[1].y += DELTA_Y;
            	   }









[Edited by - Greenbird on January 13, 2010 1:08:52 PM]
Advertisement
From what I can tell, the while loop is to move down the current[1] puyo... But it fails in the case where the double-puyo is vertical because the current[0] has not yet been placed in the puyolist so current[1] falls through current[0]. The checks need to occur such that you check the lower puyo's collision first and place it in the list then do the other puyo. The lower puyo could be either current[0] OR current[1].

I think the way I would address it is: (1) Select the lowest puyo, handle and place it. (2) Select the other puyo, handle and place it. (3) Make some functions to make the code more legible and reusable.

Something like:
//implemented elsewherebool CanMoveDown(Puyo& p);void MoveDown(Puyo& p);void PlaceInPuyoList(Puyo& p);...//Select the lower puyo into puyoA, the other into puyoB.int index = (current[0].y < current[1].y)? 0 : 1;Puyo& puyoA = current[index];Puyo& puyoB = current[(index + 1) % 2];while(CanMoveDown(puyoA))   MoveDown(puyoA);PlaceInPuyoList(puyoA);while(CanMoveDown(puyoB))   MoveDown(puyoB);PlaceInPuyoList(puyoB);

This topic is closed to new replies.

Advertisement