⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 games_huarong.c

📁 几个嵌入式手机平台小游戏c源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
				else
				{
        				hasMovedy = OP_FALSE;
        				op_debug(DEBUG_MED,"curmap[%d][%d]=%d,nextmap[%d][%d]=%d,nextmap[%d][%d]=%d\n",
						cursorY,cursorX,map[cursorY][cursorX],cursorY+1,cursorX,map[cursorY+1][cursorX],
						cursorY+1,cursorX+1,map[cursorY+1][cursorX+1]);
        				break;
				}
				
        		}
        		else
        		{
				if(JudgeNextPiece(UP))
				{
        				k = k-JudgeStep(UP);
        				state = MOVEPIECE;
        				movePiece(UP);
				
        				op_debug(DEBUG_MED,"curmap[%d][%d]=%d,nextmap[%d][%d]=%d,nextmap[%d][%d]=%d\n",
						cursorY,cursorX,map[cursorY][cursorX],cursorY+1,cursorX,map[cursorY+1][cursorX],
    						cursorY+1,cursorX+1,map[cursorY+1][cursorX+1]);
        				op_debug(DEBUG_MED,"movePiece(UP)k=%d\n",k);
				}
				else
				{
        				hasMovedy = OP_FALSE;
        				op_debug(DEBUG_MED,"curmap[%d][%d]=%d,nextmap[%d][%d]=%d,nextmap[%d][%d]=%d\n",
						cursorY,cursorX,map[cursorY][cursorX],cursorY+1,cursorX,map[cursorY+1][cursorX],
    						cursorY+1,cursorX+1,map[cursorY+1][cursorX+1]);
        				break;
				}
        		}
    		}
                else
                {
                    break;
                }
    }
    if(pieceClicked)
    {
    		MoveIfCan();
    		posx = cursorX;
    		posy = cursorY;
    }
    if(!hasMovedx && !hasMovedy)
    {
    		posx = cursorX;
    		posy = cursorY;
    }
    HighlightSquare(map[cursorY][cursorX]); 
    ds_refresh();
    if(map[posy][posx] != FIRST_BLANK
    		&& map[posy][posx] != SECOND_BLANK)
    {
    		ChangeState();
    		OPUS_Stop_Timer(OPUS_TIMER_GAME_PEN);
    }
    else
    {
    		OPUS_Start_Timer(OPUS_TIMER_GAME_PEN, 1, 0,  ONE_SHOT);
    }

    
    return OP_TRUE;
}
/*==================================================================================================
    FUNCTION: JudgeNextPiece

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
static OP_BOOLEAN JudgeNextPiece(DIRECTION direct)
{
        OP_UINT8  currentPiece;
        OP_UINT8  pieceWidth, pieceHeight;

        currentPiece=map[cursorY][cursorX];
        pieceWidth = pieces[currentPiece].width;
        pieceHeight = pieces[currentPiece].height;
        /*Judge if the picture can be moved.*/
        switch(direct)
        {
    		case DOWN:
        		if((map[cursorY+pieceHeight][cursorX]!=10 &&
    				map[cursorY+pieceHeight][cursorX]!=11)||
    				(map[cursorY+pieceHeight][cursorX+pieceWidth-1]!=10 &&
    				map[cursorY+pieceHeight][cursorX+pieceWidth-1]!=11))
				{op_debug(DEBUG_MED,"curmap[%d][%d]=%d,nextmap[%d][%d]=%d,nextmap[%d][%d]=%d\n",
						cursorY,cursorX,map[cursorY][cursorX],cursorY+1,cursorX,map[cursorY+1][cursorX],
    						cursorY+1,cursorX+1,map[cursorY+1][cursorX+1]);
    				return OP_FALSE;}
        		break;
    		case UP:
        		if((map[cursorY-1][cursorX]!=10 &&
    				map[cursorY-1][cursorX]!=11 ) ||
    				(map[cursorY-1][cursorX+pieceWidth-1]!=10 &&
    				map[cursorY-1][cursorX+pieceWidth-1]!=11))
    				return OP_FALSE;
        		break;
    		case RIGHT:
        		if((map[cursorY][cursorX+pieceWidth]!=10 &&
    				map[cursorY][cursorX+pieceWidth]!=11) ||
    				(map[cursorY+pieceHeight-1][cursorX+pieceWidth]!=10 &&
    				map[cursorY+pieceHeight-1][cursorX+pieceWidth]!=11))
    				return OP_FALSE;
        		break;
    		case LEFT:
        		if((map[cursorY][cursorX-1]!=10 &&
    				map[cursorY][cursorX-1]!=11) ||
    				(map[cursorY+pieceHeight-1][cursorX-1]!=10 &&
    				map[cursorY+pieceHeight-1][cursorX-1]!=11))
    				return OP_FALSE;
        		break;
    		default:
        		break;
        }
        return OP_TRUE;
    		
}
/*==================================================================================================
    FUNCTION: JudgeStep

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
static OP_INT8 JudgeStep(DIRECTION direct)
{
        OP_UINT8  currentPiece,nextPiece;
        OP_UINT8  currentpieceWidth, currentpieceHeight;
        OP_UINT8  nextpieceWidth, nextpieceHeight;
        OP_UINT8  step=0;

        currentPiece=map[cursorY][cursorX];
        currentpieceWidth = pieces[currentPiece].width;
        currentpieceHeight = pieces[currentPiece].height;
        /* Judge the exact steps the picture should be moved.*/
        switch(direct)
        {
    		case DOWN:
        		nextPiece = map[cursorY+currentpieceHeight][cursorX];
        		nextpieceWidth = pieces[nextPiece].width;
        		step += currentpieceHeight;
        		break;
    		case UP:
        		nextPiece = map[cursorY-1][cursorX];
        		nextpieceWidth = pieces[nextPiece].width;
        		step += 1;
        		break;
    		case RIGHT:
        		nextPiece = map[cursorY][cursorX+currentpieceWidth];
        		nextpieceHeight = pieces[nextPiece].height;
        		step += currentpieceWidth;
        		break;
    		case LEFT:
        		nextPiece = map[cursorY][cursorX-1];
        		nextpieceHeight = pieces[nextPiece].height;
        		step += 1;
        		break;
    		default:
        		break;
        }
        return step;

}

