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

📄 games_gopher.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 timer interval and the display method, to quicken 
                                              the response when press a corresponding key
    03-06-24     Chenyu           P00666     Fix bugs of games
                                       - 1.in game cargador, missed call will stop animation.
                                       - 2.in game help incoming missed call, softkey display wrong.
                                       - 3.it can't exit highscroe by press "Back"
                                       - 4.it can't back exit game by press "CLR"

    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
    03-09-10       lixingbo          C001812     Add touch function
    02/24/2004   lixingbo           p002467    Modify the game for dolphin.
    06/12/2004   lixingbo           p006127    Modify display bugs lotus.
    08/02/2004   Lixingbo          p007438    Modify the tp back function.
    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_GOPHER

#include <stdlib.h>
#include "uhapi.h"

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

#include "GAMES_highscore.h"

/*==================================================================================================
    LOCAL FUNCTION PROTOTYPES
==================================================================================================*/
void APP_Gopher_entry(void);
void App_Gopher_exit(void);
void App_Gopher_handler ( OPUS_EVENT_ENUM_TYPE   event, 
                                 void                   *pMess, 
                                 OP_BOOLEAN             *handle );

static void APP_Gopher_Init(void);
static void on_KeyPress(void  *pMess);
static void Paint(void);
static void DrawSquare(OP_INT8 col,OP_INT8 row, OP_UINT8 state);
static void judgeHit(OP_INT8 row, OP_INT8 col);
static void GopherRun(void );
static void drawDigit(OP_INT16 wInteger,OP_INT16 x, OP_INT16 y);
static void ShowGameOver(OP_UINT16 wScore);
static void ShowScore(void);

/*==================================================================================================
    LOCAL CONSTANTS
==================================================================================================*/
#define    rowNum            4
#define    colNum            3
#define    SQUAREWIDTH    56
#define    SQUAREHEIGHT    45

#define         GOPHER_BG_COLOR             COLOR_YELLOW_DEEP  
#define         MAX_STRING_LENGTH           100
#define         MAX_CONCURRENT_GOPHERS  4

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

/*
 * description of this structure, if needed. - Remember self documenting code
 */

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

/*==================================================================================================
    LOCAL VARIABLES
==================================================================================================*/
static OP_UINT8 current_level;


/*
 * the state of each position
 */
static OP_UINT8 field[rowNum][colNum];   /* 4*3 array */
static OP_BOOLEAN hasHit[rowNum][colNum];

static OP_INT16 xoffset,yoffset;

static OP_UINT16 totalGophers;
static OP_UINT8 concurrentGophers;

static OP_UINT16 score;
static OP_UINT8 missed;
static OP_BOOLEAN gamePause;
static OP_BOOLEAN inGame;

static OP_BOOLEAN levelPassed;  /* when gain 10 score, pass to the next level */

static OP_UINT16 interval;

//static OP_UINT8 text_str[MAX_STRING_LENGTH];     

static RM_SOUND_ID_T sound_list[]=
{
    RES_SOUND_0009,  /* Gophers's opening song */
    RES_SOUND_0011,  /* sound of hiting */
    RES_SOUND_0012,  /* sound that fails to hit */
    RES_SOUND_0009   /* game over */
};

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



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

/*==================================================================================================
    FUNCTION: APP_Gopher_entry

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

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

    APP_Gopher_Init();
}

/*==================================================================================================
    FUNCTION: App_Gopher_exit

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

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


/*==================================================================================================
    FUNCTION: app_Gopher_handler

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
void    
App_Gopher_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;
    *handle = OP_TRUE;

    switch (event)
    {
        case OPUS_FOCUS_CUST_PAINT :
            if ( (pMess != OP_NULL) && (*((OP_BOOLEAN *)pMess) == OP_TRUE))
            {
                if (ds_get_screen_mode() != SCREEN_FULL_IMAGE)
                    ds_set_screen_mode( SCREEN_FULL_IMAGE);
                ds_fill_rect(0,0, LCD_MAX_X-1, LCD_MAX_Y-1, GOPHER_BG_COLOR); 
                ds_set_softkeys_rm( PMPT_SKEY_EMPTY,PMPT_SKEY_EMPTY, PMPT_SKEY_BACK);
                ds_draw_text_rm(140,204, PMPT_SKEY_BACK, FONT_SIZE_SMALL|FONT_OVERLAP, 
                                  COLOR_RED,
                                  COLOR_FONTBG);
                Paint();
                // start sound here
                gamePause=OP_FALSE;
                TPO_SetCurrent_RPU(TPO_RUI_GAMES);
                if (inGame)
                {
                    GopherRun();
                }
            }
            else 
                ds_refresh();
            break;

        case OPUS_TIMER_GAME_TIMING:
            if (!gamePause && inGame)
                GopherRun();
            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;
    		if(inGame != OP_FALSE && !gamePause && TP_PEN_STATE_PENDN == pPen->state)
    		{
        		judgeHit((OP_INT8)((pPen->y-yoffset)/SQUAREHEIGHT),(OP_INT8)((pPen->x-xoffset)/SQUAREWIDTH));
    		}
           	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_OK:
                          break;
                       case COMMAND_SOFTKEY_RIGHT:
                            if(gamesApp_data.popupwin != OP_NULL)
                            {
                                inGame=OP_FALSE;
                                close_old_popup();
                                OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
                                Games_change_state((OP_UINT8) APP_GAMES_STATE_MENU);
                            }
                            else
                            {
                                ShowGameOver(score);
                            }
                          break;
                       default:
                          break;
                   }
               }
                   break;
                default:
                   break;
           }
           break;
           default :
            *handle = OP_FALSE;
            break;
    }
}


/*==================================================================================================
    FUNCTION: APP_Gopher_Init

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

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

    srand( op_get_cur_tod()); /* set the seed for rand() */
    
    for (i=0; i<4; i++)
        for (j=0; j<3; j++)
        {
            field[i][j] = 0;
            hasHit[i][j] = OP_FALSE;
        }
        
    xoffset=4;
    yoffset=2;
    current_level=1;
    
    totalGophers=0;
    concurrentGophers=0;
    
    score=0;
    missed=0;
    interval = 200;

    TPO_SetCurrent_RPU(TPO_RUI_GAMES);
    inGame=OP_TRUE;
    gamePause=OP_FALSE;
    levelPassed=OP_FALSE;

    if (gamesApp_data.audio_on == OP_TRUE)
    {
        SP_Audio_play_request(sound_list[0], gamesApp_data.volume, OP_FALSE);   
    }
    
    //clear_full_screen(GOPHER_BG_COLOR);
    ds_fill_rect(0,0, LCD_MAX_X-1, LCD_MAX_Y-1, GOPHER_BG_COLOR); 
    Paint();
    ds_set_softkeys_rm( PMPT_SKEY_EMPTY,PMPT_SKEY_EMPTY, PMPT_SKEY_BACK);
    ds_draw_text_rm(140,204, PMPT_SKEY_BACK, FONT_SIZE_SMALL|FONT_OVERLAP, 
                      COLOR_RED,
                      COLOR_FONTBG);
    GopherRun();
}


/*==================================================================================================
    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;

    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_1: 
            if (inGame)
                judgeHit(0, 0);
            break;

        case KEY_2: 
            if (inGame)
                judgeHit(0, 1);
            break;

        case KEY_3: 
            if (inGame)
                judgeHit(0, 2);
            break;
            
        case KEY_4: 
            if (inGame)
                judgeHit(1, 0);
            break;
            
        case KEY_5: 
            if (inGame)
                judgeHit(1, 1);
            break;
            

⌨️ 快捷键说明

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