Newbie in Tetris hell - please help

Started by
79 comments, last by Sir_Spritely 22 years ago
PLease someone, end my torment. I''m doing Tetris and what I along with some help have come up with is two have two arrays, one for the actual gamegrid which is set to 0 showing that it is empty or there is a space. The other array contains 1''s in the shape of a game peice. The arrays: -
  
//Actual playfield array - might need changing work out size

UCHAR blockgrid[NUM_BLOCK_ROWS][NUM_BLOCK_COLUMNS] = {
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
	
};

//This will store the game peice

int GameBlock[NUM_BLOCK_ROWS][NUM_BLOCK_COLUMNS] = {
	{1},
	{1},
	{1},
	{1}
	
};
  
What I have next is a nightmare, I am trying to put the GameBlock array onto the block_grid array. So the 1''s represent single blocks on the block_grid. This is what I got: -
  
void Draw_Block(void)
{
	for (int row = 0; row < NUM_BLOCK_ROWS; row++)
	{
		for (int col = 0; col < NUM_BLOCK_COLUMNS; col++)
		{
			if (GameBlock[row][col] == 1)
				{
				block1.x = col * block1.height;
				block1.y = row * block1.width;
				Draw_BOB(&block1, lpddsback);
				}

			if (blockgrid[row][col] == 1)
			{
				block1.x = row * block1.width;
				block1.y = col * block1.height;
				Draw_BOB(&block1, lpddsback);
			}
		}
	}
}
  
It works in that the single blocks are drawn together to represent the game peice but it is out of position on the screen and also when I take out the last if (blockgrid[row etc. statement completely it still works? WHY?? Also if I get rid of the block.x and block.y statements in the top if statement then the block is then drawn in the correct location on the screen but only one block is drawn. I think the rest are being drawn behind it but not sure. What I would appreciate is if someone could talk me through whats going on because I just don''t get it, what is it doing? Also am I doing it the right way, by copying over the bits from one array to another. I am trying to do it in C rather than c++ because it''s easier in C Any help really really appreciated it''s already taken me a month LOL Paul
Advertisement
i advise you to code all your figures possibilities.
they will be stored into a 4*4 bit matrix.

ie

....
.
.****
.
.

....
. *
. *
. *
. *

and so on...


And then you know what you have, where you have.

your idea of storing everything in an array is good too.

i can''t tell you more.

hope this help.

Educate the masses ! it''s one behavior !
Educate the masses ! it's one behavior !
Just trying to understand and get one to work at the moment before I add other game peices. I have also tried and probably will have the game peices in a 4*4 array.

Still stumped though
I don''t understand why you need 2 arrays? It looks like you''re doing the same thing to each one.

I would think you only need one array and then you do some simple collision detecting. Where are you running into your problem? Can you drop one block all the way down to the bottom and the problem is when you start with another one...

I need more information.
Yeah I was told I needed 2 arrays now unless I made a mistake somewhere I came to the same conclusion that 2 arrays are not needed.

The problem is I can drop one block all the way down no problem but what I can''t do is make a game peice up with four seperate blocks and move all the four blocks down as one entire game peice.
The reason the if(Blockgrid[row][column]==1) isn''t useful is that, as far as I can see, you never set anything in the Blockgrid to one.

Second, where is block1 declared? I think the reason you''d only see one block is that it''s a global variable somewhere (thus, always valid memory) and set once. So if you don''t set it again, it just draws the default over and over.

Hope that clarified things for you.
Erm, no it doesn''t LOL. I know it should but I just don''t get it, I think I''m losing it LOL.

I get what your saying about the blockgrid == 1 being a waste but setting the block1??

It is declared as a global and loaded in once, but I presumed much in the same way my breakout worked the array is saying if there is a number 1 in there then draw a block so regardless of how many times block is loaded in it will copy the one block loaded in as many times as the array wants (if you get that - cos I don''t).

What I think I was trying to do was was store the game peice in one array and then transfer that over to the main array. for example the game grid would be blank to start so all there would be would be 0''s in it. Once a game peice is asked for then there will be a 1111 in place of some of the 0''s if you see what I mean.

I kinda don''t get it though - thats bad when you dont get what trying to do ya know.

Pk
I''m probably missing something, but why do you set the x co-ord of the block to the height times the column if it is a game block, but then set it to the width times the row? Shouldn''t it be the same either way?

Please pardon this if I''ve overlooked something stupid, it''s quite early in the morning .
I know theres a reason for it but I can''t think what it is right now LOL - jeez - anyone ever felt like giving up?

pk
I would suggest adding some debugging code to see what''s happening. Something like this:

  if (GameBlock[row][col] == 1)				{        cout << "row:" << row << ".col:" << col << endl; 	        block1.x = col * block1.height;				block1.y = row * block1.width;        cout << ".x:" << block1.x << ".y:" << block1.y << endl;	Draw_BOB(&block1, lpddsback);				}if (blockgrid[row][col] == 1)			{        cout << "row:" << row << ".col:" << col << endl; 	block1.x = row * block1.width;				block1.y = col * block1.height;	        cout << ".x:" << block1.x << ".y:" << block1.y << endl;		Draw_BOB(&block1, lpddsback);			}  


Then you can look in the console to see when your code is firing and make sure block1.x and .y are getting the values you expect.
---------------Delphi 6 Personal Edition, free for non-commercial use.

This topic is closed to new replies.

Advertisement