Panda.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:398k
源码类别:

MTK

开发平台:

C/C++

  1.     /*----------------------------------------------------------------*/
  2.     /* Code Body                                                      */
  3.     /*----------------------------------------------------------------*/
  4.     /* compare the best grade and return it */
  5.     if (new_grade > old_grade)
  6.     {
  7.         return new_grade;
  8.     }
  9.     else
  10.     {
  11.         return old_grade;
  12.     }
  13. }
  14. /*****************************************************************************
  15.  * FUNCTION
  16.  *  mmi_gx_panda_draw_gameover
  17.  * DESCRIPTION
  18.  *  Draw Gameover Screen [Callback required by GFX]
  19.  * PARAMETERS
  20.  *  void
  21.  * RETURNS
  22.  *  void
  23.  *****************************************************************************/
  24. void mmi_gx_panda_draw_gameover(void)
  25. {
  26.     /*----------------------------------------------------------------*/
  27.     /* Local Variables                                                */
  28.     /*----------------------------------------------------------------*/
  29.     /*----------------------------------------------------------------*/
  30.     /* Code Body                                                      */
  31.     /*----------------------------------------------------------------*/
  32.     GFX_PLAY_AUDIO_GAMEOVER();
  33.     /* call this function to draw standard gameover screen */
  34.     mmi_gfx_draw_gameover_screen(
  35.         IMG_ID_GX_PANDA_GOTEXT,
  36.         IMG_ID_GX_PANDA_GRADESMAP,
  37.         IMG_ID_GX_PANDA_GOPIC,
  38.         g_gx_panda_context.game_grade);
  39. }
  40. /*****************************************************************************
  41.  * FUNCTION
  42.  *  mmi_gx_panda_enter_game
  43.  * DESCRIPTION
  44.  *  Enter Game [Callback required by GFX]
  45.  * PARAMETERS
  46.  *  void
  47.  * RETURNS
  48.  *  void
  49.  *****************************************************************************/
  50. void mmi_gx_panda_enter_game(void)
  51. {
  52.     /*----------------------------------------------------------------*/
  53.     /* Local Variables                                                */
  54.     /*----------------------------------------------------------------*/
  55.     /*----------------------------------------------------------------*/
  56.     /* Code Body                                                      */
  57.     /*----------------------------------------------------------------*/
  58.     if (g_gx_panda_context.is_new_game == TRUE)
  59.     {
  60.         mmi_gx_panda_init_game();   /* is new game, otherwise resume game */
  61.     }
  62.     g_gx_panda_context.is_new_game = FALSE;
  63.     g_gx_panda_context.is_gameover = FALSE;
  64.     /* init key's state */
  65.     g_gx_panda_context.up_key_pressed = FALSE;
  66.     g_gx_panda_context.down_key_pressed = FALSE;
  67.     gdi_layer_multi_layer_enable();
  68.     gdi_layer_get_base_handle(&g_gx_panda_context.background);
  69.     gdi_layer_create(0, 0, MMI_GX_PANDA_LCD_WIDTH, MMI_GX_PANDA_LCD_HEIGHT, &g_gx_panda_context.foreground);
  70.     gdi_layer_set_active(g_gx_panda_context.foreground);
  71.     gdi_layer_set_source_key(TRUE, GDI_COLOR_BLUE); /* set pure-blue as the transparent color in foreground */
  72.     gdi_layer_clear_background(GDI_COLOR_BLUE);     /* clean foreground layer */
  73.     // gdi_image_draw_id(50,50,IMG_GLOBAL_WARNING); /* only use for demo */
  74.     /* draw background image */
  75.     gdi_layer_set_active(g_gx_panda_context.background);
  76.     gdi_layer_set_clip(0, 0, MMI_GX_PANDA_LCD_WIDTH - 1, MMI_GX_PANDA_LCD_HEIGHT - 1);
  77.     gdi_image_draw_id(0, 0, IMG_ID_GX_PANDA_BACKGROUND);
  78. #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
  79.     GFX_OPEN_BACKGROUND_SOUND(BackGround_Panda_Midi, BACKGROUND_PANDA_MIDI, g_gx_panda_context.background_midi);
  80.     GFX_PLAY_BACKGROUND_SOUND(g_gx_panda_context.background_midi);
  81.     GFX_OPEN_DUMMY_BACKGROUND_SOUND();
  82.     GFX_PLAY_DUMMY_BACKGROUND_SOUND();
  83.     GFX_OPEN_SOUND_EFFECTS_MIDI(Up_Down_Midi, UPDOWN_MIDI, 1, g_gx_panda_context.updown_midi);
  84.     GFX_OPEN_SOUND_EFFECTS_MIDI(PandaBounce_Midi, PANDABOUNCE_MIDI, 1, g_gx_panda_context.bounce_midi);
  85.     GFX_OPEN_SOUND_EFFECTS_MIDI(PandaHit_Midi, PANDAHIT_MIDI, 1, g_gx_panda_context.hit_midi);
  86.     GFX_OPEN_MULTICHANNEL_WAV(PandaFall_wav, PANDAFALL_WAV, 1, g_gx_panda_context.fail_wav);
  87.     /* using hit wav for eating the clock */
  88.     GFX_OPEN_MULTICHANNEL_WAV(PandaEating_wav, PANDAEATING_WAV, 1, g_gx_panda_context.eating_wav);
  89.     GFX_OPEN_MULTICHANNEL_WAV(PandaDown_wav, PANDADOWN_WAV, 1, g_gx_panda_context.down_wav);
  90. #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  91.     SetKeyHandler(mmi_gx_panda_key_2_press, KEY_2, KEY_EVENT_DOWN);
  92.     SetKeyHandler(mmi_gx_panda_key_8_press, KEY_8, KEY_EVENT_DOWN);
  93.     SetKeyHandler(mmi_gx_panda_key_2_press, KEY_UP_ARROW, KEY_EVENT_DOWN);
  94.     SetKeyHandler(mmi_gx_panda_key_8_press, KEY_DOWN_ARROW, KEY_EVENT_DOWN);
  95.     SetKeyHandler(mmi_gx_panda_key_2_release, KEY_2, KEY_EVENT_UP);
  96.     SetKeyHandler(mmi_gx_panda_key_8_release, KEY_8, KEY_EVENT_UP);
  97.     SetKeyHandler(mmi_gx_panda_key_4_press, KEY_4, KEY_EVENT_DOWN);
  98.     SetKeyHandler(mmi_gx_panda_key_6_press, KEY_6, KEY_EVENT_DOWN);
  99.     SetKeyHandler(mmi_gx_panda_key_2_release, KEY_UP_ARROW, KEY_EVENT_UP);
  100.     SetKeyHandler(mmi_gx_panda_key_8_release, KEY_DOWN_ARROW, KEY_EVENT_UP);
  101.     SetKeyHandler(mmi_gx_panda_key_4_press, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  102.     SetKeyHandler(mmi_gx_panda_key_6_press, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  103.     SetKeyHandler(mmi_gx_panda_key_5_press, KEY_5, KEY_EVENT_DOWN);
  104.     SetKeyHandler(mmi_gx_panda_key_5_release, KEY_5, KEY_EVENT_UP);
  105.     mmi_gx_panda_draw_static_background();
  106.     /* set bgm resume handle */
  107.     /* SetProtocolEventHandler(mmi_gx_panda_resume_bgm, PRT_EQ_PLAY_AUDIO_FINISH_IND); */
  108.     /* start game loop */
  109.     mmi_gx_panda_cyclic_timer();
  110. //KP Jerry add on 2007-3-23 start
  111. #ifdef __MMI_TOUCH_SCREEN__
  112.     wgui_register_pen_down_handler(mmi_panda_pen_down_hdlr);
  113.     wgui_register_pen_up_handler(mmi_panda_pen_up_hdlr);
  114. #endif /* __MMI_TOUCH_SCREEN__ */ 
  115. //KP Jerry add on 2007-3-23 end
  116. }
  117. /*****************************************************************************
  118. * FUNCTION
  119. *  mmi_gx_panda_resume_bgm
  120. * DESCRIPTION
  121. *  resume bgm
  122. * PARAMETERS
  123. *  void
  124. * RETURNS
  125. *  void
  126. * GLOBALS AFFECTED
  127. *  NIL
  128. ****************************************************************************/
  129. //void  mmi_gx_panda_resume_bgm(void *info)
  130. //{
  131. //      if (g_gx_panda_context.up_key_pressed != FALSE || g_gx_panda_context.down_key_pressed != FALSE)
  132. //      {
  133. //              GFX_PLAY_AUDIO_DVI(PandaUp_down_dvi, PANDAUP_DOWN_DVI, DEVICE_AUDIO_PLAY_ONCE);
  134. //      }
  135. //}
  136. /*****************************************************************************
  137.  * FUNCTION
  138.  *  mmi_gx_panda_draw_static_background
  139.  * DESCRIPTION
  140.  *  Draw static background
  141.  * PARAMETERS
  142.  *  void
  143.  * RETURNS
  144.  *  void
  145.  *****************************************************************************/
  146. void mmi_gx_panda_draw_static_background(void)
  147. {
  148.     /*----------------------------------------------------------------*/
  149.     /* Local Variables                                                */
  150.     /*----------------------------------------------------------------*/
  151.     UI_string_type str_ptr;
  152.     /*----------------------------------------------------------------*/
  153.     /* Code Body                                                      */
  154.     /*----------------------------------------------------------------*/
  155.     str_ptr = (UI_string_type) GetString(STR_GAME_SCORE);
  156.     /* draw score */
  157. #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
  158.     gui_set_font(&MMI_small_font);
  159. #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
  160.     gui_set_font(&MMI_medium_font);
  161. //KP Jerry add on 2007-3-23 start
  162. #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
  163.     gui_set_font(&MMI_large_font);
  164. //KP Jerry add on 2007-3-23 end
  165. #endif 
  166.     gui_set_text_color(gui_color(255, 255, 255));
  167.     gui_set_text_border_color(gui_color(0, 0, 0));
  168.     g_gx_panda_context.score_str_width = (S16) gui_get_string_width(str_ptr);
  169.     if (r2lMMIFlag)
  170.     {
  171.     #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
  172.         gui_move_text_cursor(125, 3);
  173.     #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
  174.         gui_move_text_cursor(171, 3);
  175. //KP Jerry add on 2007-3-23 start
  176.     #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
  177.         gui_move_text_cursor(171, 3);
  178. //KP Jerry add on 2007-3-23 end
  179.     #endif 
  180.         gui_print_bordered_text(str_ptr);
  181.         /* draw clock */
  182.     #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
  183.         gdi_image_draw_id(32, 1, IMG_ID_GX_PANDA_CLOCK);
  184.     #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
  185.         gdi_image_draw_id(30, 1, IMG_ID_GX_PANDA_CLOCK);
  186. //KP Jerry add on 2007-3-23 start
  187.     #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
  188.         gdi_image_draw_id(30, 1, IMG_ID_GX_PANDA_CLOCK);
  189. //KP Jerry add on 2007-3-23 end
  190.     #endif 
  191.     }
  192.     else
  193.     {
  194.     #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
  195.         gui_move_text_cursor(3, 3);
  196.     #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
  197.         gui_move_text_cursor(5, 3);
  198. //KP Jerry add on 2007-3-23 start
  199.     #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
  200.         gui_move_text_cursor(5, 3);
  201. //KP Jerry add on 2007-3-23 end
  202.     #endif 
  203.         gui_print_bordered_text(str_ptr);
  204.         /* draw clock */
  205.     #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
  206.         gdi_image_draw_id(86, 1, IMG_ID_GX_PANDA_CLOCK);
  207.     #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
  208.         gdi_image_draw_id(118, 1, IMG_ID_GX_PANDA_CLOCK);
  209. //KP Jerry add on 2007-3-23 start
  210.     #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
  211.         gdi_image_draw_id(150, 1, IMG_ID_GX_PANDA_CLOCK);
  212. //KP Jerry add on 2007-3-23 end
  213.     #endif 
  214.     }
  215. }
  216. /*****************************************************************************
  217.  * FUNCTION
  218.  *  mmi_gx_panda_exit_game
  219.  * DESCRIPTION
  220.  *  Exit Game [Callback required by GFX]
  221.  * PARAMETERS
  222.  *  void
  223.  * RETURNS
  224.  *  void
  225.  *****************************************************************************/
  226. void mmi_gx_panda_exit_game(void)
  227. {
  228.     /*----------------------------------------------------------------*/
  229.     /* Local Variables                                                */
  230.     /*----------------------------------------------------------------*/
  231.     /*----------------------------------------------------------------*/
  232.     /* Code Body                                                      */
  233.     /*----------------------------------------------------------------*/
  234.     /* reset bgm resume handler */
  235.     /* SetProtocolEventHandler(NULL, PRT_EQ_PLAY_AUDIO_FINISH_IND); */
  236.     gui_cancel_timer(mmi_gx_panda_cyclic_timer);    /* cancle the looping timer */
  237. #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
  238.     GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
  239.     GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
  240.     GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
  241.     GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
  242.     GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
  243.     GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
  244.     GFX_CLOSE_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
  245.     GFX_CLOSE_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
  246.     GFX_CLOSE_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
  247.     GFX_CLOSE_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
  248.     GFX_CLOSE_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
  249.     GFX_CLOSE_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
  250.     GFX_STOP_DUMMY_BACKGROUND_SOUND();
  251.     GFX_CLOSE_DUMMY_BACKGROUND_SOUND();
  252.     GFX_STOP_BACKGROUND_SOUND(g_gx_panda_context.background_midi);
  253.     GFX_CLOSE_BACKGROUND_SOUND(g_gx_panda_context.background_midi);
  254. #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */ /* /__MMI_GAME_MULTICHANNEL_SOUND__ */
  255.     gdi_layer_free(g_gx_panda_context.foreground);
  256.     gdi_layer_multi_layer_disable();
  257. }
  258. /*****************************************************************************
  259.  * FUNCTION
  260.  *  mmi_gx_panda_init_enemy_list
  261.  * DESCRIPTION
  262.  *  init_enemy_list
  263.  * PARAMETERS
  264.  *  void
  265.  * RETURNS
  266.  *  void
  267.  *****************************************************************************/
  268. void mmi_gx_panda_init_enemy_list(void)
  269. {
  270.     /*----------------------------------------------------------------*/
  271.     /* Local Variables                                                */
  272.     /*----------------------------------------------------------------*/
  273.     gx_panda_pos_state_enum i;
  274.     U8 j;
  275.     /*----------------------------------------------------------------*/
  276.     /* Code Body                                                      */
  277.     /*----------------------------------------------------------------*/
  278.     for (i = LEFT_TREE_LEFT; i <= RIGHT_TREE_RIGHT; i++)
  279.     {
  280.         g_gx_panda_context.tree[i].first = &(g_gx_panda_context.tree[i].enemy[0]);
  281.         g_gx_panda_context.tree[i].last = &(g_gx_panda_context.tree[i].enemy[0]);
  282.         g_gx_panda_context.tree[i].empty = &(g_gx_panda_context.tree[i].enemy[1]);
  283.         g_gx_panda_context.tree[i].empty_last = &(g_gx_panda_context.tree[i].enemy[MMI_GX_PANDA_ENEMY_COUNT - 1]);
  284.         for (j = 0; j < MMI_GX_PANDA_ENEMY_COUNT; j++)
  285.         {
  286.             if (j == 0)
  287.             {
  288.                 g_gx_panda_context.tree[i].enemy[j].position_y =
  289.                     MMI_GX_PANDA_LCD_HEIGHT + MMI_GX_PANDA_ENEMY_HEIGHT * (rand() % RIGHT_TREE_RIGHT);
  290.                 g_gx_panda_context.tree[i].enemy[j].old_position_y = g_gx_panda_context.tree[i].enemy[j].position_y;
  291.                 g_gx_panda_context.tree[i].enemy[j].type = ENEMY_1 + (gx_panda_type_enum) (rand() % 3);
  292.             }
  293.             if (j != 0)
  294.             {
  295.                 g_gx_panda_context.tree[i].enemy[j].previous = &(g_gx_panda_context.tree[i].enemy[j - 1]);
  296.             }
  297.             if (j != MMI_GX_PANDA_ENEMY_COUNT - 1)
  298.             {
  299.                 g_gx_panda_context.tree[i].enemy[j].next = &(g_gx_panda_context.tree[i].enemy[j + 1]);
  300.             }
  301.             g_gx_panda_context.tree[i].enemy[j].is_dying = FALSE;
  302.         }
  303.     }
  304. }
  305. /*****************************************************************************
  306.  * FUNCTION
  307.  *  mmi_gx_panda_init_game
  308.  * DESCRIPTION
  309.  *  Game initilization
  310.  * PARAMETERS
  311.  *  void
  312.  * RETURNS
  313.  *  void
  314.  *****************************************************************************/
  315. void mmi_gx_panda_init_game(void)
  316. {
  317.     /*----------------------------------------------------------------*/
  318.     /* Local Variables                                                */
  319.     /*----------------------------------------------------------------*/
  320.     /*----------------------------------------------------------------*/
  321.     /* Code Body                                                      */
  322.     /*----------------------------------------------------------------*/
  323.     /* init game */
  324.     g_gx_panda_context.pos_state = MID_TREE_LEFT;
  325.     g_gx_panda_context.state = NORMAL;
  326.     g_gx_panda_context.position.y = 13;             /* initial role's y position */
  327.     g_gx_panda_context.pos_state = MID_TREE_LEFT;   /* on the LEFT of the MIDDLE PANDA */
  328.     g_gx_panda_context.state = NORMAL;              /* Not in ATTACK STATE */
  329.     g_gx_panda_context.old_state = NORMAL;          /* Not in ATTACK STATE */
  330.     g_gx_panda_context.old_pos_state = MID_TREE_LEFT;
  331.     g_gx_panda_context.tick = 0;                    /* tick initialization */
  332.     g_gx_panda_context.total_time = MMI_GX_PANDA_TOTAL_TIME;
  333.     g_gx_panda_context.up_key_pressed = FALSE;
  334.     g_gx_panda_context.down_key_pressed = FALSE;
  335.     g_gx_panda_context.position.x = mmi_gx_panda_get_x_position(g_gx_panda_context.pos_state, MMI_GX_PANDA_IS_ROLE);
  336.     g_gx_panda_context.old_position = g_gx_panda_context.position;
  337.     g_gx_panda_context.clock_falling = FALSE;
  338.     g_gx_panda_context.is_dying = FALSE;
  339.     g_gx_panda_context.game_grade = 0;
  340.     g_gx_panda_context.enemy_speed = MMI_GX_PANDA_ENEMY_SLOW_SPEED;
  341.     mmi_gx_panda_init_enemy_list();
  342. }
  343. /*****************************************************************************
  344.  * FUNCTION
  345.  *  mmi_gx_panda_framemove
  346.  * DESCRIPTION
  347.  *  Framemove - process the game logic
  348.  * PARAMETERS
  349.  *  void
  350.  * RETURNS
  351.  *  void
  352.  *****************************************************************************/
  353. void mmi_gx_panda_framemove(void)
  354. {
  355.     /*----------------------------------------------------------------*/
  356.     /* Local Variables                                                */
  357.     /*----------------------------------------------------------------*/
  358.     U8 moving_speed;    /* the moving speed of role */
  359.     U8 tree_number;
  360.     BOOL is_reach_button = FALSE;
  361.     gx_panda_node_struct *current_node;
  362.     gx_panda_node_struct *next_node;
  363.     /*----------------------------------------------------------------*/
  364.     /* Code Body                                                      */
  365.     /*----------------------------------------------------------------*/
  366.     /* determine the moving speed of the role */
  367.     if (g_gx_panda_context.state != ATTACK)
  368.     {
  369.         moving_speed = MMI_GX_PANDA_ROLE_SPEED;
  370.     }
  371.     else
  372.     {
  373.         moving_speed = MMI_GX_PANDA_ROLE_ATTACK_SPEED;
  374.     }
  375.     /* not dying */
  376.     if (g_gx_panda_context.is_dying != TRUE)
  377.     {
  378.         /* detect if role goes to the bottom */
  379.         if (g_gx_panda_context.down_key_pressed != FALSE)
  380.         {
  381.             g_gx_panda_context.position.y = g_gx_panda_context.position.y + moving_speed;
  382.             if (g_gx_panda_context.position.y >= MMI_GX_PANDA_LCD_HEIGHT - MMI_GX_PANDA_ROLE_HEIGHT - 1)
  383.             {
  384.                 if (g_gx_panda_context.state == ATTACK)
  385.                 {
  386.                     is_reach_button = TRUE;
  387.                 }
  388.                 g_gx_panda_context.position.y = MMI_GX_PANDA_LCD_HEIGHT - MMI_GX_PANDA_ROLE_HEIGHT - 1;
  389.             }
  390.         }
  391.         /* detect if role goes to the upmost */
  392.         if (g_gx_panda_context.up_key_pressed != FALSE)
  393.         {
  394.             g_gx_panda_context.position.y = g_gx_panda_context.position.y - MMI_GX_PANDA_ROLE_SPEED;
  395.             if (g_gx_panda_context.position.y < MMI_GX_PANDA_TOP_MARGIN)
  396.             {
  397.                 g_gx_panda_context.position.y = MMI_GX_PANDA_TOP_MARGIN + 1;
  398.             }
  399.         }
  400.     }
  401.     /* every one second (when total time < 3 minutes) and every 0.5 second (when total time > 3 minutes), new() a enemy */
  402.     if (((g_gx_panda_context.tick <= 1800 && g_gx_panda_context.tick % 10 == 0) ||
  403.          (g_gx_panda_context.tick > 1800 && g_gx_panda_context.tick % 5 == 0)) && g_gx_panda_context.tick != 0)
  404.     {
  405.         tree_number = rand() % MMI_GX_PANDA_SIDE_COUNT;
  406.         g_gx_panda_context.tree[tree_number].empty->position_y = MMI_GX_PANDA_LCD_HEIGHT + 1;
  407.         g_gx_panda_context.tree[tree_number].empty->type = ENEMY_1 + rand() % 3;
  408.         g_gx_panda_context.tree[tree_number].last = g_gx_panda_context.tree[tree_number].empty;
  409.         g_gx_panda_context.tree[tree_number].empty = g_gx_panda_context.tree[tree_number].empty->next;
  410.     }
  411.     /* check if the "clock" (for time extension) should appear after attacking 10 enemies */
  412.     if ((g_gx_panda_context.game_grade + 5) % 50 == 0)
  413.     {
  414.         g_gx_panda_context.clock_falling = TRUE;
  415.         g_gx_panda_context.clock_position_y = -MMI_GX_PANDA_CLOCK_HEIGHT - 10;
  416.         g_gx_panda_context.clock_old_position_y = -MMI_GX_PANDA_CLOCK_HEIGHT - 10;
  417.         /* determine which space between two pandas the clock should appear */
  418.         if (rand() % 2 != 0)
  419.         {
  420.             g_gx_panda_context.clock_pos_state = LEFT_SPACE;
  421.         }
  422.         else
  423.         {
  424.             g_gx_panda_context.clock_pos_state = RIGHT_SPACE;
  425.         }
  426.         g_gx_panda_context.clock_x_position =
  427.             (S16) mmi_gx_panda_get_x_position(g_gx_panda_context.clock_pos_state, MMI_GX_PANDA_IS_CLOCK);
  428.     }
  429.     /* dying, calc positon and do not need do collision detection */
  430.     if (g_gx_panda_context.is_dying == TRUE)
  431.     {
  432.         g_gx_panda_context.position.x = mmi_gx_panda_get_x_position(g_gx_panda_context.pos_state, MMI_GX_PANDA_IS_DYING_ROLE);
  433.         return;
  434.     }
  435.     /* collision detection */
  436.     if (g_gx_panda_context.state != FLYING && g_gx_panda_context.old_state != FLYING)
  437.     {
  438.         current_node = g_gx_panda_context.tree[g_gx_panda_context.pos_state].first;
  439.         while (current_node != g_gx_panda_context.tree[g_gx_panda_context.pos_state].empty)
  440.         {
  441.             next_node = current_node->next;
  442.             /* Of course, if the enemy is dying, then we don't have to check if the collision happens */
  443.             if (current_node->is_dying != TRUE)
  444.             {
  445.                 if ((current_node->position_y >= g_gx_panda_context.position.y &&
  446.                      current_node->position_y < g_gx_panda_context.position.y + MMI_GX_PANDA_ROLE_HEIGHT) ||
  447.                     (g_gx_panda_context.position.y >= current_node->position_y &&
  448.                      g_gx_panda_context.position.y < current_node->position_y + MMI_GX_PANDA_ENEMY_HEIGHT))
  449.                 {
  450.                     /* in attack mode */
  451.                     if (g_gx_panda_context.state == ATTACK && current_node->is_dying != TRUE)
  452.                     {
  453.                         current_node->is_dying = TRUE;
  454.                         /* increase score */
  455.                         g_gx_panda_context.game_grade = g_gx_panda_context.game_grade + MMI_GX_PANDA_SCORE_PER_ENEMY;
  456.                     #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
  457.                         GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
  458.                         GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
  459.                         GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
  460.                         GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
  461.                         GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
  462.                         GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
  463.                         GFX_PLAY_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
  464.                     #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  465.                         GFX_PLAY_AUDIO_DVI(PandaHit_dvi, PANDAHIT_DVI, DEVICE_AUDIO_PLAY_ONCE);
  466.                     #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  467.                         /* GFX_PLAY_VIBRATION(); */
  468.                     }
  469.                     /* in normal mode */
  470.                     else if (g_gx_panda_context.state == NORMAL)
  471.                     {
  472.                         g_gx_panda_context.is_dying = TRUE;
  473.                         /* determine which space will the dying role fall */
  474.                         g_gx_panda_context.position.x = mmi_gx_panda_get_x_position(g_gx_panda_context.pos_state, MMI_GX_PANDA_IS_DYING_ROLE);
  475.                     #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
  476.                         GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
  477.                         GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
  478.                         GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
  479.                         GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
  480.                         GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
  481.                         GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
  482.                         GFX_PLAY_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
  483.                     #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  484.                         GFX_PLAY_AUDIO_DVI(PandaFall_dvi, PANDAFALL_DVI, DEVICE_AUDIO_PLAY_ONCE);
  485.                     #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  486.                     }
  487.                 }
  488.             }
  489.             current_node = next_node;
  490.         }
  491.     }
  492.     if (is_reach_button == TRUE)
  493.     {
  494.         g_gx_panda_context.state = NORMAL;
  495.     }
  496. }
  497. /*****************************************************************************
  498.  * FUNCTION
  499.  *  mmi_gx_panda_render
  500.  * DESCRIPTION
  501.  *  Render the game images
  502.  * PARAMETERS
  503.  *  void
  504.  * RETURNS
  505.  *  void
  506.  *****************************************************************************/
  507. void mmi_gx_panda_render(void)
  508. {
  509.     /*----------------------------------------------------------------*/
  510.     /* Local Variables                                                */
  511.     /*----------------------------------------------------------------*/
  512.     MMI_ID_TYPE role_image;
  513.     S16 i;
  514.     S16 enemy_x_position;
  515.     S16 old_enemy_x_position;
  516.     gx_panda_node_struct *current_node;
  517.     gx_panda_node_struct *next_node;
  518.     gx_panda_node_struct *tmp_node;
  519.     /*----------------------------------------------------------------*/
  520.     /* Code Body                                                      */
  521.     /*----------------------------------------------------------------*/
  522.     gdi_layer_set_active(g_gx_panda_context.foreground);
  523.     gdi_layer_clear_background(MMI_GX_PANDA_TRANSPARENT_COLOR);
  524.     /* decrease time left for every second */
  525.     if (g_gx_panda_context.tick % 10 == 0)
  526.     {
  527.         g_gx_panda_context.total_time = g_gx_panda_context.total_time - 1;
  528.     }
  529.     /* time is up */
  530.     if (g_gx_panda_context.total_time == 0)
  531.     {
  532.         mmi_gx_panda_gameover();
  533.         if (g_gx_panda_context.is_gameover != FALSE)
  534.         {
  535.             return;
  536.         }
  537.     }
  538.     /* increase the speed of enemy for every 1.5 minutes */
  539.     if ((g_gx_panda_context.tick + 1) % 900 == 0)
  540.     {
  541.         g_gx_panda_context.enemy_speed = g_gx_panda_context.enemy_speed + 1;
  542.     }
  543.     /* erase all enemies */
  544.     for (i = LEFT_TREE_LEFT; i <= RIGHT_TREE_RIGHT; i++)
  545.     {
  546.         current_node = g_gx_panda_context.tree[i].first;
  547.         while (current_node != g_gx_panda_context.tree[i].empty)
  548.         {
  549.             /* determine enemy's position_x while not dying */
  550.             if (current_node->is_dying != TRUE)
  551.             {
  552.                 enemy_x_position = mmi_gx_panda_get_x_position(i, MMI_GX_PANDA_IS_ENEMY);
  553.             }
  554.             /* determine enemy's position_x while dying */
  555.             else
  556.             {
  557.                 enemy_x_position = mmi_gx_panda_get_x_position(i, MMI_GX_PANDA_IS_DYING_ENEMY);
  558.                 old_enemy_x_position = mmi_gx_panda_get_x_position(i, MMI_GX_PANDA_IS_ENEMY);
  559.             }
  560.             current_node = current_node->next;
  561.         }
  562.     }
  563.     /* display time left */
  564. #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
  565.     if (r2lMMIFlag)
  566.     {
  567.         mmi_gx_panda_draw_digits(26, 3, g_gx_panda_context.total_time);
  568.     }
  569.     else
  570.     {
  571.         mmi_gx_panda_draw_digits(102, 3, g_gx_panda_context.total_time);
  572.     }
  573. #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
  574.     if (r2lMMIFlag)
  575.     {
  576.         mmi_gx_panda_draw_digits(20, 3, g_gx_panda_context.total_time);
  577.     }
  578.     else
  579.     {
  580.         mmi_gx_panda_draw_digits(140, 3, g_gx_panda_context.total_time);
  581.     }
  582. //KP Jerry add on 2007-3-23 start
  583. #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
  584.     if (r2lMMIFlag)
  585.     {
  586.         mmi_gx_panda_draw_digits(20, 3, g_gx_panda_context.total_time);
  587.     }
  588.     else
  589.     {
  590.         mmi_gx_panda_draw_digits(195, 1, g_gx_panda_context.total_time);
  591.     }
  592. //KP Jerry add on 2007-3-23 end
  593. #endif 
  594.     /* display score */
  595. #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
  596.     if (r2lMMIFlag)
  597.     {
  598.         mmi_gx_panda_draw_digits((U16) (119 - g_gx_panda_context.score_str_width), 3, g_gx_panda_context.game_grade);
  599.     }
  600.     else
  601.     {
  602.         mmi_gx_panda_draw_digits((U16) (g_gx_panda_context.score_str_width + 9), 3, g_gx_panda_context.game_grade);
  603.     }
  604. #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
  605.     if (r2lMMIFlag)
  606.     {
  607.         mmi_gx_panda_draw_digits((U16) (167 - g_gx_panda_context.score_str_width), 3, g_gx_panda_context.game_grade);
  608.     }
  609.     else
  610.     {
  611.         mmi_gx_panda_draw_digits((U16) (g_gx_panda_context.score_str_width + 9), 3, g_gx_panda_context.game_grade);
  612.     }
  613. //KP Jerry add on 2007-3-23 start
  614. #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
  615.     if (r2lMMIFlag)
  616.     {
  617.         mmi_gx_panda_draw_digits((U16) (167 - g_gx_panda_context.score_str_width), 3, g_gx_panda_context.game_grade);
  618.     }
  619.     else
  620.     {
  621.         mmi_gx_panda_draw_digits((U16) (g_gx_panda_context.score_str_width + 9), 1, g_gx_panda_context.game_grade);
  622.     }
  623. //KP Jerry add on 2007-3-23 end
  624. #endif 
  625.     /* drawing clock */
  626.     if (g_gx_panda_context.clock_falling != FALSE)
  627.     {
  628.         g_gx_panda_context.clock_position_y = g_gx_panda_context.clock_position_y + MMI_GX_PANDA_CLOCK_SPEED;
  629.         /* draw new clock image */
  630.         gdi_image_draw_id(
  631.             g_gx_panda_context.clock_x_position,
  632.             g_gx_panda_context.clock_position_y,
  633.             IMG_ID_GX_PANDA_CLOCK);
  634.         g_gx_panda_context.clock_old_position_y = g_gx_panda_context.clock_position_y;
  635.         if (g_gx_panda_context.clock_position_y > MMI_GX_PANDA_LCD_HEIGHT)
  636.         {
  637.             g_gx_panda_context.clock_falling = FALSE;
  638.         }
  639.     }
  640.     /* draw enemies and update their position */
  641.     for (i = LEFT_TREE_LEFT; i <= RIGHT_TREE_RIGHT; i++)
  642.     {
  643.         current_node = g_gx_panda_context.tree[i].first;
  644.         while (current_node != g_gx_panda_context.tree[i].empty)
  645.         {
  646.             /* determine enemy's position_x while not dying */
  647.             if (current_node->is_dying != TRUE)
  648.             {
  649.                 enemy_x_position = mmi_gx_panda_get_x_position(i, MMI_GX_PANDA_IS_ENEMY);
  650.             }
  651.             /* determine enemy's position_x while dying */
  652.             else
  653.             {
  654.                 enemy_x_position = mmi_gx_panda_get_x_position(i, MMI_GX_PANDA_IS_DYING_ENEMY);
  655.                 old_enemy_x_position = mmi_gx_panda_get_x_position(i, MMI_GX_PANDA_IS_ENEMY);
  656.             }
  657.             /* left enemy case */
  658.             if (i % 2 == 0)
  659.             {
  660.                 gdi_image_draw_id(
  661.                     enemy_x_position,
  662.                     current_node->position_y,
  663.                     (U16) (IMG_ID_GX_PANDA_ENEMY_1_LEFT + current_node->type + (g_gx_panda_context.tick / 2 % 2) * 3));
  664.             }
  665.             /* right enemy case */
  666.             else
  667.             {
  668.                 gdi_image_draw_id(
  669.                     enemy_x_position,
  670.                     current_node->position_y,
  671.                     (U16) (IMG_ID_GX_PANDA_ENEMY_1_RIGHT + current_node->type + (g_gx_panda_context.tick / 2 % 2) * 3));
  672.             }
  673.             /* update information */
  674.             current_node->old_position_y = current_node->position_y;
  675.             if (current_node->is_dying != TRUE)
  676.             {
  677.                 current_node->position_y = current_node->position_y - g_gx_panda_context.enemy_speed;
  678.             }
  679.             else
  680.             {
  681.                 current_node->position_y = current_node->position_y + MMI_GX_PANDA_FALLING_SPEED;
  682.             }
  683.             next_node = current_node->next;
  684.             /* if the enemy is going out of the boundary, remove it from panda */
  685.             if (current_node->position_y + MMI_GX_PANDA_ENEMY_HEIGHT + 1 < 0 ||
  686.                 current_node->position_y > MMI_GX_PANDA_LCD_HEIGHT)
  687.             {
  688.                 /* normal case */
  689.                 if (current_node->is_dying != TRUE)
  690.                 {
  691.                     /* remove the first enemy in the list and append to the last position of the list */
  692.                     g_gx_panda_context.tree[i].empty_last->next = g_gx_panda_context.tree[i].first;
  693.                     g_gx_panda_context.tree[i].first->previous = g_gx_panda_context.tree[i].empty_last;
  694.                     g_gx_panda_context.tree[i].empty_last = g_gx_panda_context.tree[i].first;
  695.                     g_gx_panda_context.tree[i].first = current_node->next;
  696.                 }
  697.                 /* enemy dying case */
  698.                 else
  699.                 {
  700.                     /* if the dying enemy is the first enemy on the panda */
  701.                     if (current_node == g_gx_panda_context.tree[i].first)
  702.                     {
  703.                         g_gx_panda_context.tree[i].empty_last->next = g_gx_panda_context.tree[i].first;
  704.                         g_gx_panda_context.tree[i].first->previous = g_gx_panda_context.tree[i].empty_last;
  705.                         g_gx_panda_context.tree[i].empty_last = g_gx_panda_context.tree[i].first;
  706.                         g_gx_panda_context.tree[i].first = current_node->next;
  707.                     }
  708.                     else
  709.                     {
  710.                         tmp_node = current_node->previous;
  711.                         tmp_node->next = current_node->next;
  712.                         current_node->next->previous = tmp_node;
  713.                         g_gx_panda_context.tree[i].empty_last->next = current_node;
  714.                         current_node->previous = g_gx_panda_context.tree[i].empty_last;
  715.                         g_gx_panda_context.tree[i].empty_last = current_node;
  716.                     }
  717.                     /* because it became empty, need to restore the state */
  718.                     current_node->is_dying = FALSE;
  719.                 }
  720.             }
  721.             current_node = next_node;
  722.         }
  723.     }
  724.     /* while the role is alive */
  725.     if (g_gx_panda_context.is_dying != TRUE)
  726.     {
  727.         /* determine the role image */
  728.         /* while key pressing, the role is moving as a result we need to draw animation */
  729.         if (g_gx_panda_context.up_key_pressed != FALSE || g_gx_panda_context.down_key_pressed != FALSE)
  730.         {
  731.             switch (g_gx_panda_context.pos_state)
  732.             {
  733.                     /* all LEFT cases */
  734.                 case LEFT_TREE_LEFT:
  735.                 case MID_TREE_LEFT:
  736.                 case RIGHT_TREE_LEFT:
  737.                     if (g_gx_panda_context.state == ATTACK)
  738.                     {
  739.                         role_image = IMG_ID_GX_PANDA_ROLE_ATTACK_L_FRAME_0 + (g_gx_panda_context.tick % 2);
  740.                     }
  741.                     else
  742.                     {
  743.                         role_image = IMG_ID_GX_PANDA_ROLE_LEFT_FRAME_0 + (g_gx_panda_context.tick % 2);
  744.                     }
  745.                     break;
  746.                     /* all RIGHT cases */
  747.                 case LEFT_TREE_RIGHT:
  748.                 case MID_TREE_RIGHT:
  749.                 case RIGHT_TREE_RIGHT:
  750.                     if (g_gx_panda_context.state == ATTACK)
  751.                     {
  752.                         role_image = IMG_ID_GX_PANDA_ROLE_ATTACK_R_FRAME_0 + (g_gx_panda_context.tick % 2);
  753.                     }
  754.                     else
  755.                     {
  756.                         role_image = IMG_ID_GX_PANDA_ROLE_RIGHT_FRAME_0 + (g_gx_panda_context.tick % 2);
  757.                     }
  758.                     break;
  759.             }
  760.         }
  761.         /* while key not pressing, the role is still */
  762.         else if (g_gx_panda_context.up_key_pressed != TRUE && g_gx_panda_context.down_key_pressed != TRUE)
  763.         {
  764.             switch (g_gx_panda_context.pos_state)
  765.             {
  766.                     /* all LEFT cases */
  767.                 case LEFT_TREE_LEFT:
  768.                 case MID_TREE_LEFT:
  769.                 case RIGHT_TREE_LEFT:
  770.                     role_image = IMG_ID_GX_PANDA_ROLE_LEFT_FRAME_0;
  771.                     break;
  772.                     /* all RIGHT cases */
  773.                 case LEFT_TREE_RIGHT:
  774.                 case MID_TREE_RIGHT:
  775.                 case RIGHT_TREE_RIGHT:
  776.                     role_image = IMG_ID_GX_PANDA_ROLE_RIGHT_FRAME_0;
  777.                     break;
  778.             }
  779.         }
  780.         /* while the role is flying */
  781.         if (g_gx_panda_context.state == FLYING)
  782.         {
  783.             role_image = IMG_ID_GX_PANDA_ROLE_JUMP;
  784.             /* check if the role get the clock */
  785.             if (g_gx_panda_context.clock_falling != FALSE)
  786.             {
  787.                 /* the role from left_tree to mid_tree or from mid_tree to left_tree */
  788.                 /* or the role from right_tree to mid_tree or from mid_tree to right_tree */
  789.                 if ((g_gx_panda_context.clock_pos_state == LEFT_SPACE &&
  790.                      ((g_gx_panda_context.old_pos_state == LEFT_TREE_RIGHT &&
  791.                        g_gx_panda_context.pos_state == MID_TREE_LEFT) ||
  792.                       (g_gx_panda_context.pos_state == LEFT_TREE_RIGHT &&
  793.                        g_gx_panda_context.old_pos_state == MID_TREE_LEFT))) ||
  794.                     (g_gx_panda_context.clock_pos_state == RIGHT_SPACE &&
  795.                      ((g_gx_panda_context.old_pos_state == RIGHT_TREE_LEFT &&
  796.                        g_gx_panda_context.pos_state == MID_TREE_RIGHT) ||
  797.                       (g_gx_panda_context.pos_state == RIGHT_TREE_LEFT &&
  798.                        g_gx_panda_context.old_pos_state == MID_TREE_RIGHT))))
  799.                 {
  800.                     /* the role does touch the clock */
  801.                     if ((g_gx_panda_context.position.y >= g_gx_panda_context.clock_position_y &&
  802.                          g_gx_panda_context.position.y <
  803.                          g_gx_panda_context.clock_position_y + MMI_GX_PANDA_CLOCK_HEIGHT) ||
  804.                         (g_gx_panda_context.clock_position_y >= g_gx_panda_context.position.y &&
  805.                          g_gx_panda_context.clock_position_y <
  806.                          g_gx_panda_context.position.y + MMI_GX_PANDA_ROLE_HEIGHT))
  807.                     {
  808.                         /* extend 20 seconds */
  809.                         g_gx_panda_context.total_time = g_gx_panda_context.total_time + MMI_GX_PANDA_TIME_EXTENSION;
  810.                         g_gx_panda_context.clock_falling = FALSE;
  811.                     #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
  812.                         GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
  813.                         GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
  814.                         GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
  815.                         GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
  816.                         GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
  817.                         GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
  818.                         GFX_PLAY_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
  819.                     #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  820.                         GFX_PLAY_AUDIO_DVI(PandaEat_dvi, PANDAEAT_DVI, DEVICE_AUDIO_PLAY_ONCE);
  821.                     #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  822.                     }
  823.                 }
  824.                 if (g_gx_panda_context.total_time > 99)
  825.                 {
  826.                     g_gx_panda_context.total_time = 99;
  827.                 }
  828.             }
  829.         }
  830.     }
  831.     /* while the role is dying */
  832.     else
  833.     {
  834.         role_image = IMG_ID_GX_PANDA_ROLE_FALL_FRAME_0 + (g_gx_panda_context.tick % 2);
  835.     }
  836.     g_gx_panda_context.old_position = g_gx_panda_context.position;
  837.     g_gx_panda_context.old_pos_state = g_gx_panda_context.pos_state;
  838.     if (g_gx_panda_context.old_state == FLYING)
  839.     {
  840.         g_gx_panda_context.old_state = NORMAL;
  841.     }
  842.     /* Last, draw the role image because it should be on top of the layer to show correct display order */
  843.     gdi_image_draw_id(g_gx_panda_context.position.x, g_gx_panda_context.position.y, role_image);
  844.     /* set the flying role's position to the landing position */
  845.     if (g_gx_panda_context.state == FLYING)
  846.     {
  847.         g_gx_panda_context.state = NORMAL;
  848.         g_gx_panda_context.old_state = FLYING;
  849.         g_gx_panda_context.position.x = mmi_gx_panda_get_x_position(g_gx_panda_context.pos_state, MMI_GX_PANDA_IS_ROLE);
  850.     }
  851.     /* if the role is dying */
  852.     if (g_gx_panda_context.is_dying != FALSE)
  853.     {
  854.         g_gx_panda_context.position.y = g_gx_panda_context.position.y + MMI_GX_PANDA_FALLING_SPEED;
  855.         if (g_gx_panda_context.position.y > MMI_GX_PANDA_LCD_HEIGHT)
  856.         {
  857.             mmi_gx_panda_gameover();
  858.             gdi_layer_set_active(g_gx_panda_context.background);
  859.             return;
  860.         }
  861.     }
  862.     gdi_layer_blt(
  863.         g_gx_panda_context.background,  /* layer 0 */
  864.         g_gx_panda_context.foreground,  /* layer 1 */
  865.         0,                              /* layer 2 */
  866.         0,                              /* layer 3 */
  867.         0,                              /* offset x */
  868.         0,                              /* offset y */
  869.         UI_device_width - 1,            /* widht */
  870.         UI_device_height - 1);          /* height */
  871.     gdi_layer_set_active(g_gx_panda_context.background);
  872. }
  873. /*****************************************************************************
  874.  * FUNCTION
  875.  *  mmi_gx_panda_draw_digits
  876.  * DESCRIPTION
  877.  *  Drawing digits
  878.  * PARAMETERS
  879.  *  x           [IN]        X position for images
  880.  *  y           [IN]        Y position for images
  881.  *  number      [IN]        The number to be displayed
  882.  * RETURNS
  883.  *  void
  884.  *****************************************************************************/
  885. void mmi_gx_panda_draw_digits(U16 x, U16 y, U16 number)
  886. {
  887.     /*----------------------------------------------------------------*/
  888.     /* Local Variables                                                */
  889.     /*----------------------------------------------------------------*/
  890.     S8 buf[20];
  891.     S8 buf_USC2[40];
  892.     S32 str_width;
  893.     S32 str_height;
  894.     /*----------------------------------------------------------------*/
  895.     /* Code Body                                                      */
  896.     /*----------------------------------------------------------------*/
  897. #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
  898.     gui_set_font(&MMI_small_font);
  899. #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
  900.     gui_set_font(&MMI_medium_font);
  901. //KP Jerry add on 2007-3-23 start
  902. #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
  903.     gui_set_font(&MMI_large_font);
  904. //KP Jerry add on 2007-3-23 end
  905. #endif 
  906.     gui_set_text_color(gui_color(255, 255, 255));
  907.     gui_set_text_border_color(gui_color(0, 0, 0));
  908.     sprintf(buf, "%d", number);
  909.     AnsiiToUnicodeString(buf_USC2, buf);
  910.     gui_measure_string((UI_string_type) buf_USC2, &str_width, &str_height);
  911.     gui_move_text_cursor(x, y);
  912.     gui_print_bordered_text((UI_string_type) buf_USC2);
  913. }
  914. /*****************************************************************************
  915.  * FUNCTION
  916.  *  mmi_gx_panda_turn_or_fly
  917.  * DESCRIPTION
  918.  *  React to turn left or turn right action
  919.  * PARAMETERS
  920.  *  action      [IN]        Indicate the input is left-pressing or right-pressing
  921.  * RETURNS
  922.  *  void
  923.  *****************************************************************************/
  924. void mmi_gx_panda_turn_or_fly(U8 action)
  925. {
  926.     /*----------------------------------------------------------------*/
  927.     /* Local Variables                                                */
  928.     /*----------------------------------------------------------------*/
  929.     /*----------------------------------------------------------------*/
  930.     /* Code Body                                                      */
  931.     /*----------------------------------------------------------------*/
  932.     /* if the role is dying, we don't need to process the key press */
  933.     if (g_gx_panda_context.is_dying != FALSE)
  934.     {
  935.         return;
  936.     }
  937.     g_gx_panda_context.old_pos_state = g_gx_panda_context.pos_state;
  938.     if (action == MMI_GX_PANDA_GO_LEFT)
  939.     {
  940.         /* it's not in the leftmost position thus there is action happen */
  941.         if (g_gx_panda_context.pos_state != LEFT_TREE_LEFT)
  942.         {
  943.             g_gx_panda_context.pos_state = g_gx_panda_context.pos_state - 1;
  944.             if ((g_gx_panda_context.pos_state - LEFT_TREE_LEFT) % 2 == 1)
  945.             {
  946.                 g_gx_panda_context.state = FLYING;
  947.             }
  948.         }
  949.     }
  950.     else if (action == MMI_GX_PANDA_GO_RIGHT)
  951.     {
  952.         /* it's not in the rightmost position thus there is action happen */
  953.         if (g_gx_panda_context.pos_state != RIGHT_TREE_RIGHT)
  954.         {
  955.             g_gx_panda_context.pos_state = g_gx_panda_context.pos_state + 1;
  956.             if ((g_gx_panda_context.pos_state - LEFT_TREE_LEFT) % 2 == 0)
  957.             {
  958.                 g_gx_panda_context.state = FLYING;
  959.             }
  960.         }
  961.     }
  962.     g_gx_panda_context.position.x = mmi_gx_panda_get_x_position(g_gx_panda_context.pos_state, MMI_GX_PANDA_IS_ROLE);
  963.     /* adjust the X-position in FLYING state */
  964.     if (g_gx_panda_context.state == FLYING)
  965.     {
  966.         g_gx_panda_context.position.x =
  967.             (g_gx_panda_context.position.x +
  968.              mmi_gx_panda_get_x_position(g_gx_panda_context.old_pos_state, MMI_GX_PANDA_IS_ROLE)) / 2;
  969.     #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
  970.         GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
  971.         GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
  972.         GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
  973.         GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
  974.         GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
  975.         GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
  976.         GFX_PLAY_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
  977.     #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  978.         GFX_PLAY_AUDIO_DVI(PandaBounce_dvi, PANDABOUNCE_DVI, DEVICE_AUDIO_PLAY_ONCE);
  979.     #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  980.     }
  981. }
  982. /*****************************************************************************
  983.  * FUNCTION
  984.  *  mmi_gx_panda_gameover
  985.  * DESCRIPTION
  986.  *  Gameover function
  987.  * PARAMETERS
  988.  *  void
  989.  * RETURNS
  990.  *  void
  991.  *****************************************************************************/
  992. void mmi_gx_panda_gameover(void)
  993. {
  994.     /*----------------------------------------------------------------*/
  995.     /* Local Variables                                                */
  996.     /*----------------------------------------------------------------*/
  997.     /*----------------------------------------------------------------*/
  998.     /* Code Body                                                      */
  999.     /*----------------------------------------------------------------*/
  1000.     g_gx_panda_context.is_gameover = TRUE;
  1001.     g_gx_panda_context.is_new_game = TRUE;
  1002.     /* call this function to draw gameover screen */
  1003.     mmi_gfx_entry_gameover_screen();
  1004. }
  1005. /*****************************************************************************
  1006.  * FUNCTION
  1007.  *  mmi_gx_panda_cyclic_timer
  1008.  * DESCRIPTION
  1009.  *  Timer trigger function - looping
  1010.  * PARAMETERS
  1011.  *  void
  1012.  * RETURNS
  1013.  *  void
  1014.  *****************************************************************************/
  1015. void mmi_gx_panda_cyclic_timer(void)
  1016. {
  1017.     /*----------------------------------------------------------------*/
  1018.     /* Local Variables                                                */
  1019.     /*----------------------------------------------------------------*/
  1020.     /*----------------------------------------------------------------*/
  1021.     /* Code Body                                                      */
  1022.     /*----------------------------------------------------------------*/
  1023.     g_gx_panda_context.tick = g_gx_panda_context.tick + 1;
  1024.     gui_start_timer(g_gx_panda_context.timer_elapse, mmi_gx_panda_cyclic_timer);
  1025.     if (g_gx_panda_context.is_gameover == FALSE)
  1026.     {
  1027.         mmi_gx_panda_framemove();
  1028.         mmi_gx_panda_render();
  1029.     }
  1030. }
  1031. /*****************************************************************************
  1032.  * FUNCTION
  1033.  *  mmi_gx_panda_key_2_press
  1034.  * DESCRIPTION
  1035.  *  Key handling
  1036.  * PARAMETERS
  1037.  *  void
  1038.  * RETURNS
  1039.  *  void
  1040.  *****************************************************************************/
  1041. void mmi_gx_panda_key_2_press(void)
  1042. {
  1043.     /*----------------------------------------------------------------*/
  1044.     /* Local Variables                                                */
  1045.     /*----------------------------------------------------------------*/
  1046.     /*----------------------------------------------------------------*/
  1047.     /* Code Body                                                      */
  1048.     /*----------------------------------------------------------------*/
  1049.     /* if the role is dying, we don't need to process the key press */
  1050.     if (g_gx_panda_context.is_dying != FALSE)
  1051.     {
  1052.         return;
  1053.     }
  1054.     g_gx_panda_context.up_key_pressed = TRUE;
  1055. #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
  1056.     GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
  1057.     GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
  1058.     GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
  1059.     GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
  1060.     GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
  1061.     GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
  1062.     GFX_PLAY_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
  1063. #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  1064.     GFX_PLAY_AUDIO_DVI(PandaUp_down_dvi, PANDAUP_DOWN_DVI, DEVICE_AUDIO_PLAY_ONCE);
  1065. #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  1066. }
  1067. /*****************************************************************************
  1068.  * FUNCTION
  1069.  *  mmi_gx_panda_key_8_press
  1070.  * DESCRIPTION
  1071.  *  Key handling
  1072.  * PARAMETERS
  1073.  *  void
  1074.  * RETURNS
  1075.  *  void
  1076.  *****************************************************************************/
  1077. void mmi_gx_panda_key_8_press(void)
  1078. {
  1079.     /*----------------------------------------------------------------*/
  1080.     /* Local Variables                                                */
  1081.     /*----------------------------------------------------------------*/
  1082.     /*----------------------------------------------------------------*/
  1083.     /* Code Body                                                      */
  1084.     /*----------------------------------------------------------------*/
  1085.     /* if the role is dying, we don't need to process the key press */
  1086.     if (g_gx_panda_context.is_dying != FALSE)
  1087.     {
  1088.         return;
  1089.     }
  1090.     g_gx_panda_context.down_key_pressed = TRUE;
  1091. #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
  1092.     GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
  1093.     GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
  1094.     GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
  1095.     GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
  1096.     GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
  1097.     GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
  1098.     GFX_PLAY_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
  1099. #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  1100.     GFX_PLAY_AUDIO_DVI(PandaUp_down_dvi, PANDAUP_DOWN_DVI, DEVICE_AUDIO_PLAY_ONCE);
  1101. #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  1102. }
  1103. /*****************************************************************************
  1104.  * FUNCTION
  1105.  *  mmi_gx_panda_key_5_press
  1106.  * DESCRIPTION
  1107.  *  Key handling
  1108.  * PARAMETERS
  1109.  *  void
  1110.  * RETURNS
  1111.  *  void
  1112.  *****************************************************************************/
  1113. void mmi_gx_panda_key_5_press(void)
  1114. {
  1115.     /*----------------------------------------------------------------*/
  1116.     /* Local Variables                                                */
  1117.     /*----------------------------------------------------------------*/
  1118.     /*----------------------------------------------------------------*/
  1119.     /* Code Body                                                      */
  1120.     /*----------------------------------------------------------------*/
  1121.     /* if the role is dying or flying, we don't need to process the key press */
  1122.     if (g_gx_panda_context.is_dying != FALSE || g_gx_panda_context.state == FLYING)
  1123.     {
  1124.         return;
  1125.     }
  1126.     /* if at the button, cant go down anymore */
  1127.     if (g_gx_panda_context.position.y == MMI_GX_PANDA_LCD_HEIGHT - MMI_GX_PANDA_ROLE_HEIGHT - 1)
  1128.     {
  1129.         return;
  1130.     }
  1131.     g_gx_panda_context.state = ATTACK;
  1132.     g_gx_panda_context.down_key_pressed = TRUE;
  1133. #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
  1134.     GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
  1135.     GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
  1136.     GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
  1137.     GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
  1138.     GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
  1139.     GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
  1140.     GFX_PLAY_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
  1141. #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  1142.     GFX_PLAY_AUDIO_DVI(PandaDown_dvi, PANDADOWN_DVI, DEVICE_AUDIO_PLAY_ONCE);
  1143. #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */ 
  1144. }
  1145. /*****************************************************************************
  1146.  * FUNCTION
  1147.  *  mmi_gx_panda_key_2_release
  1148.  * DESCRIPTION
  1149.  *  Key handling
  1150.  * PARAMETERS
  1151.  *  void
  1152.  * RETURNS
  1153.  *  void
  1154.  *****************************************************************************/
  1155. void mmi_gx_panda_key_2_release(void)
  1156. {
  1157.     /*----------------------------------------------------------------*/
  1158.     /* Local Variables                                                */
  1159.     /*----------------------------------------------------------------*/
  1160.     /*----------------------------------------------------------------*/
  1161.     /* Code Body                                                      */
  1162.     /*----------------------------------------------------------------*/
  1163.     g_gx_panda_context.up_key_pressed = FALSE;
  1164. }
  1165. /*****************************************************************************
  1166.  * FUNCTION
  1167.  *  mmi_gx_panda_key_8_release
  1168.  * DESCRIPTION
  1169.  *  Key handling
  1170.  * PARAMETERS
  1171.  *  void
  1172.  * RETURNS
  1173.  *  void
  1174.  *****************************************************************************/
  1175. void mmi_gx_panda_key_8_release(void)
  1176. {
  1177.     /*----------------------------------------------------------------*/
  1178.     /* Local Variables                                                */
  1179.     /*----------------------------------------------------------------*/
  1180.     /*----------------------------------------------------------------*/
  1181.     /* Code Body                                                      */
  1182.     /*----------------------------------------------------------------*/
  1183.     g_gx_panda_context.down_key_pressed = FALSE;
  1184. }
  1185. /*****************************************************************************
  1186.  * FUNCTION
  1187.  *  mmi_gx_panda_key_5_release
  1188.  * DESCRIPTION
  1189.  *  Key handling
  1190.  * PARAMETERS
  1191.  *  void
  1192.  * RETURNS
  1193.  *  void
  1194.  *****************************************************************************/
  1195. void mmi_gx_panda_key_5_release(void)
  1196. {
  1197.     /*----------------------------------------------------------------*/
  1198.     /* Local Variables                                                */
  1199.     /*----------------------------------------------------------------*/
  1200.     /*----------------------------------------------------------------*/
  1201.     /* Code Body                                                      */
  1202.     /*----------------------------------------------------------------*/
  1203.     g_gx_panda_context.down_key_pressed = FALSE;
  1204.     g_gx_panda_context.state = NORMAL;
  1205. }
  1206. /*****************************************************************************
  1207.  * FUNCTION
  1208.  *  mmi_gx_panda_key_4_press
  1209.  * DESCRIPTION
  1210.  *  Key handling
  1211.  * PARAMETERS
  1212.  *  void
  1213.  * RETURNS
  1214.  *  void
  1215.  *****************************************************************************/
  1216. void mmi_gx_panda_key_4_press(void)
  1217. {
  1218.     /*----------------------------------------------------------------*/
  1219.     /* Local Variables                                                */
  1220.     /*----------------------------------------------------------------*/
  1221.     /*----------------------------------------------------------------*/
  1222.     /* Code Body                                                      */
  1223.     /*----------------------------------------------------------------*/
  1224.     mmi_gx_panda_turn_or_fly(MMI_GX_PANDA_GO_LEFT);
  1225. }
  1226. /*****************************************************************************
  1227.  * FUNCTION
  1228.  *  mmi_gx_panda_key_6_press
  1229.  * DESCRIPTION
  1230.  *  Key handling
  1231.  * PARAMETERS
  1232.  *  void
  1233.  * RETURNS
  1234.  *  void
  1235.  *****************************************************************************/
  1236. void mmi_gx_panda_key_6_press(void)
  1237. {
  1238.     /*----------------------------------------------------------------*/
  1239.     /* Local Variables                                                */
  1240.     /*----------------------------------------------------------------*/
  1241.     /*----------------------------------------------------------------*/
  1242.     /* Code Body                                                      */
  1243.     /*----------------------------------------------------------------*/
  1244.     mmi_gx_panda_turn_or_fly(MMI_GX_PANDA_GO_RIGHT);
  1245. }
  1246. /*****************************************************************************
  1247.  * FUNCTION
  1248.  *  mmi_gx_panda_get_x_position
  1249.  * DESCRIPTION
  1250.  *  Calculate the x position of objects from its position-state
  1251.  * PARAMETERS
  1252.  *  state       [IN]        Current position-state of object.
  1253.  *  type        [IN]        Type of object
  1254.  * RETURNS
  1255.  *  The position in X-direction
  1256.  *****************************************************************************/
  1257. S16 mmi_gx_panda_get_x_position(gx_panda_pos_state_enum state, U8 type)
  1258. {
  1259.     /*----------------------------------------------------------------*/
  1260.     /* Local Variables                                                */
  1261.     /*----------------------------------------------------------------*/
  1262.     S16 offset;
  1263.     S16 object_width;
  1264.     S16 result;
  1265.     /*----------------------------------------------------------------*/
  1266.     /* Code Body                                                      */
  1267.     /*----------------------------------------------------------------*/
  1268.     if (type == MMI_GX_PANDA_IS_ROLE || type == MMI_GX_PANDA_IS_DYING_ROLE)
  1269.     {
  1270.     #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
  1271.         offset = 8;
  1272.     #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
  1273.         offset = 11;
  1274. //KP Jerry add on 2007-3-23 start
  1275.     #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
  1276.         offset = 16;
  1277. //KP Jerry add on 2007-3-23 end
  1278.     #endif 
  1279.         object_width = MMI_GX_PANDA_ROLE_WIDTH;
  1280.     }
  1281.     else if (type == MMI_GX_PANDA_IS_ENEMY || type == MMI_GX_PANDA_IS_DYING_ENEMY)
  1282.     {
  1283.         offset = 2;
  1284.         object_width = MMI_GX_PANDA_ENEMY_WIDTH;
  1285.     }
  1286.     else if (type == MMI_GX_PANDA_IS_CLOCK)
  1287.     {
  1288.         switch (state)
  1289.         {
  1290.             case LEFT_SPACE:
  1291.         #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
  1292.                 return 38;
  1293.         #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
  1294.                 return 54;
  1295. //KP Jerry add on 2007-3-23 start
  1296.         #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
  1297.                 return 75;
  1298. //KP Jerry add on 2007-3-23 end
  1299.         #endif 
  1300.                 break;
  1301.             case RIGHT_SPACE:
  1302.         #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
  1303.                 return 78;
  1304.         #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
  1305.                 return 109;
  1306. //KP Jerry add on 2007-3-23 start
  1307.         #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
  1308.                 return 155;
  1309. //KP Jerry add on 2007-3-23 end
  1310.         #endif 
  1311.                 break;
  1312.         }
  1313.     }
  1314.     switch (state)
  1315.     {
  1316.         case LEFT_TREE_LEFT:
  1317.             result = MMI_GX_PANDA_LEFT_PANDA - (object_width - offset);
  1318.             if (type == MMI_GX_PANDA_IS_DYING_ROLE)
  1319.             {
  1320.                 result = result - 15;
  1321.             }
  1322.             else if (type == MMI_GX_PANDA_IS_DYING_ENEMY)
  1323.             {
  1324.                 result = result - 5;
  1325.             }
  1326.             break;
  1327.         case LEFT_TREE_RIGHT:
  1328.             result = MMI_GX_PANDA_LEFT_PANDA + MMI_GX_PANDA_PANDA_WIDTH - offset;
  1329.             if (type == MMI_GX_PANDA_IS_DYING_ROLE)
  1330.             {
  1331.                 result = result + 15;
  1332.             }
  1333.             else if (type == MMI_GX_PANDA_IS_DYING_ENEMY)
  1334.             {
  1335.                 result = result + 5;
  1336.             }
  1337.             break;
  1338.         case MID_TREE_LEFT:
  1339.             result = MMI_GX_PANDA_MID_PANDA - (object_width - offset);
  1340.             if (type == MMI_GX_PANDA_IS_DYING_ROLE)
  1341.             {
  1342.                 result = result - 15;
  1343.             }
  1344.             else if (type == MMI_GX_PANDA_IS_DYING_ENEMY)
  1345.             {
  1346.                 result = result - 5;
  1347.             }
  1348.             break;
  1349.         case MID_TREE_RIGHT:
  1350.             result = MMI_GX_PANDA_MID_PANDA + MMI_GX_PANDA_PANDA_WIDTH - offset;
  1351.             if (type == MMI_GX_PANDA_IS_DYING_ROLE)
  1352.             {
  1353.                 result = result + 15;
  1354.             }
  1355.             else if (type == MMI_GX_PANDA_IS_DYING_ENEMY)
  1356.             {
  1357.                 result = result + 5;
  1358.             }
  1359.             break;
  1360.         case RIGHT_TREE_LEFT:
  1361.             result = MMI_GX_PANDA_RIGHT_PANDA - (object_width - offset);
  1362.             if (type == MMI_GX_PANDA_IS_DYING_ROLE)
  1363.             {
  1364.                 result = result - 15;
  1365.             }
  1366.             else if (type == MMI_GX_PANDA_IS_DYING_ENEMY)
  1367.             {
  1368.                 result = result - 5;
  1369.             }
  1370.             break;
  1371.         case RIGHT_TREE_RIGHT:
  1372.             result = MMI_GX_PANDA_RIGHT_PANDA + MMI_GX_PANDA_PANDA_WIDTH - offset;
  1373.             if (type == MMI_GX_PANDA_IS_DYING_ROLE)
  1374.             {
  1375.                 result = result + 15;
  1376.             }
  1377.             else if (type == MMI_GX_PANDA_IS_DYING_ENEMY)
  1378.             {
  1379.                 result = result + 5;
  1380.             }
  1381.             break;
  1382.     }
  1383.     return result;
  1384. }
  1385. //KP Jerry add on 2007-3-23 start
  1386. #ifdef __MMI_TOUCH_SCREEN__
  1387. typedef enum
  1388. {
  1389. PANDA_MOVE_NONE,
  1390. PANDA_MOVE_UP,
  1391. PANDA_MOVE_DOWN,
  1392. PANDA_MOVE_LEFT,
  1393. PANDA_MOVE_RIGHT,
  1394. PANDA_MOVE_KILLENEMY
  1395. }PANDA_MOVEMENT;
  1396. static PANDA_MOVEMENT PandaState = PANDA_MOVE_NONE;
  1397. /*****************************************************************************
  1398.  * FUNCTION
  1399.  *  mmi_panda_is_panda_moveable
  1400.  * DESCRIPTION
  1401.  *  get the panda move state
  1402.  * PARAMETERS
  1403.  *  pos     [IN]        
  1404.  * RETURNS
  1405.  *  void
  1406.  *****************************************************************************/
  1407. PANDA_MOVEMENT mmi_panda_is_panda_moveable(S32 coord_x, S32 coord_y)
  1408. {
  1409. if(coord_x >= g_gx_panda_context.old_position.x && coord_x <= g_gx_panda_context.old_position.x + MMI_GX_PANDA_ROLE_WIDTH
  1410.    && coord_y >= g_gx_panda_context.old_position.y && coord_y <= g_gx_panda_context.old_position.y + MMI_GX_PANDA_ROLE_HEIGHT)
  1411. {
  1412. PandaState = PANDA_MOVE_KILLENEMY;
  1413. return PANDA_MOVE_KILLENEMY;
  1414. }
  1415. else if(coord_x > g_gx_panda_context.old_position.x + MMI_GX_PANDA_ROLE_WIDTH)
  1416. {
  1417. PandaState = PANDA_MOVE_RIGHT;
  1418. return PANDA_MOVE_RIGHT;
  1419. }
  1420. else if(coord_x < g_gx_panda_context.old_position.x )
  1421. {
  1422. PandaState = PANDA_MOVE_LEFT;
  1423. return PANDA_MOVE_LEFT;
  1424. }
  1425. else if(coord_y > g_gx_panda_context.old_position.y)
  1426. {
  1427. PandaState = PANDA_MOVE_DOWN;
  1428. return PANDA_MOVE_DOWN;
  1429. }
  1430. else if(coord_y < g_gx_panda_context.old_position.y)
  1431. {
  1432. PandaState = PANDA_MOVE_UP;
  1433. return PANDA_MOVE_UP;
  1434. }
  1435. else
  1436. {
  1437. PandaState = PANDA_MOVE_NONE;
  1438. return PANDA_MOVE_NONE;
  1439. }
  1440. }
  1441. /*****************************************************************************
  1442.  * FUNCTION
  1443.  *  mmi_panda_pen_down_hdlr
  1444.  * DESCRIPTION
  1445.  *  
  1446.  * PARAMETERS
  1447.  *  pos     [IN]        
  1448.  * RETURNS
  1449.  *  void
  1450.  *****************************************************************************/
  1451.  
  1452. void mmi_panda_pen_down_hdlr(mmi_pen_point_struct pos)
  1453. {
  1454. S32 pos_x = pos.x, pos_y = pos.y;
  1455. switch(mmi_panda_is_panda_moveable(pos_x,pos_y))
  1456. {
  1457. case PANDA_MOVE_UP:
  1458. mmi_gx_panda_key_2_press();
  1459. break;
  1460. case PANDA_MOVE_DOWN:
  1461. mmi_gx_panda_key_8_press();
  1462. break;
  1463. case PANDA_MOVE_LEFT:
  1464. mmi_gx_panda_key_4_press();
  1465. break;
  1466. case PANDA_MOVE_RIGHT:
  1467. mmi_gx_panda_key_6_press();
  1468. break;
  1469. case PANDA_MOVE_KILLENEMY:
  1470. mmi_gx_panda_key_5_press();
  1471. break;
  1472. default:
  1473. break;
  1474. }
  1475. }
  1476. /*****************************************************************************
  1477.  * FUNCTION
  1478.  *  mmi_panda_pen_up_hdlr
  1479.  * DESCRIPTION
  1480.  *  
  1481.  * PARAMETERS
  1482.  *  pos     [IN]        
  1483.  * RETURNS
  1484.  *  void
  1485.  *****************************************************************************/
  1486.  
  1487. void mmi_panda_pen_up_hdlr(mmi_pen_point_struct pos)
  1488. {
  1489. switch(PandaState)
  1490. {
  1491. case PANDA_MOVE_UP:
  1492. mmi_gx_panda_key_2_release();
  1493. break;
  1494. case PANDA_MOVE_DOWN:
  1495. mmi_gx_panda_key_8_release();
  1496. break;
  1497. case PANDA_MOVE_LEFT:
  1498. //mmi_gx_panda_key_2_release();
  1499. break;
  1500. case PANDA_MOVE_RIGHT:
  1501. //mmi_gx_panda_key_8_release();
  1502. break;
  1503. case PANDA_MOVE_KILLENEMY:
  1504. mmi_gx_panda_key_5_release();
  1505. break;
  1506. default:
  1507. break;
  1508. }
  1509. }
  1510. #endif /* __MMI_TOUCH_SCREEN__ */ 
  1511. //KP Jerry add on 2007-3-23 end
  1512. #endif /* IS_PANDA_BASE_GAME */