/*==================================================================================================
    FUNCTION: ShowGameOver

    DESCRIPTION:
        
    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
static void ShowGameOver(OP_UINT16 wScore)
{
    char ss[4];
    OP_UINT8 ustr[MAX_STRING_LENGTH];
    OP_UINT8 tmpstr[MAX_STRING_LENGTH];
    APP_GAMES_ID_ENUM_T game_id;  

    switch(gamesApp_data.select_item)
    {
        case 0:     
            game_id=APP_GAMES_HUARONG_MAP1;
            break;
            
        case 1:
            game_id=APP_GAMES_HUARONG_MAP2;
            break;
            
        case 2:
            game_id=APP_GAMES_HUARONG_MAP3;
            break;
            
        case 3:
            game_id=APP_GAMES_HUARONG_MAP4;
            break;
            
        default:
            break;
    }

    inGame=OP_FALSE;
    if (gamesApp_data.audio_on == OP_TRUE)
    {
        SP_Audio_play_request(sound_list[2], gamesApp_data.volume, OP_FALSE);   
    }

    op_memset((void*)ustr, 0, MAX_STRING_LENGTH); 
    op_memset((void*)tmpstr, 0, MAX_STRING_LENGTH);

    OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);

    if (wScore > 0 && is_new_highscore(game_id, wScore))
    {
        util_get_text_from_res_w_max_len(PMPT_TEXT_CONGRATULATION,ustr,MAX_STRING_LENGTH);
        util_get_text_from_res_w_max_len(PMPT_TEXT_NEW_HIGHSCORE,tmpstr,MAX_STRING_LENGTH);
    }
    else
    {
        util_get_text_from_res_w_max_len(PMPT_TEXT_GAME_OVER,ustr,MAX_STRING_LENGTH);
        util_get_text_from_res_w_max_len(PMPT_TEXT_YOUR_STEP,tmpstr,MAX_STRING_LENGTH);
    }
    Ustrcat(ustr,tmpstr);

    op_sprintf(ss,"%d",wScore);
    AtoU(tmpstr,(OP_UINT8 *)ss);
    Ustrcat(ustr,tmpstr);

    gamesApp_data.popupwin=ds_popup_message(OP_NULL, ustr, DS_POPUP_DEFAULT_MSG_TIME);
}

/*==================================================================================================
    FUNCTION: MoveIfCan

    DESCRIPTION:
        
    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
static OP_BOOLEAN MoveIfCan()
{
        OP_UINT8  currentPiece,mark[4]={0};
        OP_UINT8  pieceWidth, pieceHeight;
        OP_UINT8  direcNum = 0;
        DIRECTION direct,MoveDirect;
        currentPiece = map[cursorY][cursorX];
        pieceWidth = pieces[currentPiece].width;
        pieceHeight = pieces[currentPiece].height;

        for(direct=LEFT;direct<=RIGHT;direct++)
        {
		switch(direct)
		{
                    case RIGHT:
				if(cursorX <= colNum-2 )
				{
        				if( (map[cursorY][cursorX+pieceWidth] == FIRST_BLANK ||
						map[cursorY][cursorX+pieceWidth] == SECOND_BLANK)
						&& (map[cursorY+pieceHeight-1][cursorX+pieceWidth] == FIRST_BLANK ||
        						map[cursorY+pieceHeight-1][cursorX+pieceWidth] == SECOND_BLANK) )
        						{
								direcNum++;
								MoveDirect = RIGHT;
								mark[RIGHT] = 1;
        						}
				}
				break;
        		case LEFT:
				if(cursorX > 0)
				{
        				if( (map[cursorY][cursorX-1] == FIRST_BLANK ||
						 map[cursorY][cursorX-1] == SECOND_BLANK)
                				&& (map[cursorY+pieceHeight-1][cursorX-1] == FIRST_BLANK ||
        						map[cursorY+pieceHeight-1][cursorX-1] == SECOND_BLANK) )
        						{
                						direcNum++;
                						MoveDirect = LEFT;
                						mark[LEFT] = 1;
        						}
				}
				break;
        		case DOWN:
				if(cursorY <= rowNum-2)
				{
        				if( (map[cursorY+pieceHeight][cursorX] == FIRST_BLANK ||
						map[cursorY+pieceHeight][cursorX] == SECOND_BLANK)
						&& (map[cursorY+pieceHeight][cursorX+pieceWidth-1] == FIRST_BLANK ||
        						map[cursorY+pieceHeight][cursorX+pieceWidth-1] == SECOND_BLANK) )
        						{
                						direcNum++;
                                                        MoveDirect = DOWN;
								mark[DOWN] = 1;
        						}
				}
				break;
        		case UP:
				if(cursorY > 0)
				{
        				if( (map[cursorY-1][cursorX] == FIRST_BLANK ||
						  map[cursorY-1][cursorX] == SECOND_BLANK)
						&& (map[cursorY-1][cursorX+pieceWidth-1] == FIRST_BLANK ||
        						map[cursorY-1][cursorX+pieceWidth-1] == SECOND_BLANK) )
        						{
								direcNum++;
								MoveDirect = UP;
								mark[UP] = 1;
        						}
        						
				}
				break;
        		default:
				break;
		}
        }
        if(direcNum == 1)
        {
            movePiece(MoveDirect);
        }
        else
        {
		if(direcNum > 1)
		{
                    for(direct=LEFT;direct<=RIGHT;direct++)
                    {
				if(mark[direct] == 1)
				{
        				DrawCursor(direct);
				}
        		}
		}
        }
    return OP_SUCCESS;
}
/*==================================================================================================
    FUNCTION: DrawCursor

    DESCRIPTION:
        
    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
static void DrawCursor(DIRECTION direct)
{
    OP_UINT8  currentPiece;
    OP_UINT8  pieceWidth, pieceHeight;
    OP_INT16 x1=0,y1=0,x2=0,y2=0;
    currentPiece = map[cursorY][cursorX];
    pieceWidth = pieces[currentPiece].width;
    pieceHeight = pieces[currentPiece].height;

    switch(direct)
    {
		case LEFT:
                    x1 = cursorX*RECTWIDTH-3*RECTWIDTH/4+xoffset+FRAMEWIDTH;
                    y1 = cursorY*RECTHEIGHT+pieceHeight*RECTHEIGHT/2+yoffset+FRAMEWIDTH;
                    x2 = cursorX*RECTWIDTH-RECTWIDTH/2+xoffset+FRAMEWIDTH;
                    y2 = cursorY*RECTHEIGHT+pieceHeight*RECTHEIGHT/4+yoffset+FRAMEWIDTH;
                    break;
                case RIGHT:
                    x1 = cursorX*RECTWIDTH+pieceWidth*RECTWIDTH+RECTWIDTH/4+xoffset+FRAMEWIDTH;
                    y1 = cursorY*RECTHEIGHT+pieceHeight*RECTHEIGHT/2+yoffset+FRAMEWIDTH;
                    x2 = cursorX*RECTWIDTH+pieceWidth*RECTWIDTH+RECTWIDTH/2+xoffset+FRAMEWIDTH;
                    y2 = cursorY*RECTHEIGHT+pieceHeight*RECTHEIGHT/4+yoffset+FRAMEWIDTH;
                    break;
                case DOWN:
                    x1 = cursorX*RECTWIDTH+pieceWidth*RECTWIDTH/4+xoffset+FRAMEWIDTH;
                    y1 = cursorY*RECTHEIGHT+pieceHeight*RECTHEIGHT+RECTHEIGHT/2+yoffset+FRAMEWIDTH;
                    x2 = cursorX*RECTWIDTH+pieceWidth*RECTWIDTH/2+xoffset+FRAMEWIDTH;
                    y2 = cursorY*RECTHEIGHT+pieceHeight*RECTHEIGHT+RECTHEIGHT/4+yoffset+FRAMEWIDTH;
                    break;
                case UP:
                    x1 = cursorX*RECTWIDTH+pieceWidth*RECTWIDTH/4+xoffset+FRAMEWIDTH;
                    y1 = cursorY*RECTHEIGHT-RECTHEIGHT/2+yoffset+FRAMEWIDTH;
                    x2 = cursorX*RECTWIDTH+pieceWidth*RECTWIDTH/2+xoffset+FRAMEWIDTH;
                    y2 = cursorY*RECTHEIGHT-3*RECTHEIGHT/4+yoffset+FRAMEWIDTH;
                    break;
		default:
        		break;
    }
    ds_draw_line(x1,  y1,  (OP_INT16)(x1+RECTWIDTH/2), y1, COLOR_RED);
    ds_draw_line(x2,  y2,  x2, (OP_INT16)(y2+RECTHEIGHT/2), COLOR_RED);
    ds_refresh();
}
/*==================================================================================================
    FUNCTION: ChangeState

    DESCRIPTION:
        
    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
static void ChangeState()
{
        /* If the picture can be moved, then change the state to "MOVEPIECE", else "MOVECURSOR". */
        if (map[cursorY][cursorX]<10 &&                             
            (pieces[map[cursorY][cursorX]].roadblocks[LEFT] == 0 ||  
            pieces[map[cursorY][cursorX]].roadblocks[RIGHT] == 0 ||  
            pieces[map[cursorY][cursorX]].roadblocks[UP] == 0 ||     
            pieces[map[cursorY][cursorX]].roadblocks[DOWN] == 0 ))   
            {                                                           
                state = MOVEPIECE; 
                state1 = 0;
                HuarongRun();                                           
            }
        else
        {
            state = MOVECURSOR;
        }                                                           
}       
        
        
/*==================================================================================================
    GLOBAL FUNCTIONS
==================================================================================================*/
        
/*================================================================================================*/
        
#endif  
        
#ifdef __cplusplus
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -