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

📄 games_lightup.c

📁 几个嵌入式手机平台小游戏c源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
 #ifdef __cplusplus
extern "C" {
#endif

/*==================================================================================================

    MODULE NAME : module-filename.c

    GENERAL DESCRIPTION
        General description of this grouping of functions.

    TECHFAITH Telecom Confidential Proprietary
    (c) Copyright 2002 by TECHFAITH Telecom Corp. All Rights Reserved.
====================================================================================================

    Revision History
   
    Modification                  Tracking
    Date         Author           Number      Description of changes
    ----------   --------------   ---------   -----------------------------------------------------------------------------------
    MM/DD/YYYY   name of author   crxxxxx     Brief description of changes made

    03/03/2002   Steven Lai      PP00132      Change some popup timer from absolute number to default value 
    03/01/2003   Steven Lai      PC00009      Restructure Games app
    03/13/2003   Steven Lai      PP00159      Removed some useless code
    04/25/2003   Steven Lai      P000166      Change the default focused item of the highscore list, to 
                                              let there is no item be highlighted

    05/27/2003   Chenyu          P000436      Fix sublcd & game display
    03-06-3      Chenyu          P00502       Fix game tetris

    07/02/2003   Steven Lai       C000662     Add a sound-switch for Games App
                                              replace all the App_change_state() with Games_change_state()
                                              fixed some bugs
    07/11/2003   Steven Lai       P000887     When user press any key, stop the audio
    03-09-10       lixingbo           C001812     Add touch function.
    02/24/2004   lixingbo           p002467    Modify the game for dolphin.
    03/22/2004   chouwangyun   p002678          modify cargador softkey display game problem
    03/29/2004   lixingbo           p002775    Modify the some bug for dolphin.
    04/14/2004   lixingbo           p002994    Modify some bug for dolphin.
    05/24/2004   lixingbo           p005556    Modify some bug for dolphin.
    Self-documenting Code
    Describe/explain low-level design of this module and/or group of funtions and/or specific
    funtion that are hard to understand by reading code and thus requires detail description.
    Free format !
        
====================================================================================================
    INCLUDE FILES
==================================================================================================*/
#include "APP_include.h"

#include "MENU_main.h"

#include "GAMES_main.h"

#ifdef GAMES_LIGHTUP

#include <stdlib.h>

#include "uhapi.h"

#include "SP_volume.h"
#include "Ds_lcd.h"
#include "SP_audio.h"

#include "GAMES_highscore.h"

/*==================================================================================================
    LOCAL FUNCTION PROTOTYPES
==================================================================================================*/
void APP_Lightup_entry(void);
void App_Lightup_exit(void);
void App_Lightup_handler ( OPUS_EVENT_ENUM_TYPE   event, 
                                 void                   *pMess, 
                                 OP_BOOLEAN             *handle );

static void APP_Lightup_Init(void);
static void initRoadblocks(void);
static void on_KeyPress(void  *pMess);
static void moveCursor(DIRECTION direct);
static void switchLights(void);
static void Paint(void);
static void ShowStatus(void);
static void DrawSquare(OP_UINT8 row, OP_UINT8 col);
static void DrawCursor(OP_BOOLEAN);
static void LightupRun(void );
static void drawDigit(OP_UINT16 wInteger,OP_INT16 x, OP_INT16 y);
static void ShowGameOver(OP_UINT16 wScore);

/*==================================================================================================
    LOCAL CONSTANTS
==================================================================================================*/
#define         LIGHTUP_BG_COLOR             COLOR_BLUE  
#define         MAX_STRING_LENGTH           100
#define    maxRow            5
#define    maxCol            5

/*==================================================================================================
    LOCAL TYPEDEFS - Structure, Union, Enumerations...etc
==================================================================================================*/

/*
 * description of this structure, if needed. - Remember self documenting code
 */
typedef enum
{
    ON,
    OFF
}STATUS; 

/*==================================================================================================
    LOCAL MACROS
==================================================================================================*/
/*
 * description of this macro, if needed. - Remember self documenting code
 */

/*==================================================================================================
    LOCAL VARIABLES
==================================================================================================*/
static OP_UINT8 totalRow;
static OP_UINT8 totalCol;
static OP_UINT8 square_width;

static OP_INT16 xoffset,yoffset;

static OP_UINT8 state;
static OP_UINT16 step;
static OP_UINT8 on_lights;

static OP_UINT8 cursorI, cursorJ;

static OP_UINT8 text_str[MAX_STRING_LENGTH];   

static STATUS map[maxRow][maxCol];

static OP_BOOLEAN gamePause;
static OP_BOOLEAN inGame;

static RM_SOUND_ID_T sound_list[]=
{
    RES_SOUND_0010,  /* lightup opening song */
    RES_SOUND_0014,  /* switch lights */
    RES_SOUND_0010,  /* game over */
};

/*==================================================================================================
    GLOBAL VARIABLES
==================================================================================================*/
extern APP_GAMES_STRUCTURE_NAME_T   gamesApp_data;
extern APP_SUBSTATE_STRUCTURE_NAME_T games_substate;



/*==================================================================================================
    LOCAL FUNCTIONS
==================================================================================================*/

/*==================================================================================================
    FUNCTION: APP_Lightup_entry

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
void APP_Lightup_entry(void)
{
    ds_set_screen_mode(SCREEN_OWNERDRAW);
    gamesApp_data.popupwin=OP_NULL;

    APP_Lightup_Init();
}

/*==================================================================================================
    FUNCTION: App_Lightup_exit

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
void App_Lightup_exit(void)
{
    close_old_popup();
    ds_set_softkeys_rm(PMPT_SKEY_EMPTY, PMPT_SKEY_EMPTY, PMPT_SKEY_EMPTY);   
    SP_Audio_stop();
}


/*==================================================================================================
    FUNCTION: app_Lightup_handler

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
void    
App_Lightup_handler
( 
    OPUS_EVENT_ENUM_TYPE   event, 
    void                   *pMess, 
    OP_BOOLEAN             *handle 
)
{
    KEYEVENT_STRUCT *pKey;
    TP_PEN_EVENT_STRUCTURE_T  *pPen;
    TPO_OPERATION_PARAM_STRUCTURE_T *  pOperation_param;

    switch (event)
    {
        case OPUS_FOCUS_CUST_PAINT :
            if ( (pMess != OP_NULL) && (*((OP_BOOLEAN *)pMess) == OP_TRUE))
            {
                if (ds_get_screen_mode() != SCREEN_OWNERDRAW)
                {
                    ds_set_screen_mode( SCREEN_OWNERDRAW);
                }
                clear_full_screen(LIGHTUP_BG_COLOR);
                Paint();
                // start sound here
                gamePause=OP_FALSE;
                TPO_SetCurrent_RPU(TPO_RUI_GAMES);
                LightupRun();
            }
            break;

            case OPUS_TIMER_GAME_TIMING:
                if (!gamePause && inGame)
                {
                    LightupRun();
                }
                break;

            case OPUS_FOCUS_KEYPAD :
                pKey = (KEYEVENT_STRUCT *)pMess;
                if(pKey->state == UHKEY_RELEASE) 
                {
                    break;
                }
                on_KeyPress(pMess);
                break;

            case OPUS_TIMER_POPUP_MSG:
                if (gamesApp_data.popupwin != OP_NULL)
                {
                     close_old_popup();
                }
                Games_change_state((OP_UINT8) APP_GAMES_STATE_MENU);
                break;
            
            case OPUS_FOCUS_CUST_APP_PAUSE:
                gamePause=OP_TRUE;
                OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
                if (gamesApp_data.popupwin!= OP_NULL)
                {
                    close_old_popup();
                    Games_change_state((OP_UINT8) APP_GAMES_STATE_MENU);
                }
                break;
            case OPUS_FOCUS_PEN :
                pPen=pMess;
                op_debug(DEBUG_MED,"PENX=%d\nPENY=%d\n",pPen->x,pPen->y);
                if(inGame != OP_FALSE && TP_PEN_STATE_PENDN == pPen->state
                    && pPen->x<square_width*totalCol+xoffset && pPen->x>xoffset
                    && pPen->y<square_width*totalRow+yoffset+LCD_ANNUN_HIGH && pPen->y>yoffset+LCD_ANNUN_HIGH)
                    {
                        DrawCursor(OP_FALSE);
                        cursorI = (pPen->y-yoffset-20)/square_width;
                        cursorJ = (pPen->x-xoffset)/square_width;
                        op_debug(DEBUG_MED,"CURSORI=%d\n",cursorI);
                        DrawCursor(OP_TRUE);
                        ds_refresh();
                        step++;
                        switchLights();
                    }
                break;
        case OPUS_FOCUS_OPERATION:
           pOperation_param = (TPO_OPERATION_PARAM_STRUCTURE_T *)pMess;
           switch (pOperation_param->op)   
           {
           case OPERATION_ID_SK_CONFIRM:
               {
                   switch(pOperation_param->id)
                   {
                       case COMMAND_SOFTKEY_LEFT:
                            if(gamesApp_data.popupwin != OP_NULL)
                            {
                                close_old_popup();
                            }
                            OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
                            APP_Lightup_Init();
                          break;
                       case COMMAND_SOFTKEY_RIGHT:
                                 Games_change_state((OP_UINT8) APP_GAMES_STATE_MENU);
                          break;
                       default:
                          break;
                   }
               }
                   break;
                default:
                   break;
           }
           break;
           default :
                *handle = OP_FALSE;
                break;
    }
}


/*==================================================================================================
    FUNCTION: APP_Lightup_Init

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
static void APP_Lightup_Init(void)
{
    OP_UINT8 i,j;

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

    switch(gamesApp_data.select_item)
    {
        case 0:
            totalRow = gamesApp_data.select_item+2;
            totalCol = totalRow;
            square_width = 58;
            xoffset=30;
            yoffset=22;
            break;
            
        case 1:
            totalRow = gamesApp_data.select_item+2;
            totalCol = totalRow;
            square_width = 44;
            xoffset=22;
            yoffset=14;
            break;
            
        case 2:
            totalRow = gamesApp_data.select_item+2;
            totalCol = totalRow;
            square_width = 30;
            xoffset=28;
            yoffset=20;
            break;
            
        case 3:    /* fall through */
        default:
            totalRow = gamesApp_data.select_item+2;
            totalCol = totalRow;
            square_width = 30;
            xoffset=13;
            yoffset=5;
            break;
    }

    for(i=0;i<totalRow;i++)
        for(j=0;j<totalCol;j++)
        {
            map[i][j]=OFF;
        }

    on_lights=0;
            
    cursorI= totalRow/2;
    cursorJ = totalCol/2;
    state= 0;
    step=0;
    
    gamePause=OP_FALSE;
    TPO_SetCurrent_RPU(TPO_RUI_GAMES);
    inGame=OP_TRUE;

    clear_full_screen(LIGHTUP_BG_COLOR);
    Paint();
    LightupRun();
}


/*==================================================================================================
    FUNCTION: onKeyPress

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
static void on_KeyPress(void  *pMess)
{
    KEYEVENT_STRUCT *pKey;
    OP_UINT16 code;

    SP_Audio_stop();
    pKey=(KEYEVENT_STRUCT *)pMess;
    code=pKey->code;
    switch(code)
    {
        case KEY_SIDE_UP:
            if (gamesApp_data.volume < VOLUME_LEVEL_SIZE-1)
            {
                gamesApp_data.volume++;
            }
            break;

        case KEY_SIDE_DOWN:
            if (gamesApp_data.volume > 0)
            {
                gamesApp_data.volume--;
            }
            break;
        
        case KEY_8:
        case KEY_DOWN:
            if (inGame)
            {
                moveCursor(DOWN);
            }
            break;

        case KEY_2: 
        case KEY_UP:
            if (inGame)
            {
                moveCursor(UP);
            }
            break;

        case KEY_LEFT:
        case KEY_4: 
            if (inGame)
            {
                moveCursor(LEFT);
            }
            break;
            
        case KEY_RIGHT:
        case KEY_6:
            if (inGame)
            {
                moveCursor(RIGHT);
            }
            break;
                       
        case KEY_5: 
        case KEY_OK:
            if (inGame)
            {
                step++;
                switchLights();
            }
            break;

           
        case KEY_SOFT_LEFT:

⌨️ 快捷键说明

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