📄 game.c
字号:
-1, // -1 = Use full string length
MAP_WIDTH*pMe->block_width+1+pMe->block_width+pMe->block_width, // x-cordinate
MAP_HEIGHT*pMe->block_height-32+pMe->block_height, // y-cordinate
NULL, // No clipping
0);//IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
IDISPLAY_DrawText(pMe->a.m_pIDisplay, // Display instance
AEE_FONT_BOLD, // Use BOLD font
game_title, // Text - Normally comes from resource
-1, // -1 = Use full string length
0, // x-cordinate
MAP_HEIGHT*pMe->block_height+pMe->block_height+pMe->block_height, // y-cordinate
NULL, // No clipping
IDF_ALIGN_CENTER );
for (i=0; i<pMe->map_line; i++)
for (j=0; j<pMe->map_col; j++)
pMe->map[i][j]=0;
ClearBlock(pMe);
pMe->a0=0;
//map_line=24;
//map_col=12;
pMe->block_x=0;
pMe->block_y=20;
pMe->gameover=0;
pMe->x_size=0;
pMe->y_size=0;
pMe->score=0;
pMe->dels=0;
pMe->pause=FALSE;
pMe->next_block=pMe->x_size+pMe->y_size+pMe->block_x+pMe->block_y+dwTime;
pMe->next_block=pMe->next_block%pMe->difficult_level+pMe->a0;
pMe->next_block=pMe->next_block%pMe->difficult_level+1;
}
//================================================================
//Function: restorememory
//Description: get over the memory
//Side effect: none
//================================================================
void restorememory(CGametype * pMe)
{
int i,j;
AEERect rect;
int temp = pMe->current_block;
AECHAR szText[] ={'N','e','x','t','\0','S','c','o','r','e','\0'},game_title[30]={0};
AECHAR game_score[8]={0};
ISHELL_LoadResString(pMe->a.m_pIShell,GAME_RES_FILE, IDS_GAME_TITLE, game_title, sizeof(game_title));
rect.x=0;
rect.y=0;
rect.dx=120; //screen width
rect.dy=pMe->block_height;
IDISPLAY_DrawRect(pMe->a.m_pIDisplay,
&rect,
pMe->frame_color,// RGBVAL
pMe->frame_color,// RGBVAL
IDF_RECT_FRAME | IDF_RECT_FILL);
rect.x=0;
rect.y=MAP_HEIGHT*pMe->block_height+pMe->block_height;
rect.dx=pMe->m_Rect.dx;//screen width
rect.dy=pMe->block_height;
IDISPLAY_DrawRect(pMe->a.m_pIDisplay,
&rect,
pMe->frame_color,// RGBVAL
pMe->frame_color,// RGBVAL
IDF_RECT_FRAME | IDF_RECT_FILL);
rect.x=MAP_WIDTH*pMe->block_width+pMe->block_width;
rect.y=pMe->block_height;
rect.dx=pMe->block_width;
rect.dy=MAP_HEIGHT*pMe->block_height;
IDISPLAY_DrawRect(pMe->a.m_pIDisplay,
&rect,
pMe->frame_color,
pMe->frame_color,
IDF_RECT_FRAME | IDF_RECT_FILL);
rect.x=0;
rect.y=pMe->block_height;
rect.dx=pMe->block_width;
rect.dy=MAP_HEIGHT*pMe->block_height;
IDISPLAY_DrawRect(pMe->a.m_pIDisplay,
&rect,
pMe->frame_color,// RGBVAL
pMe->frame_color,// RGBVAL
IDF_RECT_FRAME | IDF_RECT_FILL);
rect.x=pMe->m_Rect.dx-pMe->block_width;
rect.y=pMe->block_height;
rect.dx=pMe->block_width;
rect.dy=MAP_HEIGHT*pMe->block_height;
IDISPLAY_DrawRect(pMe->a.m_pIDisplay,
&rect,
pMe->frame_color,// RGBVAL
pMe->frame_color,// RGBVAL
IDF_RECT_FRAME | IDF_RECT_FILL);
IDISPLAY_DrawText(pMe->a.m_pIDisplay, // Display instance
AEE_FONT_BOLD, // Use BOLD font
szText, // Text - Normally comes from resource
-1, // -1 = Use full string length
MAP_WIDTH*pMe->block_width+1+pMe->block_width+pMe->block_width, // x-cordinate
pMe->block_height+8, // y-cordinate
NULL, // No clipping
0);//IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
IDISPLAY_DrawText(pMe->a.m_pIDisplay, // Display instance
AEE_FONT_BOLD, // Use BOLD font
szText+5, // Text - Normally comes from resource
-1, // -1 = Use full string length
MAP_WIDTH*pMe->block_width+1+pMe->block_width+pMe->block_width, // x-cordinate
MAP_HEIGHT*pMe->block_height-32+pMe->block_height, // y-cordinate
NULL, // No clipping
0);//IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
IDISPLAY_DrawText(pMe->a.m_pIDisplay, // Display instance
AEE_FONT_BOLD, // Use BOLD font
game_title, // Text - Normally comes from resource
-1, // -1 = Use full string length
0, // x-cordinate
MAP_HEIGHT*pMe->block_height+pMe->block_height+pMe->block_height, // y-cordinate
NULL, // No clipping
IDF_ALIGN_CENTER );
up_Itoa(game_score,(int)pMe->score);
IDISPLAY_DrawText(pMe->a.m_pIDisplay, // Display instance
AEE_FONT_BOLD, // Use BOLD font
game_score, // Text - Normally comes from resource
-1, // -1 = Use full string length
MAP_WIDTH*pMe->block_width+1+pMe->block_width, // x-cordinate
MAP_HEIGHT*pMe->block_height-16+pMe->block_height, // y-cordinate
NULL, // No clipping
0);//IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
GenerateBlock(pMe,pMe->next_block);
for (i=0; i<4; i++) {
for (j=0; j<4; j++) {
if (pMe->block[i][j] !=0)
write_video(pMe,(pMe->map_line+2+i)*pMe->block_width+pMe->block_width,(j)*pMe->block_height+pMe->block_height+24,pMe->color_table[pMe->block[i][j]],black);
else
{write_video(pMe,(pMe->map_line+2+i)*pMe->block_width+pMe->block_width,(j)*pMe->block_height+pMe->block_height+24,RGB_NONE,noblack);}
}
}
GenerateBlock(pMe,temp);
}
//=================================================================
//Function: generatenew
//Description: generate a new block
//Side effect: none
//=================================================================
void GenerateNew(CGametype * pMe) /*generate a new block*/
{int i,j;
int temp = pMe->next_block;
uint32 dwTime = GET_UPTIMEMS();
pMe->next_block=pMe->x_size+pMe->y_size+pMe->block_x+dwTime;
pMe->next_block=pMe->next_block%pMe->difficult_level+pMe->a0;
pMe->next_block=pMe->next_block%pMe->difficult_level+1;
pMe->a0=0;
GenerateBlock(pMe,pMe->next_block);
// for(i=0;i<4;i++)
// for(j=0;j<4;j++)
// write_video(pMe,(map_line+i)*pMe->block_width,(map_col+j)*pMe->block_width,noblack);
for (i=0; i<4; i++) {
for (j=0; j<4; j++) {
if (pMe->block[i][j] !=0)
write_video(pMe,(pMe->map_line+2+i)*pMe->block_width+pMe->block_width,(j)*pMe->block_height+pMe->block_height+24,pMe->color_table[pMe->block[i][j]],black);
else
{write_video(pMe,(pMe->map_line+2+i)*pMe->block_width+pMe->block_width,(j)*pMe->block_height+pMe->block_height+24,RGB_NONE,noblack);}
}
}
GenerateBlock(pMe,temp);
pMe->block_x = 4;
pMe->block_y = 0;
if (!CanPut(pMe)) {
pMe->gameover=1;
}
}
//=====================================================================
//Function: putblock
//Description: put a block into map
//Side effect: none
//=====================================================================
void PutBlock(CGametype * pMe) /* put block data into map*/
{int i,j;
for (i=0; i<4; i++) {
for (j=0; j<4; j++) {
if (pMe->block[i][j] !=0)
pMe->map[pMe->block_x+i][pMe->block_y+j] = pMe->block[i][j];
}
}
DeleteRow(pMe);
}
//======================================================================
//Function: rotateblock
//Description: rotate the current block at the clockwise
//Side effect: none
//======================================================================
void RotateBlock(CGametype * pMe) /*rotate the block*/
{
int old_block = pMe->current_block;
pMe->current_block += 10;
if (pMe->current_block > 40) pMe->current_block -= 40;
GenerateBlock(pMe,pMe->current_block);
if (!CanPut(pMe)) {
pMe->current_block = old_block;
GenerateBlock(pMe,pMe->current_block);
}
}
//======================================================================
//Function canput
//Description: determine whether block is out of the map and go down the bottom of map
//Side effect: none
//======================================================================
int CanPut(CGametype * pMe) /*check if block have been out of the range*/
{int i,j;
for (i=0; i<4; i++) {
for (j=0; j<4; j++) {
if (pMe->block[i][j] !=0) {
if (pMe->block_x + i > pMe->map_line-1) return 0;
if (pMe->block_x + i < 0) return 0;
if (pMe->block_y + j > pMe->map_col-1) return 0;
if (pMe->block_y + j < 0) return 0;
if (pMe->map[pMe->block_x+i][pMe->block_y+j] != 0) return 0;
}
}
}
return 1;
}
//===============================================================
//Function: drawmap
//Description: refresh the whole map
//Side effect: play with the display
//===============================================================
void DrawMap(CGametype * pMe) /*draw map*/
{int i,j;
for (i=0; i<pMe->map_line; i++)
{
for (j=0; j<pMe->map_col; j++)
{
if (pMe->map[i][j] !=0)
{
write_video(pMe,(i)*pMe->block_width+pMe->block_width,(j)*pMe->block_width+pMe->block_height,pMe->color_table[pMe->map[i][j]],black);
}
else
write_video(pMe,(i)*pMe->block_width+pMe->block_width,(j)*pMe->block_width+pMe->block_height,RGB_NONE,noblack);
}
}
for (i=0; i<pMe->x_size; i++)
{
for (j=0; j<pMe->y_size; j++)
{
if (pMe->block[i][j] != 0)
write_video(pMe,(pMe->block_x+i)*pMe->block_width+pMe->block_width,(pMe->block_y+j)*pMe->block_width+pMe->block_height,pMe->color_table[pMe->block[i][j]],black);
}
}
}
//===================================================================
//Function: deleterow
//Description: delete one more rows
//Side effect: play with the display
//===================================================================
void DeleteRow(CGametype * pMe) /*delete a line meet the requirement*/
{
int sum, i, j,k,del = 0;
int a[]={0,1,3,5,7};
AECHAR game_score[8];
for (i=pMe->map_col-1; i>=0; i--)
{
sum = 0;
for (j=0; j<pMe->map_line; j++) sum += pMe->map[j][i]?1:0;
if (sum == pMe->map_line)
{
for (j=i; j>=1; j--) for (k=0; k<pMe->map_line; k++) pMe->map[k][j] = pMe->map[k][j-1];
i++;
del++;
}
}
if(del!=0)
{
//ISHELL_Beep(pMe->a.m_pIShell, BEEP_ERROR, TRUE);
pMe->dels += del;
pMe->score+=del*100+(del-1)*25+(pMe->dels/10)*50;
up_Itoa(game_score,(int)pMe->score);
IDISPLAY_DrawText(pMe->a.m_pIDisplay, // Display instance
AEE_FONT_BOLD, // Use BOLD font
game_score, // Text - Normally comes from resource
-1, // -1 = Use full string length
MAP_WIDTH*pMe->block_width+1+pMe->block_width+pMe->block_width, // x-cordinate
MAP_HEIGHT*pMe->block_height-16+pMe->block_height, // y-cordinate
NULL, // No clipping
0);//IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
}
}
//game over
void Gameover(CGametype * pMe,uint32 r_color,uint32 g_color, uint32 b_color) /*draw map*/
{int i,j;
AECHAR game_over[] ={'G','a','m','e',' ','O','v','e','r','!','\0'};
for (i=0; i<pMe->map_line; i++)
{
for (j=0; j<pMe->map_col; j++)
{
write_video(pMe,(i)*pMe->block_width+pMe->block_width,(j)*pMe->block_width+pMe->block_height,MAKE_RGB(r_color, g_color, b_color),black);
}
}
IDISPLAY_DrawText(pMe->a.m_pIDisplay, // Display instance
AEE_FONT_BOLD, // Use BOLD font
game_over, // Text - Normally comes from resource
-1, // -1 = Use full string length
pMe->block_height, // x-cordinate
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -