#include "Tetrad_J.h"
#include "BlocksMatrix.h"
CTetrad_J::CTetrad_J(CBlocksMatrix* pParent) : CTetrad(pParent,bcBlue)
{
}
CTetrad_J::~CTetrad_J()
{
}
bool CTetrad_J::Rotate()
{
bool bSuccess = false;
switch (m_Orientation)
{
case Rotation0:
if (m_pParentMatrix->IsCellFree(m_iXPos-1,m_iYPos+1) &&
m_pParentMatrix->IsCellFree(m_iXPos ,m_iYPos+1) &&
m_pParentMatrix->IsCellFree(m_iXPos ,m_iYPos-1))
{
m_Orientation = Rotation90;
bSuccess = true;
}
break;
case Rotation90:
if (m_pParentMatrix->IsCellFree(m_iXPos-1,m_iYPos-1) &&
m_pParentMatrix->IsCellFree(m_iXPos-1,m_iYPos ) &&
m_pParentMatrix->IsCellFree(m_iXPos+1,m_iYPos))
{
m_Orientation = Rotation180;
bSuccess = true;
}
break;
case Rotation180:
if (m_pParentMatrix->IsCellFree(m_iXPos ,m_iYPos+1) &&
m_pParentMatrix->IsCellFree(m_iXPos ,m_iYPos-1) &&
m_pParentMatrix->IsCellFree(m_iXPos+1,m_iYPos-1))
{
m_Orientation = Rotation270;
bSuccess = true;
}
break;
case Rotation270:
if (m_pParentMatrix->IsCellFree(m_iXPos-1,m_iYPos ) &&
m_pParentMatrix->IsCellFree(m_iXPos+1,m_iYPos ) &&
m_pParentMatrix->IsCellFree(m_iXPos+1,m_iYPos+1))
{
m_Orientation = Rotation0;
bSuccess = true;
}
break;
}
return bSuccess;
}
bool CTetrad_J::MoveLeft()
{
bool bSuccess = false;
switch (m_Orientation)
{
case Rotation0:
if (m_pParentMatrix->IsCellFree(m_iXPos-2,m_iYPos) &&
m_pParentMatrix->IsCellFree(m_iXPos ,m_iYPos+1))
{
m_iXPos--;
bSuccess = true;
}
break;
case Rotation90:
if (m_pParentMatrix->IsCellFree(m_iXPos-2,m_iYPos+1) &&
m_pParentMatrix->IsCellFree(m_iXPos-1,m_iYPos) &&
m_pParentMatrix->IsCellFree(m_iXPos-1,m_iYPos-1))
{
m_iXPos--;
bSuccess = true;
}
break;
case Rotation180:
if (m_pParentMatrix->IsCellFree(m_iXPos-2,m_iYPos-1) &&
m_pParentMatrix->IsCellFree(m_iXPos-2,m_iYPos ))
{
m_iXPos--;
bSuccess = true;
}
break;
case Rotation270:
if (m_pParentMatrix->IsCellFree(m_iXPos-1,m_iYPos+1) &&
m_pParentMatrix->IsCellFree(m_iXPos-1,m_iYPos) &&
m_pParentMatrix->IsCellFree(m_iXPos-1,m_iYPos-1))
{
m_iXPos--;
bSuccess = true;
}
break;
}
return bSuccess;
}
bool CTetrad_J::MoveRight()
{
bool bSuccess = false;
switch (m_Orientation)
{
case Rotation0:
if (m_pParentMatrix->IsCellFree(m_iXPos+2,m_iYPos) &&
m_pParentMatrix->IsCellFree(m_iXPos+2,m_iYPos+1))
{
m_iXPos++;
bSuccess = true;
}
break;
case Rotation90:
if (m_pParentMatrix->IsCellFree(m_iXPos+1,m_iYPos+1) &&
m_pParentMatrix->IsCellFree(m_iXPos+1,m_iYPos ) &&
m_pParentMatrix->IsCellFree(m_iXPos+1,m_iYPos-1))
{
m_iXPos++;
bSuccess = true;
}
break;
case Rotation180:
if (m_pParentMatrix->IsCellFree(m_iXPos+2,m_iYPos) &&
m_pParentMatrix->IsCellFree(m_iXPos ,m_iYPos-1))
{
m_iXPos++;
bSuccess = true;
}
break;
case Rotation270:
if (m_pParentMatrix->IsCellFree(m_iXPos+2,m_iYPos-1) &&
m_pParentMatrix->IsCellFree(m_iXPos+1,m_iYPos ) &&
m_pParentMatrix->IsCellFree(m_iXPos+1,m_iYPos+1))
{
m_iXPos++;
bSuccess = true;
}
break;
}
return bSuccess;
}
bool CTetrad_J::MoveDown()
{
bool bSuccess = false;
switch (m_Orientation)
{
case Rotation0:
if (m_pParentMatrix->IsCellFree(m_iXPos-1,m_iYPos+1) &&
m_pParentMatrix->IsCellFree(m_iXPos ,m_iYPos+1) &&
m_pParentMatrix->IsCellFree(m_iXPos+1,m_iYPos+2) )
{
m_iYPos++;
bSuccess = true;
}
break;
case Rotation90:
if (m_pParentMatrix->IsCellFree(m_iXPos-1,m_iYPos+2) &&
m_pParentMatrix->IsCellFree(m_iXPos ,m_iYPos+2))
{
m_iYPos++;
bSuccess = true;
}
break;
case Rotation180:
if (m_pParentMatrix->IsCellFree(m_iXPos-1,m_iYPos+1) &&
m_pParentMatrix->IsCellFree(m_iXPos ,m_iYPos+1) &&
m_pParentMatrix->IsCellFree(m_iXPos+1,m_iYPos+1) )
{
m_iYPos++;
bSuccess = true;
}
break;
case Rotation270:
if (m_pParentMatrix->IsCellFree(m_iXPos ,m_iYPos+2) &&
m_pParentMatrix->IsCellFree(m_iXPos+1,m_iYPos ))
{
m_iYPos++;
bSuccess = true;
}
break;
}
return bSuccess;
}
void CTetrad_J::Draw()
{
int screenX=0, screenY=0;
switch (m_Orientation)
{
case Rotation0:
m_pParentMatrix->GetScreenPosFromCell(m_iXPos-1,m_iYPos,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
m_pParentMatrix->GetScreenPosFromCell(m_iXPos ,m_iYPos,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
m_pParentMatrix->GetScreenPosFromCell(m_iXPos+1,m_iYPos ,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
m_pParentMatrix->GetScreenPosFromCell(m_iXPos+1,m_iYPos+1,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
break;
case Rotation90:
m_pParentMatrix->GetScreenPosFromCell(m_iXPos-1,m_iYPos+1,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
m_pParentMatrix->GetScreenPosFromCell(m_iXPos ,m_iYPos-1,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
m_pParentMatrix->GetScreenPosFromCell(m_iXPos ,m_iYPos ,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
m_pParentMatrix->GetScreenPosFromCell(m_iXPos ,m_iYPos+1,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
break;
case Rotation180:
m_pParentMatrix->GetScreenPosFromCell(m_iXPos-1,m_iYPos-1,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
m_pParentMatrix->GetScreenPosFromCell(m_iXPos-1,m_iYPos ,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
m_pParentMatrix->GetScreenPosFromCell(m_iXPos ,m_iYPos ,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
m_pParentMatrix->GetScreenPosFromCell(m_iXPos+1,m_iYPos ,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
break;
case Rotation270:
m_pParentMatrix->GetScreenPosFromCell(m_iXPos+1,m_iYPos-1,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
m_pParentMatrix->GetScreenPosFromCell(m_iXPos ,m_iYPos-1,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
m_pParentMatrix->GetScreenPosFromCell(m_iXPos ,m_iYPos ,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
m_pParentMatrix->GetScreenPosFromCell(m_iXPos ,m_iYPos+1,screenX,screenY);
m_pBlockImg->BlitImage(screenX,screenY);
break;
}
}
void CTetrad_J::DrawOnScreen(const TRectanglei& rect)
{
int XPos = (rect.GetWidth() - 3*BLOCK_WIDTH)/2 + rect.m_Left;
int YPos = (rect.GetHeight() - 2*BLOCK_HEIGHT)/2 + rect.m_Top;
m_pBlockImg->BlitImage(XPos,YPos);
m_pBlockImg->BlitImage(XPos+BLOCK_WIDTH,YPos);
m_pBlockImg->BlitImage(XPos+2*BLOCK_WIDTH,YPos);
m_pBlockImg->BlitImage(XPos+2*BLOCK_WIDTH,YPos+BLOCK_HEIGHT);
}
void CTetrad_J::FillMatrix()
{
switch (m_Orientation)
{
case Rotation0:
m_pParentMatrix->FillCell(m_iXPos-1,m_iYPos ,m_BlockColor);
m_pParentMatrix->FillCell(m_iXPos ,m_iYPos ,m_BlockColor);
m_pParentMatrix->FillCell(m_iXPos+1,m_iYPos ,m_BlockColor);
m_pParentMatrix->FillCell(m_iXPos+1,m_iYPos+1,m_BlockColor);
break;
case Rotation90:
m_pParentMatrix->FillCell(m_iXPos-1,m_iYPos+1,m_BlockColor);
m_pParentMatrix->FillCell(m_iXPos ,m_iYPos-1,m_BlockColor);
m_pParentMatrix->FillCell(m_iXPos ,m_iYPos ,m_BlockColor);
m_pParentMatrix->FillCell(m_iXPos ,m_iYPos+1,m_BlockColor);
break;
case Rotation180:
m_pParentMatrix->FillCell(m_iXPos-1,m_iYPos-1,m_BlockColor);
m_pParentMatrix->FillCell(m_iXPos-1,m_iYPos ,m_BlockColor);
m_pParentMatrix->FillCell(m_iXPos ,m_iYPos ,m_BlockColor);
m_pParentMatrix->FillCell(m_iXPos+1,m_iYPos ,m_BlockColor);
break;
case Rotation270:
m_pParentMatrix->FillCell(m_iXPos+1,m_iYPos-1,m_BlockColor);
m_pParentMatrix->FillCell(m_iXPos ,m_iYPos-1,m_BlockColor);
m_pParentMatrix->FillCell(m_iXPos ,m_iYPos ,m_BlockColor);
m_pPare
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Tutorial3_src.zip (79个子文件)
bin
HighScoreItems.png 21KB
Block.png 4KB
DevIL.dll 856KB
PlayBckgnd.png 461KB
ProgressBar.png 9KB
ScoresTitle.png 33KB
MenuItems.png 25KB
01 Digitall.ttf 48KB
MainBackground.png 1.2MB
MenuTitle.png 23KB
TetroGL.vcproj 7KB
dependencies
DevIL
include
IL
config.h 3KB
ilut.h 12KB
il.h 19KB
ilu_region.h 593B
devil_internal_exports.h 7KB
ilu.h 6KB
lib
ILUT.exp 6KB
DevIL.lib 27KB
ILU.exp 7KB
ILUT.dll 32KB
DevIL.dll 856KB
DevIL.exp 17KB
ILUT.lib 10KB
ILU.lib 11KB
ILU.dll 76KB
src
Main.cpp 460B
TextureManager.h 1KB
Texture.cpp 3KB
Constants.h 436B
MenuState.h 1KB
Image.h 2KB
TextControl.h 1022B
GameState.cpp 276B
ImageList.h 1KB
Tetrad_L.cpp 8KB
Tetrad_L.h 373B
BlocksMatrix.h 3KB
ComboControl.cpp 2KB
Tetrad.h 3KB
TextureManager.cpp 2KB
PlayState.h 1KB
Tetrad_J.cpp 8KB
ComboControl.h 2KB
MainWindow.cpp 7KB
Tetrad_I.h 373B
Texture.h 2KB
SmartPtr.h 3KB
Exception.h 376B
GameState.h 939B
BlocksMatrix.cpp 7KB
Tetrad_S.cpp 5KB
StateManager.cpp 681B
MainWindow.h 1KB
Application.cpp 3KB
Tetrad_S.h 375B
GameFont.cpp 3KB
MenuState.cpp 4KB
PlayState.cpp 5KB
Tetrad_Z.cpp 5KB
TetradFactory.h 311B
Tetrad_J.h 373B
ImageList.cpp 1KB
TextControl.cpp 1KB
Tetrad_Z.h 375B
Tetrad_O.cpp 2KB
StateManager.h 904B
Tetrad_I.cpp 5KB
Tetrad_O.h 375B
GameFont.h 1KB
TetradFactory.cpp 926B
HighScoreState.h 2KB
Application.h 747B
Tetrad_T.h 375B
HighScoreState.cpp 5KB
Rectangle.h 2KB
Tetrad_T.cpp 8KB
Image.cpp 3KB
TetroGL.sln 878B
共 79 条
- 1
资源评论
wsedwsed
- 粉丝: 9
- 资源: 111
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功