📄 block.c
字号:
/**********************************************************
* Copyright (C),2004-2007, Fuzhou Rockchip Co.,Ltd.
* Module name : block game
* Author: Zushang Chen
* Description: 俄罗斯方块游戏
* Calls:
* Input: 无
* Return: 无
* Remark:
*
* History: 从26平台上移植到27平台,26平台上是方镇福所写
* 增加行闪烁功能
* 将新方块队列从一个增加到四个
* 增加新方块队列的刷新功能
* 更新方块的图像
*
*
$Log: Block.c,v $
Revision 1.3 2008/06/19 04:42:26 Administrator
代码整理!
Revision 1.2 2008/06/06 03:15:21 XXX
更改游戏在RGB屏情况的问题
Revision 1.3 2008/03/14 06:39:03 Chenzushang
修正RGB屏显示不正常问题
Revision 1.2 2008/03/07 09:28:30 Hanjiang
no message
Revision 1.3 2008/01/14 08:53:28 Chenzushang
去除编译过程中出现的警告
Revision 1.2 2008/01/10 12:57:50 Chenzushang
修改窗口ID、延时函数和任务栏隐藏函数
Revision 1.1 2008/01/09 08:57:56 Chenzushang
增加俄罗斯方块游戏
***********************************************************/
#include "Block.h"
#ifdef __arm
#define BLOCKRANDFUNC() RockGetRamdom()
#else
#define BLOCKRANDFUNC() rand()
#endif
void RKDrawBmpIdEx(INT16S x, INT16S y, INT16U id , UHRECT *srcRect, DispMode xTransp);
unsigned int BlockScopeBuf[BLOCKGAME_SCOPE_ROW][BLOCKGAME_SCOPE_COL];
unsigned int BlockInsertFlag[BLOCKGAME_SCOPE_ROW+4];
unsigned int CurBlock;
unsigned int BlockAspect;
unsigned int BlockNextMat[4];
unsigned int MoveBlock_X;
unsigned int MoveBlock_Y;
unsigned int BlockFlashing;
unsigned char BlockGameLevel;
unsigned char BlockGameLevelBase;
unsigned long BlockGameScore;
unsigned char BlockGameState;
HTIMER m_blockTimerID;
WINDOW *pblockwin = NULL;
/*
********************************************************************************
定义7种基本方块形状,4个方向的值
********************************************************************************
*/
unsigned int BlockDat[7][4][4] =
{
{ //BLOCK _|
{0x04, 0x07, 0x00, 0x00},
{0x06, 0x04, 0x04, 0x00},
{0x0E, 0x02, 0x00, 0x00},
{0x02, 0x02, 0x06, 0x00}
},
{ //BLOCK |_
{0x02, 0x0E, 0x00, 0x00},
{0x04, 0x04, 0x06, 0x00},
{0x07, 0x04, 0x00, 0x00},
{0x06, 0x02, 0x02, 0x00}
},
{ //BLOCK 田
{0x06, 0x06, 0x00, 0x00},
{0x06, 0x06, 0x00, 0x00},
{0x06, 0x06, 0x00, 0x00},
{0x06, 0x06, 0x00, 0x00}
},
{ //BLOCK |_
// |
{0x06, 0x0C, 0x00, 0x00},
{0x04, 0x06, 0x02, 0x00},
{0x06, 0x0C, 0x00, 0x00},
{0x04, 0x06, 0x02, 0x00}
},
{ //BLOCK _|
// |
{0x06, 0x03, 0x00, 0x00},
{0x02, 0x06, 0x04, 0x00},
{0x06, 0x03, 0x00, 0x00},
{0x02, 0x06, 0x04, 0x00}
},
{ //BLOCK T
{0x02, 0x07, 0x00, 0x00},
{0x04, 0x06, 0x04, 0x00},
{0x07, 0x02, 0x00, 0x00},
{0x02, 0x06, 0x02, 0x00}
},
{
{0x00, 0x0F, 0x00, 0x00},
{0x04, 0x04, 0x04, 0x04},
{0x00, 0x0F, 0x00, 0x00},
{0x04, 0x04, 0x04, 0x04}
}
};
extern void RKWindowDestroyEx(WINDOW *win , WMPARAM wParam, WLPARAM lParam);
BEGIN_CHILDMESSAGE_MAP(BlockProcMap , NULL)
ON_MESSAGE(WM_PAINT , BlockOnPaint)
ON_MESSAGE(WM_TIMER, BlockOnTimer)
ON_MESSAGE(WM_KEY, BlockOnKey)
ON_MESSAGE(WM_DESTROY, BlockOnDestroy)
END_MESSAGE_MAP()
/******************************************************
Name: BlockOnPaint
Desc: WM_PAINT消息的响应函数,负责屏幕的绘制
Param: WINDOW* win--父窗口
WMPARAM wParam--
WLPARAM lParam--
Return: TRUE--成功,FALSE--失败
Global: 有
Note:
Author:czs
Log:
******************************************************/
UINT32 BlockOnPaint(WINDOW* win , WMPARAM wParam, WLPARAM lParam)
{
BlockDrawBackground();
BlockDrawGameArea();
BlockDispNext();
BlockShowScore();
return TRUE;
}
/******************************************************
Name: BlockOnTimer
Desc: 定时器回调函数
Param: WINDOW* win--父窗口
WMPARAM wParam--窗口参数
WLPARAM lParam--窗口参数
Return: TRUE--成功,FALSE--失败
Global: 有
Note:
Author:czs
Log:
******************************************************/
UINT32 BlockOnTimer(WINDOW* win , WMPARAM wParam, WLPARAM lParam)
{
BlockMove(KE_DN_RELEASE);
// DoLcdFlush( gGuiDspLcdLogic );
//RockOSSendMsg(MBDISP,MS_ISRDI_FlushInd,NULL);
WindowInvalidateWindow(win);
return TRUE;
}
/******************************************************
Name: BlockOnKey
Desc: 按键处理函数
Param: WINDOW* win--父窗口
WMPARAM wParam--窗口参数
WLPARAM lParam--窗口参数
Return: TRUE--成功,FALSE--失败
Global: 有
Note:
Author:czs
Log:
******************************************************/
UINT32 BlockOnKey(WINDOW* win , WMPARAM wParam, WLPARAM lParam)
{
UINT16 keyPress = (UINT16)((wParam) >> 16);
UINT16 KEY_EV = (UINT16)(wParam);
switch (KEY_EV)
{
case KE_DN_PRESS:
case KE_DN_LONGP:
case KE_DN_RELEASE:
case KE_DN_LONG_RELEASE:
case KE_PREV_PRESS://left
case KE_PREV_LONGP:
case KE_PREV_RELEASE:
case KE_PREV_LONG_RELEASE:
case KE_UP_PRESS:
case KE_UP_LONGP:
case KE_UP_RELEASE:
case KE_UP_LONG_RELEASE:
case KE_NEXT_PRESS: //right
case KE_NEXT_LONGP:
case KE_NEXT_RELEASE:
case KE_NEXT_LONG_RELEASE:
case KE_PLAY_PRESS://
case KE_PLAY_RELEASE:
case KE_SHIFT_PRESS://
case KE_SHIFT_RELEASE:
case KE_MENU_PRESS://
case KE_MENU_RELEASE:
if (BlockGameState == BLOCKGAME_STOP)
BlockGameSetting(wParam);
else
BlockGameProcess(wParam);
//RockOSSendMsg(MBDISP,MS_ISRDI_FlushInd,NULL);
WindowInvalidateWindow(win);
break;
case KE_RETURN_PRESS:
break;
case KE_RETURN_RELEASE:
if (m_blockTimerID != NULL)
{
WinStopTimer(m_blockTimerID);
m_blockTimerID = NULL;
}
RKWindowDestroyEx(win, 0, NULL);
break;
}
return TRUE;
}
/******************************************************
Name: BlockDispOneNext
Desc: 显示新方块队列中的一个方块
Param: int xx --坐标x
int yy --坐标y
int index --新方块队列中方块的下标
Return: 无
Global: 有
Note:
Author:czs
Log:
******************************************************/
void BlockDispOneNext(int xx, int yy, int index)
{
unsigned int i, j;
unsigned int *pBlock;
unsigned int NBlocki, NBlockAspecti;
unsigned int DMask = 0x08;
UHRECT rect, rect2;
NBlocki = BlockNextMat[index] & 0xff;
NBlockAspecti = (BlockNextMat[index] >> 8) & 0xff;
rect.h = rect.w = 12;
rect.x = 0;
rect.y = NBlocki * 12;
rect2.h = rect2.w = 12;
rect2.x = 0;
rect2.y = 7 * 12;
pBlock = &BlockDat[NBlocki][NBlockAspecti][0];
for (i = 0; i < 4; i++)
{
DMask = 0x08;
for (j = 0; j < 4; j++)
{
if (*pBlock & DMask)
{
RKDrawBmpIdEx((INT16S)(xx + j*BASE_BLOCK_YSIZE), (INT16S)(yy + i*BASE_BLOCK_XSIZE),
BID_Block_Data, &rect, DSPM_Normal);
}
else
{
RKDrawBmpIdEx((INT16S)(xx + j*BASE_BLOCK_YSIZE), (INT16S)(yy + i*BASE_BLOCK_XSIZE),
BID_Block_Data, &rect2, DSPM_Normal);
}
DMask >>= 1;
}
pBlock++;
}
}
/******************************************************
Name: BlockDispNext
Desc: 显示新方块队列中的所有方块
Param: 无
Return: 无
Global: 有
Note:
Author:czs
Log:
******************************************************/
void BlockDispNext(void)
{
BlockDispOneNext(BLOCKGAME_DISP_NEXT_BLOCK_X, BLOCKGAME_DISP_NEXT_BLOCK_Y, 0);
BlockDispOneNext(BLOCKGAME_DISP_NEXT2_BLOCK_X, BLOCKGAME_DISP_NEXT2_BLOCK_Y, 1);
BlockDispOneNext(BLOCKGAME_DISP_NEXT3_BLOCK_X, BLOCKGAME_DISP_NEXT3_BLOCK_Y, 2);
BlockDispOneNext(BLOCKGAME_DISP_NEXT4_BLOCK_X, BLOCKGAME_DISP_NEXT4_BLOCK_Y, 3);
}
/******************************************************
Name: BlockDrawGameArea
Desc: 重画游戏区域图像
Param: 无
Return: 无
Global: 有
Note:
Author:czs
Log:
******************************************************/
void BlockDrawGameArea(void)
{
unsigned int i, j;
UHRECT rect;
rect.h = rect.w = 12;
rect.x = 0;
for (j = 0; j < BLOCKGAME_SCOPE_COL; j++)
for (i = 0; i < BLOCKGAME_SCOPE_ROW; i++)
{
if (BlockScopeBuf[i][j] != BLOCK_IMAGE_NULL)
{
rect.y = BlockScopeBuf[i][j] * 12;
RKDrawBmpIdEx((INT16S)(j*BASE_BLOCK_XSIZE + BLOCKGAME_DISP_OFFSET_X), (INT16S)(i*BASE_BLOCK_YSIZE + BLOCKGAME_DISP_OFFSET_Y),
BID_Block_Data, &rect, DSPM_Normal);
}
else
{
rect.y = 12 * 7;
RKDrawBmpIdEx((INT16S)(j*BASE_BLOCK_XSIZE + BLOCKGAME_DISP_OFFSET_X), (INT16S)(i*BASE_BLOCK_YSIZE + BLOCKGAME_DISP_OFFSET_Y),
BID_Block_Data, &rect, DSPM_Normal);
}
}
//if(BlockFlashCnt)
// BlockFlashLine(BlockDelLine,BlockDelLineNum);
}
/******************************************************
Name: BlockFlashLine
Desc: 游戏过程中当一行或几行方块满之后,调用此函数以闪烁
Param: unsigned int *yy -- 行数组的地址
unsigned int len -- 行数组的长度
Return: 无
Global: 有
Note:
Author:czs
Log:
******************************************************/
void DelayMs_nops(UINT32 msec);
void BlockFlashLine(unsigned int *yy, unsigned int len)
{
UINT8 cnt = 0, j, i;
UHRECT rect;
rect.h = rect.w = 12;
rect.x = 0;
while (cnt < 8)
{
if ((cnt&0x01))
{
for (i = 0;i < len;i++)
for (j = 0; j < BLOCKGAME_SCOPE_COL; j++)
{
rect.y = BlockScopeBuf[yy[i]][j] * 12;
RKDrawBmpIdEx((INT16S)(j*BASE_BLOCK_XSIZE + BLOCKGAME_DISP_OFFSET_X), (INT16S)(yy[i]*BASE_BLOCK_YSIZE + BLOCKGAME_DISP_OFFSET_Y),
BID_Block_Data, &rect, DSPM_Normal);
}
}
else
{
for (i = 0;i < len;i++)
for (j = 0; j < BLOCKGAME_SCOPE_COL; j++)
{
rect.y = 7 * 12;
RKDrawBmpIdEx((INT16S)(j*BASE_BLOCK_XSIZE + BLOCKGAME_DISP_OFFSET_X), (INT16S)(yy[i]*BASE_BLOCK_YSIZE + BLOCKGAME_DISP_OFFSET_Y),
BID_Block_Data, &rect, DSPM_Normal);
}
}
//#ifdef MCU_PANEL
//RockOSSendMsg(MBDISP,MS_ISRDI_FlushInd,NULL);
//#else
WindowInvalidateWindow(pblockwin);
//#endif
//RkosDelayMs(1000);
DelayMs_nops(60);
cnt++;
}
}
/******************************************************
Name: BlockInitNextMat
Desc: 初始化新方块队列
Param: 无
Return: 无
Global: 有
Note:
Author:czs
Log:
******************************************************/
void BlockInitNextMat(void)
{
int i, temp;
for (i = 0;i < 4;i++)
{
temp = (BLOCKRANDFUNC() % 7) & 0xff;
temp |= (((BLOCKRANDFUNC() % 4) << 8) & 0xff00);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -