TGrid.cpp
上传用户:snevogroup
上传日期:2008-06-06
资源大小:432k
文件大小:1k
- #include "TGrid.h"
- // Construct
- TGrid::TGrid()
- {
- Clear();
- }
- TGrid TGrid::NewGrid()
- {
- return TGrid();
- }
- /////////////////////////////////////////////////////////////////////////////
- // Method
- // Clear()
- void TGrid::Clear()
- {
- for (int i = 0; i < KGridY; i++)
- {
- iMask[i] = 0x003f;
- for (int j=0; j<KGridX; j++)
- iContent[i][j] = 0;
- }
- }
- // DoesCollide()
- bool TGrid::DoesCollide(const TBlock& aBlock, const TPoint& aPoint) const
- {
- TInt i;
- for (i = aPoint.iY; i < aPoint.iY + 4; i++)
- {
- if (i < 0)
- {
- if ( ( static_cast<TUint32>(aBlock.RowMask(i - aPoint.iY)) << (12-aPoint.iX) ) & 0xf003f )
- return true;
- }
- else if (i >= KGridY)
- {
- if (aBlock.RowMask(i-aPoint.iY))
- return true;
- }
- else
- {
- if (iMask[i] & (aBlock.RowMask(i-aPoint.iY)<<(12-aPoint.iX)))
- return true;
- if (aPoint.iX<0 && ((aBlock.RowMask(i-aPoint.iY)>>(4+aPoint.iX))))
- return true;
- }
- }
- return false;
- }
- // PutBlock()
- void TGrid::PutBlock(const TBlock& aBlock, const TPoint& aPoint)
- {
- TInt i, j;
- TUint8 BlockType = aBlock.Type(); // start from 1
- for (i = aPoint.iY; i < aPoint.iY+4; i++)
- {
- if (i<0)
- continue;
- if (i>=KGridY)
- break;
- TUint16 mask=aBlock.RowMask(i - aPoint.iY);
- iMask[i] |= mask << (12 - aPoint.iX); // -3 ~ ..
- for (j = aPoint.iX; j < aPoint.iX+4; j++)
- if (mask & (1 << (3 - j + aPoint.iX)))
- iContent[i][j] = BlockType;
- }
- }