Advertisement

please help, nobody ever ansewrs my questions, the games tetris

Started by July 22, 2002 12:24 PM
1 comment, last by JinJo 22 years, 4 months ago
I gave up on a Tetris clone about a month and a half ago, as during it I had a college project and other stuff to do so I didn’t get much time on it, so I eventually got lost in old code that was poorly commented. So I got a book called Game Programming All In One, I thought this book was excellent, during the book I learnt the basics of directx (my old Tetris was done using OpenGL) and eventually the book gets you to develop a simple game engine and guides you through a breakout clone. So after finishing the book I have now decided to do a Tetris clone again. I have got quite a bit of it working and have got some nice graphics (well for me they are) and features going into it, however there’s this one major problem that was the biggest problem in my old version, getting two blocks to collide. my tetris shapes (bricks) are 4x4 arrays and the main playing grid is 10x20 each brick has an x and y offset, GridX, GridY Here is what I have got for the collision if(handleCollisionWithOtherBricks()==true) { m_kCurrentBrick.setGridY((m_kCurrentBrick.getGridY()-1)); updateGameGrid(); m_kCurrentBrick.create(m_kNextBrick.getColour()); } each shape has a different colour so it’s easy to use the colour to hold the actual shape Here’s what the collision code looks like
      
bool bricksGame::handleCollisionWithOtherBricks(void)
{
	for(int columns = 0; columns < 4; columns++)
	{
		for(int rows = 0; rows < 4; rows++)
		{
			if((m_aiPlayingGrid[m_kCurrentBrick.getGridX() + columns][m_kCurrentBrick.getGridY() + rows] > 0) && (m_kCurrentBrick.m_aiShape[columns][rows] > 0))
			{
				return mrTrue;
			}
		}
	}
	return mrFalse;
}
  

according to every guide, source that ive seen this is correct, and here is the code to my update grid code
      
void bricksGame::updateGameGrid(void)
{
	for(int columns = 0; columns < 4; columns++)
	{
		for(int rows = 0; rows < 4; rows++)
		{
			if(m_kCurrentBrick.m_aiShape[columns][rows] > 0)
			{
				m_aiPlayingGrid[m_kCurrentBrick.getGridX() + columns][m_kCurrentBrick.getGridY() + rows] = m_kCurrentBrick.getColour();
			}
		}
	}
}
      
i cant think of anything that could be wrong here. thats the only functions that i can think of that effect the problem. also when a brick hits the bottom of the grid it stays in the correct place and a new one comes down from the top if anyone can help or needs any more info ill be on gamdev for a while. [edited by - JinJo on July 22, 2002 5:49:38 PM] [edited by - JinJo on July 22, 2002 6:00:07 PM]
G''day,

Can you put a bit of a better description of the problem please, I am having difficulty understanding what the code above is doing. Like what m_aiPlayingGrid and m_kCurrentBrick.m_aiShape being greater than 0 means.

Perhaps then I can shed some light on your problem.

Doolwind
Advertisement
m_aiPlayingGrid is the main grid, the m_ means its a member variable of a class, the ai means array of ints, this is a 10x20 array of the main grid.

m_kCurrentBrick.m_aiShape is the 4x4 grid area of the m_kCurrentBrick this is a class called CBrick which holds the height and width, offsets etc

the > 0 is just checking if there is block in that space of the array, 0 means empty and anything above represents a different coloured block, ive given a better description in the game programming forum, the title is something to do with tetris, hope this helps you to help me

thanks

This topic is closed to new replies.

Advertisement