0

Hi friends i am doing the snake game program for Set top Box . I am Facing problem when i get the remote control keys.


if i press the up,down,right,left keys when program is running ,program does not response .once game is over then it is taking the values from keys.

Please help to solve this problem

Note : i am getting the keys through the MENU_GameKeys function,

and game starts at runsnake function

I post some parts of code here.........


Advance thanks for helping

Attachments
/**********************    Yuvaraj   ***************************************/

#include "ftypes.h"
#include "fd_lib\fd_ir.h "
#include <stdio.h>
#include "fm_lib\fm_debug.h"
#include "rtos_lib\rtos_lib.h"
#include "ffs_lib\ffs_lib.h"
#include "app_menu.h"
#include "app_satellites.h"
#include "key_input.h "
#include "sys_api.h"
#include "utils.h"
#include "config.h"
#include "fgs.h"
#include "app_menu.h"

 int data =4;


/***************** Local  Data Declaration *****************************/

enum
{
    MENU_GAME_ID_TITLE = 0,
    MENU_GAME_ID_LIST,
    MENU_GAME_ID_HELPLIST,
    MENU_GAME_ID_REST,
	MENU_GAME_ID_RUN,

};

typedef struct
{
    FD_HANDLE    pnlHdl;
    FD_HANDLE    listHdl;
    FD_HANDLE    listHelpHdl;
	FD_HANDLE    levelItemHdl;
	FGS_PANEL_MEMBER_S*   pItemBorder;
	FD_HANDLE    runItemHdl;
	FGS_POS_S    itemBorderPos;
     U8          helpStrWidth;
} MENU_GAME_INST_S;

FSTATIC MENU_GAME_INST_S*  menuGameDat = NULL;
#define MENU_GAME_WIDTH  600
/**************************************Local Functions *********************/

 startagain1();
 
 int runsnake();

 int sntargetinit(int x, int y, int dataget, U16  *temp1, U16  *temp2, int mazev, int snlen1, int levelv, int check);

 int snakefailed( U16 *xx, U16 *yy, int snlen1);

 int snmovefn();

int  getKeypadKey1(void);

U8  getPressedKey1(void);

void pausekey();

void resumekey();


FERR MENU_GameInit (void);

FBOOL MENU_GameEntry (FD_HANDLE h, FBOOL test);

FSTATIC FBOOL MENU_GameBuild( FD_HANDLE h );

FSTATIC void MENU_GameonFocusSet (FD_HANDLE h, FBOOL hasFocus);

FSTATIC FBOOL MENU_GameLeave (FD_HANDLE h, FBOOL force);

FSTATIC FBOOL MENU_GameKeys (FD_HANDLE h);

FERR MENU_Run(FD_HANDLE h);

FSTATIC void MENU_GameGetDescrItem (FD_HANDLE h, S32 id, U32 index,
                                      FGS_ITEMSTATE_E state, FGS_ITEM_S* item);
 
FSTATIC void MENU_GameGetItem (FD_HANDLE h, S32 id, U32 index,FGS_ITEMSTATE_E state, FGS_ITEM_S* item); 

FSTATIC void MENU_GameGetHelpDescrItem (FD_HANDLE h, S32 id, U32 index,
                                           FGS_ITEMSTATE_E state,
                                           FGS_ITEM_S* item);

FSTATIC FBOOL MENU_GameOnSelect (FD_HANDLE h, S32 itemId);


/********************************Intiliaze the Game  **********/
                             
FERR MENU_GameInit (void)     
{
	
	if ( menuGameDat != NULL )
		return FD_ERR_ALREADY_INITIALIZED;

    menuGameDat = RTOS_MemoryAllocate((RTOS_Size)sizeof(MENU_GAME_INST_S), FTRUE);
    if ( menuGameDat == NULL )
		return FD_ERR_OUT_OF_MEMORY;

    RTOS_MemorySet(menuGameDat, 0, sizeof(MENU_GAME_INST_S));

    menuMainDat->helpStrWidth = OSD_GetStrWidth (OSD_GetStr(STR_ENTRY_OK), -1, OSD_FONT_SYMBOL);

      return FD_OK;
}


