3 Replies - 1487 Views - Last Post: 16 July 2007 - 01:01 PM Rate Topic: -----

#1 awag22   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 15-July 07

Need help with a puzzle game I'm working on in flash

Posted 15 July 2007 - 03:22 PM

Hi everyone,

I've been working on a tetris-attack-ish puzzle game in flash mx 2004 for the past week or so.

Things were going pretty well it seemed, until about two days ago when I encountered a problem I can't seem to solve. This is going to be kind of long, I hope someone is willing to read it.

First let me explain the game. Take a look at the attached screenshot and you will see
that there is a tower of blocks. You will score points by cycling a selected row of blocks to the left or right
to make a vertical line of 3 or more blocks of the same color. A new row of blocks falls from the top every few seconds.

I have the game set up so it uses two main 2d arrays to display the blocks.

blockGrid[18][8] and blockGridMclip[18][8]

blockGrid holds numbers corresponding to what the color of the block at that location is.
0 = nothing there, 1 = green, 2 = blue, 3 = orange, 4 = grey, 5 = pink.

it ends up looking something like this.

row 0: 0,0,0,0,0,0,0,0
row 1: 0,0,0,0,0,0,0,0
row 2: 0,0,0,0,0,0,0,0
row 3: 0,0,0,0,0,0,0,0
row 4: 0,0,0,0,0,0,0,0
row 5: 0,0,0,0,0,0,0,0
row 6: 0,0,0,0,0,0,0,0
row 7: 0,0,0,0,0,0,0,0
row 8: 5,4,1,4,1,3,2,2
row 9: 1,5,4,4,2,1,3,2
row 10: 4,2,5,2,2,3,3,1
row 11: 2,5,2,4,4,1,2,2
row 12: 5,5,2,5,3,2,1,3
row 13: 4,4,2,4,2,2,3,5
row 14: 4,3,3,5,3,1,2,4
row 15: 5,3,4,3,5,1,5,3
row 16: 5,2,3,5,4,4,2,3
row 17: 5,1,1,3,4,1,3,5

Then I have a function that reads all the data in the blockGrid array, and creates the blocks
of the corresponding color with movie clip objects using _root.attachMovie and puts them
into the same location in my other array, blockGridMclip[][].

I then have a function that cycles the row(cycleRow) that is currently selected by the user.
It cycles the row to the left or right by copying the data from the selected row of blockGrid into a
temp array. It will copy blockGrid[currentRow][0] into temp[1] and so on, until it reaches the end and then it puts the last element of blockGrid[currentRow][] into temp[0].

I then do the same for blockGridMclip[][] so as to keep the elements between the two arrays aligned.

after that I change the ._x value by +32 or - 32 (32pixels is the size of one block) for each move clip object
inside blockGridMclip[currentRow][] depending on the direction of the movement. The ones at the edges are handled in the same way as written above.

HERE is my problem. I want to have a function that eliminates the blocks that have been destroyed by the user.
I wrote a function to do such, and it sets the value of the destroyed blocks in blockGrid[][] to 0. Then I have it destroy the movieClip object that corresponds to that location in blockGridp[][].
However when I destroy the object, the ._x for that location no longer exists. So when the cycleRow function
is called and wants to cycle the ._x locations for that row, the data doesn't exist for the location of the objects that were destroyed.
I'm not really sure what to do about this. I've tried various things but none of them seem to work.

Any help would be appreciated. I'm posting the code for the cycleRow function and the function that erases the matched blocks below this post. If you need to see more of the program please let me know and I will post it.

thanks in advance,
awag







here is cycleRow

function cycleRow(row, direction)
{
	
	// cycle to the left
	
	if(direction == "L")
	{
		
		tempArray = new Array(blockGrid[0].length);
		
				for(count=0; count < blockGrid[row].length; count++) 
				{
					tempArray[count] = blockGrid[row][count+1];
					
					if (count+1 > blockGrid[row].length - 1)
					{
						tempArray[7] =
						blockGrid[row][0];
					} // end if
					
				} // end for
				
	// copy the temp array back into the current row in blockGrid		
		for(count=0; count < blockGrid[row].length; count++) 
				{
					 blockGrid[row][count] = tempArray[count];
					 tempArray[count]=0;
				}// end for
				
	// do the same thing for blockGridMclip[row][] so the elements still match the data in blockGrid
				for(count=0; count < blockGridMclip[row].length; count++) 
				{
					tempArray[count] = blockGridMclip[row][count+1];
					
					if (count+1 > blockGridMclip[row].length - 1)
					{
						tempArray[7] =
						blockGridMclip[row][0];
					} // end if
					
				} // end for
				
		for(count=0; count < blockGridMclip[row].length; count++) 
				{
					 blockGridMclip[row][count] = tempArray[count];
					 tempArray[count]=0;
				}// end for	
				
				
	// change the ._x of the movie clips
				for(count=1; count < blockGrid[row].length; count++) 
				{
					tempArray[count] = blockGridMclip[row][count-1]._x;
					
					if (count == blockGrid[row].length - 1)
					{
						tempArray[0] = blockGridMclip[row][blockGrid[row].length-1]._x;
					}
			
				}// end for
				
				for(count=0; count < blockGrid[row].length; count++) 
				{
					 blockGridMclip[row][count]._x = tempArray[count];
					 tempArray[count]=0;
				}// end for
	} // emd if "L"
	
	
	// cycle to the right
	
	if(direction == "R")
	{
		tempArray = new Array(blockGrid[0].length);
				for(count=1; count < blockGrid[row].length; count++) 
				{
					tempArray[count] = blockGrid[row][count-1];
					if (count == blockGrid[row].length - 1)
					{
						tempArray[0] = blockGrid[row][blockGrid[row].length-1];
					}
				} // end for
				
				for(count=0; count < blockGrid[row].length; count++) 
				{
					 blockGrid[row][count] = tempArray[count];
					 tempArray[count]=0;
				}// end for
				
	// do the same for the movie clip array
	
				for(count=1; count < blockGridMclip[row].length; count++) 
							{
								tempArray[count] = blockGridMclip[row][count-1];
								if (count == blockGridMclip[row].length - 1)
								{
									tempArray[0] = blockGridMclip[row][blockGridMclip[row].length-1];
								}
							} // end for
							
							for(count=0; count < blockGridMclip[row].length; count++) 
							{
								 blockGridMclip[row][count] = tempArray[count];
								 tempArray[count]=0;
				}// end for
	
	
	
		// change the ._x of the movie clips
				for(count=0; count < blockGridMclip[row].length; count++) 
				{
					tempArray[count] = blockGridMclip[row][count+1]._x;
					if (count+1 > blockGridMclip[row].length-1)
					{
						tempArray[7] =
						blockGridMclip[row][0]._x;
					}
					
				}// end for
				
				for(count=0; count < blockGridMclip[row].length; count++) 
				{
					
					 blockGridMclip[row][count]._x = tempArray[count];
					 tempArray[count]=0;
				}// end for
		
	} // end if "R"			

	
}





here is matchBlocksCheck

function matchBlocksCheck()
{

	for(i = 0; i < blockGrid.length; i++)
	{
		trace("row " + i + ": " + blockGrid[i]);
		for(j = 0; j <  blockGrid[i].length; j ++)
		{
			if (blockGrid[i][j] != 0)
			{
				if(blockGrid[i][j] == blockGrid[i+1][j])
				{
					if(blockGrid[i][j] == blockGrid[i+2][j])
					{
						
						killBlock(blockGridMclip[i][j]);
						killBlock(blockGridMclip[i+1][j]);
						killBlock(blockGridMclip[i+2][j]);
						
						blockGridMclip[i][j] = 0;
						nextBlockRow[j] = 0;
						blockGridMclip[i+1][j] = 0;
						blockGridMclip[i+2][j] = 0;
						
						blockGrid[i][j] = 0; 
						
						erasedX = i;
						erasedY = j;
						blockGrid[i+1][j] = 0;
						blockGrid[i+2][j] = 0;
						
						//trace("blockGrid["+i+"]["+j+"] = " + blockGrid[i][j]);
						
					} // end if
				}// end if		
			}// end if
			
		}// end for
	}// end for
}


Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Need help with a puzzle game I'm working on in flash

#2 awag22   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 15-July 07

Re: Need help with a puzzle game I'm working on in flash

Posted 16 July 2007 - 09:01 AM

Even if you don't have time to look at all my code and stuff, comments are welcome. bump
Was This Post Helpful? 0
  • +
  • -

#3 Trogdor   User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Re: Need help with a puzzle game I'm working on in flash

Posted 16 July 2007 - 09:39 AM

Would replacing the destroyed blocks with a placeholder for empty spaces help ?
That way you would not have holes in the array.
The other way is to let the cycleRow check if it needs to actualy do something on a certain position by checking if the corrosponding color is > 0 in the blockGrid array.
Was This Post Helpful? 0
  • +
  • -

#4 awag22   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 15-July 07

Re: Need help with a puzzle game I'm working on in flash

Posted 16 July 2007 - 01:01 PM

Thanks for the response Trogdor. That sounds like it would work. So I'll make
all the places that had objects which got destroyed in them = 0. Then I guess I can do something like if (that spot in the array == 0) make that x coordinate = counter * width of a block. I'll try it when I get home from work!

thanks,
awag
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1