• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Prolly stupid but...

## Recommended Posts

##### Share on other sites
Tybal    122
I''m kind of doing something similar at the moment actually, the way I''m planning to do it is to keep the piece always on the bottom-left of the 4*4 array. Then you''d have to keep the piece''s bottom left position in relation to the game play grid. So if you have the grid full of random blocks, to check collision with pieces below, you only have to check the bottom of your grid with the game grid. So say you have the line piece
0 0 0 00 0 0 00 0 0 01 1 1 1

and are trying to check to see if it will collide with the grid, you check the 4 squares right below that line up with the 4 squares of your piece. For checking with the sides, you can just use the bottom-left point to check with the left side, because you always keep your piece in the bottom left of your array. To check with the right side, just check to see if there are any rows where row + bottom-left >= right bound (or however) with pieces in them.

Hope this helps

Tybal
ehlertjd@uwec.edu

##### Share on other sites
Sorry for the crappy diagram...

I rotate the shape within the array, meaning I move it, so need to decide where it is.. I presume you hold each of the rotated shapes in individual arrays, and when they rotate move to the next one?

Anyway, I think I have a solution in that I will move the shape through itself if they move it, if they rotate it will rotate from its last known good position (if this makes sense)

Add more detail later, if required.. Thanks..

##### Share on other sites
Tybal    122
Actually if you write a function to remove dead space from the bottom and from the left, you can 'shift' your piece down and to the left.

Some valueable functions to have for this:

bool isColumnEmpty(int index);
bool isRowEmpty(int index);
void shiftLeft();
void shiftDown();

they're pretty easy to write, so then you just have to say:
while( isRowEmpty(3) ){     shiftDown();}while( isColumnEmpty(0) ){     shiftLeft();}

do this every time you rotate, and it'll always be in the bottome left.

void Block::shiftLeft(){	for(int y = 0; y < 4; y++)	{		for(int x = 0; x < 3; x++)		{			squares[y][x] = squares[y][x+1];		}		squares[y][3] = 0;	}}void Block::isColumnEmpty(int index){	return(squares[0][index] == 0 && squares[1][index] == 0 && squares[2][index] == 0 && squares[3][index] == 0);}

or something like that.

[edited by - Tybal on October 22, 2002 8:57:54 AM]