/********************************** Entry for Game ********************************/
FBOOL MENU_GameEntry (FD_HANDLE h, FBOOL test)
{
    MENU_GAME_INST_S* inst = menuGameDat;
    U32                  lastFocusItem;

    if ( test == FTRUE ) return FTRUE;

    MENU_GameBuild((FD_HANDLE)inst);

    
   if ( MENUSTACK_GetData(&lastFocusItem) == FFALSE )
    {
        lastFocusItem = 0;
    }
    
   //  set list focus on first item *
    FGS_LIST_SetMemberFocus  (inst->listHdl, lastFocusItem);
    FGS_PANEL_SetMemberFocus (inst->pnlHdl, MENU_GAME_ID_LIST);
    MENUSTACK_FocusClaim     (MENUID_GAME);
    FGS_PANEL_Show           (inst->pnlHdl, FFALSE); /* turn visibility on */

    MENUSTACK_SetCleanup((MENUSTACK_CLEANUP)MENU_GameLeave, (FD_HANDLE)inst);

    return FTRUE; 
}


/********************************* Build Game Menu **********************************/
 
FSTATIC FBOOL MENU_GameBuild(FD_HANDLE h)
{
    MENU_GAME_INST_S* inst = (MENU_GAME_INST_S*)h;
    FGS_PANEL_OPEN_S      pnlPars;
    FGS_LIST_OPEN_S       listPars;
    FD_HANDLE             itemHdl;
    FGS_BOX_OPEN_S        boxPars;
    FGS_ITEM_TXT_OPEN_S   txtPars;
    FGS_LNAVI_OPEN_S      naviPars;
    FGS_STRING_S          boxStr;
    FGS_POS_S             itemPos;
    FGS_ITEM_S            item;
    FGS_POS_S             valuePos;
    FGS_POS_S             descrPos;
    FERR                  retVal;
    U16                   helpWidth;
    U16                   stackedFrameWidth;
    U16                   menuHeight=700;
    U32                   numLines =12;
    U8                    numHelpLines=6;
    FGS_PANEL_MEMBER_S    member;
    U16                   idCnt;
    U16                   midPos;
    
  
    
    RTOS_MemorySet(&pnlPars,  0, sizeof(pnlPars));
    RTOS_MemorySet(&naviPars, 0, sizeof(naviPars));
    RTOS_MemorySet(&listPars, 0, sizeof(listPars));
    RTOS_MemorySet(&boxPars,  0, sizeof(boxPars));
    RTOS_MemorySet(&txtPars,  0, sizeof(txtPars));
    RTOS_MemorySet(&boxStr,   0, sizeof(boxStr));
    RTOS_MemorySet(&item,     0, sizeof(item));
    RTOS_MemorySet(&itemPos,  0, sizeof(itemPos));
    RTOS_MemorySet(&descrPos, 0, sizeof(descrPos));
    RTOS_MemorySet(&valuePos, 0, sizeof(valuePos));
    RTOS_MemorySet(&member,   0, sizeof(member));
    
    helpWidth         = 0;
    stackedFrameWidth = (MENUSTACK_GetLevel() - 1) *
                        (STACKED_FRAME_DIST + OUTER_FRAME_WIDTH);
    menuHeight        = stackedFrameWidth + (2*OUTER_FRAME_WIDTH) +
                        (2*TITLE_TB_PADDING) + TITLE_LINE_HEIGHT +
                        MAIN_TOP_PADDING + MAIN_BOT_PADDING +
                        ( numLines        * LIST_LINE_HEIGHT) +
                        ((numLines - 1 )  * LIST_LINE_PADDING) +
                        ( numHelpLines    * HELP_LINE_HEIGHT) +
                        ((numHelpLines -1)* HELP_LINE_PADDING) +
                        (2*HELP_TB_PADDING) + (2*INNER_FRAME_WIDTH);
    
   
    
    do
    {
        pnlPars.pos.width       = MENU_GAME_WIDTH + helpWidth +
                                  2*OUTER_FRAME_WIDTH +
                                  INNER_FRAME_WIDTH +
                                  stackedFrameWidth;
        pnlPars.pos.height      = menuHeight;
        pnlPars.bkgrType        = OSD_PNLTYPE_MENUWTITLEWBOTHELP0 + numHelpLines;
        pnlPars.onFocusSet      = MENU_GameonFocusSet;
        pnlPars.onFocusSetArg   = (FD_HANDLE)inst;
        pnlPars.pInst           = &(appDat->pnlInst);
        
        MENU_CommonSetPanelPos(&(pnlPars.pos));
        
        retVal = FGS_PANEL_Open(&pnlPars, MENUID_GAME, &(inst->pnlHdl));
        if ( retVal != FD_OK ) break;

        /* ----- create textbox holding title ------------------------------ */

        retVal = MENU_CommonAddTitle(OSD_GetStr(STR_TITLE_GAME),
                                     MENU_GAME_ID_TITLE,
                                     inst->pnlHdl, pnlPars.pos.width,
                                     stackedFrameWidth);
        if ( retVal != FD_OK ) break;

        /* ----- create list ----------------------------------------------- */
        
      
            listPars.pos.x           = OUTER_FRAME_WIDTH +
                                       stackedFrameWidth;
            listPars.pos.y           = OUTER_FRAME_WIDTH +
                                       INNER_FRAME_WIDTH +
                                       MAIN_TOP_PADDING +
                                       (2*TITLE_TB_PADDING) +
                                       TITLE_LINE_HEIGHT +
                                       8*LIST_LINE_HEIGHT +
                                       2*LIST_LINE_PADDING +
                                       stackedFrameWidth;
            listPars.pos.width       = MENU_GAME_WIDTH;
            listPars.pos.height      = numLines * (LIST_LINE_HEIGHT+LIST_LINE_PADDING);
            
            listPars.pos.alignment   = FGS_ALIGN_HOR_LEFT | FGS_ALIGN_VER_TOP;
            listPars.bkgrType        = OSD_LSTITEM_BKGR_HELP;
            listPars.topDownOriented = FTRUE;
            listPars.wraparound      = FTRUE;
            listPars.getDescrItem    = MENU_GameGetDescrItem;
            listPars.getDescrItemArg = (FD_HANDLE)inst;
            listPars.getItem         = MENU_GameGetItem;
            listPars.getItemArg      = (FD_HANDLE)inst;
            listPars.onSelect        = MENU_GameOnSelect;
            listPars.onSelectArg     = (FD_HANDLE)inst;
            listPars.pInst           = &(appDat->listInst);
            
            retVal = FGS_LIST_Open (&listPars, MENU_GAME_ID_LIST, inst->pnlHdl,
                                    &(inst->listHdl));
            if ( retVal != FD_OK ) break;
     
        /* ----------------------------------------------------------------- */

        itemPos.x          = 0;
        itemPos.y          = 0;
        itemPos.width      = MENU_GAME_WIDTH;
        itemPos.height     = LIST_LINE_HEIGHT;
        itemPos.alignment  = FGS_ALIGN_HOR_LEFT | FGS_ALIGN_VER_TOP;

        /* position of list item descriptors in list entry */
        descrPos.x         = MAIN_LEFT_PADDING;
        descrPos.y         = 0;
        descrPos.width     = (((itemPos.width - MAIN_LEFT_PADDING - MAIN_RIGHT_PADDING) * 1 )>>1);
        descrPos.height    = LIST_LINE_HEIGHT;
        descrPos.alignment = FGS_ALIGN_HOR_LEFT | FGS_ALIGN_VER_TOP;

        /* position of list item values in list entry */
        valuePos.x         = descrPos.x + descrPos.width;
        valuePos.y         = descrPos.y;
        valuePos.width     = itemPos.width - descrPos.width -
                             MAIN_LEFT_PADDING  - MAIN_RIGHT_PADDING;
        valuePos.height    = OSD_LISTLINE_HEIGHT;
        valuePos.alignment = FGS_ALIGN_HOR_LEFT | FGS_ALIGN_VER_TOP;

        /* ----- menu lines -------------------------------------------------*/

        txtPars.bkgrType           = OSD_LSTITEM_BKGR_NORMAL;
        txtPars.descrPos           = descrPos;
        txtPars.valuePos           = valuePos;
        txtPars.pos                = itemPos;
        
        /* ----- create Service list --------------------------------------- */
        
        boxPars.pos.x               = OUTER_FRAME_WID
2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by nucleon
0

You're going to have to give more info, and preferably less code. What (non-standard) libaries are you using? For example, is FGS_GetCurrentKeyCode() a library function? Also, what does this mean exactly: "once game is over then it is taking the values from keys".

0

FGS_GetCurrentKeyCode() means some driver library function in set top box.

if i press the keys ,while running the game that time snake did not move according to the key directions..


Once game is over . Then it takes the key value and move according to the pressed key direction when i am running snake game again.


Please help me


Thanks

Yuvaraj.R

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.