Panda.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:398k
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* compare the best grade and return it */
- if (new_grade > old_grade)
- {
- return new_grade;
- }
- else
- {
- return old_grade;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_draw_gameover
- * DESCRIPTION
- * Draw Gameover Screen [Callback required by GFX]
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_draw_gameover(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- GFX_PLAY_AUDIO_GAMEOVER();
- /* call this function to draw standard gameover screen */
- mmi_gfx_draw_gameover_screen(
- IMG_ID_GX_PANDA_GOTEXT,
- IMG_ID_GX_PANDA_GRADESMAP,
- IMG_ID_GX_PANDA_GOPIC,
- g_gx_panda_context.game_grade);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_enter_game
- * DESCRIPTION
- * Enter Game [Callback required by GFX]
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_enter_game(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_gx_panda_context.is_new_game == TRUE)
- {
- mmi_gx_panda_init_game(); /* is new game, otherwise resume game */
- }
- g_gx_panda_context.is_new_game = FALSE;
- g_gx_panda_context.is_gameover = FALSE;
- /* init key's state */
- g_gx_panda_context.up_key_pressed = FALSE;
- g_gx_panda_context.down_key_pressed = FALSE;
- gdi_layer_multi_layer_enable();
- gdi_layer_get_base_handle(&g_gx_panda_context.background);
- gdi_layer_create(0, 0, MMI_GX_PANDA_LCD_WIDTH, MMI_GX_PANDA_LCD_HEIGHT, &g_gx_panda_context.foreground);
- gdi_layer_set_active(g_gx_panda_context.foreground);
- gdi_layer_set_source_key(TRUE, GDI_COLOR_BLUE); /* set pure-blue as the transparent color in foreground */
- gdi_layer_clear_background(GDI_COLOR_BLUE); /* clean foreground layer */
- // gdi_image_draw_id(50,50,IMG_GLOBAL_WARNING); /* only use for demo */
- /* draw background image */
- gdi_layer_set_active(g_gx_panda_context.background);
- gdi_layer_set_clip(0, 0, MMI_GX_PANDA_LCD_WIDTH - 1, MMI_GX_PANDA_LCD_HEIGHT - 1);
- gdi_image_draw_id(0, 0, IMG_ID_GX_PANDA_BACKGROUND);
- #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
- GFX_OPEN_BACKGROUND_SOUND(BackGround_Panda_Midi, BACKGROUND_PANDA_MIDI, g_gx_panda_context.background_midi);
- GFX_PLAY_BACKGROUND_SOUND(g_gx_panda_context.background_midi);
- GFX_OPEN_DUMMY_BACKGROUND_SOUND();
- GFX_PLAY_DUMMY_BACKGROUND_SOUND();
- GFX_OPEN_SOUND_EFFECTS_MIDI(Up_Down_Midi, UPDOWN_MIDI, 1, g_gx_panda_context.updown_midi);
- GFX_OPEN_SOUND_EFFECTS_MIDI(PandaBounce_Midi, PANDABOUNCE_MIDI, 1, g_gx_panda_context.bounce_midi);
- GFX_OPEN_SOUND_EFFECTS_MIDI(PandaHit_Midi, PANDAHIT_MIDI, 1, g_gx_panda_context.hit_midi);
- GFX_OPEN_MULTICHANNEL_WAV(PandaFall_wav, PANDAFALL_WAV, 1, g_gx_panda_context.fail_wav);
- /* using hit wav for eating the clock */
- GFX_OPEN_MULTICHANNEL_WAV(PandaEating_wav, PANDAEATING_WAV, 1, g_gx_panda_context.eating_wav);
- GFX_OPEN_MULTICHANNEL_WAV(PandaDown_wav, PANDADOWN_WAV, 1, g_gx_panda_context.down_wav);
- #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- SetKeyHandler(mmi_gx_panda_key_2_press, KEY_2, KEY_EVENT_DOWN);
- SetKeyHandler(mmi_gx_panda_key_8_press, KEY_8, KEY_EVENT_DOWN);
- SetKeyHandler(mmi_gx_panda_key_2_press, KEY_UP_ARROW, KEY_EVENT_DOWN);
- SetKeyHandler(mmi_gx_panda_key_8_press, KEY_DOWN_ARROW, KEY_EVENT_DOWN);
- SetKeyHandler(mmi_gx_panda_key_2_release, KEY_2, KEY_EVENT_UP);
- SetKeyHandler(mmi_gx_panda_key_8_release, KEY_8, KEY_EVENT_UP);
- SetKeyHandler(mmi_gx_panda_key_4_press, KEY_4, KEY_EVENT_DOWN);
- SetKeyHandler(mmi_gx_panda_key_6_press, KEY_6, KEY_EVENT_DOWN);
- SetKeyHandler(mmi_gx_panda_key_2_release, KEY_UP_ARROW, KEY_EVENT_UP);
- SetKeyHandler(mmi_gx_panda_key_8_release, KEY_DOWN_ARROW, KEY_EVENT_UP);
- SetKeyHandler(mmi_gx_panda_key_4_press, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
- SetKeyHandler(mmi_gx_panda_key_6_press, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
- SetKeyHandler(mmi_gx_panda_key_5_press, KEY_5, KEY_EVENT_DOWN);
- SetKeyHandler(mmi_gx_panda_key_5_release, KEY_5, KEY_EVENT_UP);
- mmi_gx_panda_draw_static_background();
- /* set bgm resume handle */
- /* SetProtocolEventHandler(mmi_gx_panda_resume_bgm, PRT_EQ_PLAY_AUDIO_FINISH_IND); */
- /* start game loop */
- mmi_gx_panda_cyclic_timer();
- //KP Jerry add on 2007-3-23 start
- #ifdef __MMI_TOUCH_SCREEN__
- wgui_register_pen_down_handler(mmi_panda_pen_down_hdlr);
- wgui_register_pen_up_handler(mmi_panda_pen_up_hdlr);
- #endif /* __MMI_TOUCH_SCREEN__ */
- //KP Jerry add on 2007-3-23 end
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_resume_bgm
- * DESCRIPTION
- * resume bgm
- * PARAMETERS
- * void
- * RETURNS
- * void
- * GLOBALS AFFECTED
- * NIL
- ****************************************************************************/
- //void mmi_gx_panda_resume_bgm(void *info)
- //{
- // if (g_gx_panda_context.up_key_pressed != FALSE || g_gx_panda_context.down_key_pressed != FALSE)
- // {
- // GFX_PLAY_AUDIO_DVI(PandaUp_down_dvi, PANDAUP_DOWN_DVI, DEVICE_AUDIO_PLAY_ONCE);
- // }
- //}
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_draw_static_background
- * DESCRIPTION
- * Draw static background
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_draw_static_background(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- UI_string_type str_ptr;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- str_ptr = (UI_string_type) GetString(STR_GAME_SCORE);
- /* draw score */
- #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
- gui_set_font(&MMI_small_font);
- #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
- gui_set_font(&MMI_medium_font);
- //KP Jerry add on 2007-3-23 start
- #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
- gui_set_font(&MMI_large_font);
- //KP Jerry add on 2007-3-23 end
- #endif
- gui_set_text_color(gui_color(255, 255, 255));
- gui_set_text_border_color(gui_color(0, 0, 0));
- g_gx_panda_context.score_str_width = (S16) gui_get_string_width(str_ptr);
- if (r2lMMIFlag)
- {
- #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
- gui_move_text_cursor(125, 3);
- #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
- gui_move_text_cursor(171, 3);
- //KP Jerry add on 2007-3-23 start
- #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
- gui_move_text_cursor(171, 3);
- //KP Jerry add on 2007-3-23 end
- #endif
- gui_print_bordered_text(str_ptr);
- /* draw clock */
- #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
- gdi_image_draw_id(32, 1, IMG_ID_GX_PANDA_CLOCK);
- #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
- gdi_image_draw_id(30, 1, IMG_ID_GX_PANDA_CLOCK);
- //KP Jerry add on 2007-3-23 start
- #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
- gdi_image_draw_id(30, 1, IMG_ID_GX_PANDA_CLOCK);
- //KP Jerry add on 2007-3-23 end
- #endif
- }
- else
- {
- #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
- gui_move_text_cursor(3, 3);
- #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
- gui_move_text_cursor(5, 3);
- //KP Jerry add on 2007-3-23 start
- #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
- gui_move_text_cursor(5, 3);
- //KP Jerry add on 2007-3-23 end
- #endif
- gui_print_bordered_text(str_ptr);
- /* draw clock */
- #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
- gdi_image_draw_id(86, 1, IMG_ID_GX_PANDA_CLOCK);
- #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
- gdi_image_draw_id(118, 1, IMG_ID_GX_PANDA_CLOCK);
- //KP Jerry add on 2007-3-23 start
- #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
- gdi_image_draw_id(150, 1, IMG_ID_GX_PANDA_CLOCK);
- //KP Jerry add on 2007-3-23 end
- #endif
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_exit_game
- * DESCRIPTION
- * Exit Game [Callback required by GFX]
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_exit_game(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* reset bgm resume handler */
- /* SetProtocolEventHandler(NULL, PRT_EQ_PLAY_AUDIO_FINISH_IND); */
- gui_cancel_timer(mmi_gx_panda_cyclic_timer); /* cancle the looping timer */
- #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
- GFX_CLOSE_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
- GFX_CLOSE_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
- GFX_CLOSE_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
- GFX_CLOSE_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
- GFX_CLOSE_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
- GFX_CLOSE_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
- GFX_STOP_DUMMY_BACKGROUND_SOUND();
- GFX_CLOSE_DUMMY_BACKGROUND_SOUND();
- GFX_STOP_BACKGROUND_SOUND(g_gx_panda_context.background_midi);
- GFX_CLOSE_BACKGROUND_SOUND(g_gx_panda_context.background_midi);
- #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */ /* /__MMI_GAME_MULTICHANNEL_SOUND__ */
- gdi_layer_free(g_gx_panda_context.foreground);
- gdi_layer_multi_layer_disable();
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_init_enemy_list
- * DESCRIPTION
- * init_enemy_list
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_init_enemy_list(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- gx_panda_pos_state_enum i;
- U8 j;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- for (i = LEFT_TREE_LEFT; i <= RIGHT_TREE_RIGHT; i++)
- {
- g_gx_panda_context.tree[i].first = &(g_gx_panda_context.tree[i].enemy[0]);
- g_gx_panda_context.tree[i].last = &(g_gx_panda_context.tree[i].enemy[0]);
- g_gx_panda_context.tree[i].empty = &(g_gx_panda_context.tree[i].enemy[1]);
- g_gx_panda_context.tree[i].empty_last = &(g_gx_panda_context.tree[i].enemy[MMI_GX_PANDA_ENEMY_COUNT - 1]);
- for (j = 0; j < MMI_GX_PANDA_ENEMY_COUNT; j++)
- {
- if (j == 0)
- {
- g_gx_panda_context.tree[i].enemy[j].position_y =
- MMI_GX_PANDA_LCD_HEIGHT + MMI_GX_PANDA_ENEMY_HEIGHT * (rand() % RIGHT_TREE_RIGHT);
- g_gx_panda_context.tree[i].enemy[j].old_position_y = g_gx_panda_context.tree[i].enemy[j].position_y;
- g_gx_panda_context.tree[i].enemy[j].type = ENEMY_1 + (gx_panda_type_enum) (rand() % 3);
- }
- if (j != 0)
- {
- g_gx_panda_context.tree[i].enemy[j].previous = &(g_gx_panda_context.tree[i].enemy[j - 1]);
- }
- if (j != MMI_GX_PANDA_ENEMY_COUNT - 1)
- {
- g_gx_panda_context.tree[i].enemy[j].next = &(g_gx_panda_context.tree[i].enemy[j + 1]);
- }
- g_gx_panda_context.tree[i].enemy[j].is_dying = FALSE;
- }
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_init_game
- * DESCRIPTION
- * Game initilization
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_init_game(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* init game */
- g_gx_panda_context.pos_state = MID_TREE_LEFT;
- g_gx_panda_context.state = NORMAL;
- g_gx_panda_context.position.y = 13; /* initial role's y position */
- g_gx_panda_context.pos_state = MID_TREE_LEFT; /* on the LEFT of the MIDDLE PANDA */
- g_gx_panda_context.state = NORMAL; /* Not in ATTACK STATE */
- g_gx_panda_context.old_state = NORMAL; /* Not in ATTACK STATE */
- g_gx_panda_context.old_pos_state = MID_TREE_LEFT;
- g_gx_panda_context.tick = 0; /* tick initialization */
- g_gx_panda_context.total_time = MMI_GX_PANDA_TOTAL_TIME;
- g_gx_panda_context.up_key_pressed = FALSE;
- g_gx_panda_context.down_key_pressed = FALSE;
- g_gx_panda_context.position.x = mmi_gx_panda_get_x_position(g_gx_panda_context.pos_state, MMI_GX_PANDA_IS_ROLE);
- g_gx_panda_context.old_position = g_gx_panda_context.position;
- g_gx_panda_context.clock_falling = FALSE;
- g_gx_panda_context.is_dying = FALSE;
- g_gx_panda_context.game_grade = 0;
- g_gx_panda_context.enemy_speed = MMI_GX_PANDA_ENEMY_SLOW_SPEED;
- mmi_gx_panda_init_enemy_list();
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_framemove
- * DESCRIPTION
- * Framemove - process the game logic
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_framemove(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 moving_speed; /* the moving speed of role */
- U8 tree_number;
- BOOL is_reach_button = FALSE;
- gx_panda_node_struct *current_node;
- gx_panda_node_struct *next_node;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* determine the moving speed of the role */
- if (g_gx_panda_context.state != ATTACK)
- {
- moving_speed = MMI_GX_PANDA_ROLE_SPEED;
- }
- else
- {
- moving_speed = MMI_GX_PANDA_ROLE_ATTACK_SPEED;
- }
- /* not dying */
- if (g_gx_panda_context.is_dying != TRUE)
- {
- /* detect if role goes to the bottom */
- if (g_gx_panda_context.down_key_pressed != FALSE)
- {
- g_gx_panda_context.position.y = g_gx_panda_context.position.y + moving_speed;
- if (g_gx_panda_context.position.y >= MMI_GX_PANDA_LCD_HEIGHT - MMI_GX_PANDA_ROLE_HEIGHT - 1)
- {
- if (g_gx_panda_context.state == ATTACK)
- {
- is_reach_button = TRUE;
- }
- g_gx_panda_context.position.y = MMI_GX_PANDA_LCD_HEIGHT - MMI_GX_PANDA_ROLE_HEIGHT - 1;
- }
- }
- /* detect if role goes to the upmost */
- if (g_gx_panda_context.up_key_pressed != FALSE)
- {
- g_gx_panda_context.position.y = g_gx_panda_context.position.y - MMI_GX_PANDA_ROLE_SPEED;
- if (g_gx_panda_context.position.y < MMI_GX_PANDA_TOP_MARGIN)
- {
- g_gx_panda_context.position.y = MMI_GX_PANDA_TOP_MARGIN + 1;
- }
- }
- }
- /* every one second (when total time < 3 minutes) and every 0.5 second (when total time > 3 minutes), new() a enemy */
- if (((g_gx_panda_context.tick <= 1800 && g_gx_panda_context.tick % 10 == 0) ||
- (g_gx_panda_context.tick > 1800 && g_gx_panda_context.tick % 5 == 0)) && g_gx_panda_context.tick != 0)
- {
- tree_number = rand() % MMI_GX_PANDA_SIDE_COUNT;
- g_gx_panda_context.tree[tree_number].empty->position_y = MMI_GX_PANDA_LCD_HEIGHT + 1;
- g_gx_panda_context.tree[tree_number].empty->type = ENEMY_1 + rand() % 3;
- g_gx_panda_context.tree[tree_number].last = g_gx_panda_context.tree[tree_number].empty;
- g_gx_panda_context.tree[tree_number].empty = g_gx_panda_context.tree[tree_number].empty->next;
- }
- /* check if the "clock" (for time extension) should appear after attacking 10 enemies */
- if ((g_gx_panda_context.game_grade + 5) % 50 == 0)
- {
- g_gx_panda_context.clock_falling = TRUE;
- g_gx_panda_context.clock_position_y = -MMI_GX_PANDA_CLOCK_HEIGHT - 10;
- g_gx_panda_context.clock_old_position_y = -MMI_GX_PANDA_CLOCK_HEIGHT - 10;
- /* determine which space between two pandas the clock should appear */
- if (rand() % 2 != 0)
- {
- g_gx_panda_context.clock_pos_state = LEFT_SPACE;
- }
- else
- {
- g_gx_panda_context.clock_pos_state = RIGHT_SPACE;
- }
- g_gx_panda_context.clock_x_position =
- (S16) mmi_gx_panda_get_x_position(g_gx_panda_context.clock_pos_state, MMI_GX_PANDA_IS_CLOCK);
- }
- /* dying, calc positon and do not need do collision detection */
- if (g_gx_panda_context.is_dying == TRUE)
- {
- g_gx_panda_context.position.x = mmi_gx_panda_get_x_position(g_gx_panda_context.pos_state, MMI_GX_PANDA_IS_DYING_ROLE);
- return;
- }
- /* collision detection */
- if (g_gx_panda_context.state != FLYING && g_gx_panda_context.old_state != FLYING)
- {
- current_node = g_gx_panda_context.tree[g_gx_panda_context.pos_state].first;
- while (current_node != g_gx_panda_context.tree[g_gx_panda_context.pos_state].empty)
- {
- next_node = current_node->next;
- /* Of course, if the enemy is dying, then we don't have to check if the collision happens */
- if (current_node->is_dying != TRUE)
- {
- if ((current_node->position_y >= g_gx_panda_context.position.y &&
- current_node->position_y < g_gx_panda_context.position.y + MMI_GX_PANDA_ROLE_HEIGHT) ||
- (g_gx_panda_context.position.y >= current_node->position_y &&
- g_gx_panda_context.position.y < current_node->position_y + MMI_GX_PANDA_ENEMY_HEIGHT))
- {
- /* in attack mode */
- if (g_gx_panda_context.state == ATTACK && current_node->is_dying != TRUE)
- {
- current_node->is_dying = TRUE;
- /* increase score */
- g_gx_panda_context.game_grade = g_gx_panda_context.game_grade + MMI_GX_PANDA_SCORE_PER_ENEMY;
- #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
- GFX_PLAY_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
- #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- GFX_PLAY_AUDIO_DVI(PandaHit_dvi, PANDAHIT_DVI, DEVICE_AUDIO_PLAY_ONCE);
- #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- /* GFX_PLAY_VIBRATION(); */
- }
- /* in normal mode */
- else if (g_gx_panda_context.state == NORMAL)
- {
- g_gx_panda_context.is_dying = TRUE;
- /* determine which space will the dying role fall */
- g_gx_panda_context.position.x = mmi_gx_panda_get_x_position(g_gx_panda_context.pos_state, MMI_GX_PANDA_IS_DYING_ROLE);
- #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
- GFX_PLAY_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
- #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- GFX_PLAY_AUDIO_DVI(PandaFall_dvi, PANDAFALL_DVI, DEVICE_AUDIO_PLAY_ONCE);
- #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- }
- }
- }
- current_node = next_node;
- }
- }
- if (is_reach_button == TRUE)
- {
- g_gx_panda_context.state = NORMAL;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_render
- * DESCRIPTION
- * Render the game images
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_render(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- MMI_ID_TYPE role_image;
- S16 i;
- S16 enemy_x_position;
- S16 old_enemy_x_position;
- gx_panda_node_struct *current_node;
- gx_panda_node_struct *next_node;
- gx_panda_node_struct *tmp_node;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- gdi_layer_set_active(g_gx_panda_context.foreground);
- gdi_layer_clear_background(MMI_GX_PANDA_TRANSPARENT_COLOR);
- /* decrease time left for every second */
- if (g_gx_panda_context.tick % 10 == 0)
- {
- g_gx_panda_context.total_time = g_gx_panda_context.total_time - 1;
- }
- /* time is up */
- if (g_gx_panda_context.total_time == 0)
- {
- mmi_gx_panda_gameover();
- if (g_gx_panda_context.is_gameover != FALSE)
- {
- return;
- }
- }
- /* increase the speed of enemy for every 1.5 minutes */
- if ((g_gx_panda_context.tick + 1) % 900 == 0)
- {
- g_gx_panda_context.enemy_speed = g_gx_panda_context.enemy_speed + 1;
- }
- /* erase all enemies */
- for (i = LEFT_TREE_LEFT; i <= RIGHT_TREE_RIGHT; i++)
- {
- current_node = g_gx_panda_context.tree[i].first;
- while (current_node != g_gx_panda_context.tree[i].empty)
- {
- /* determine enemy's position_x while not dying */
- if (current_node->is_dying != TRUE)
- {
- enemy_x_position = mmi_gx_panda_get_x_position(i, MMI_GX_PANDA_IS_ENEMY);
- }
- /* determine enemy's position_x while dying */
- else
- {
- enemy_x_position = mmi_gx_panda_get_x_position(i, MMI_GX_PANDA_IS_DYING_ENEMY);
- old_enemy_x_position = mmi_gx_panda_get_x_position(i, MMI_GX_PANDA_IS_ENEMY);
- }
- current_node = current_node->next;
- }
- }
- /* display time left */
- #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
- if (r2lMMIFlag)
- {
- mmi_gx_panda_draw_digits(26, 3, g_gx_panda_context.total_time);
- }
- else
- {
- mmi_gx_panda_draw_digits(102, 3, g_gx_panda_context.total_time);
- }
- #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
- if (r2lMMIFlag)
- {
- mmi_gx_panda_draw_digits(20, 3, g_gx_panda_context.total_time);
- }
- else
- {
- mmi_gx_panda_draw_digits(140, 3, g_gx_panda_context.total_time);
- }
- //KP Jerry add on 2007-3-23 start
- #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
- if (r2lMMIFlag)
- {
- mmi_gx_panda_draw_digits(20, 3, g_gx_panda_context.total_time);
- }
- else
- {
- mmi_gx_panda_draw_digits(195, 1, g_gx_panda_context.total_time);
- }
- //KP Jerry add on 2007-3-23 end
- #endif
- /* display score */
- #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
- if (r2lMMIFlag)
- {
- mmi_gx_panda_draw_digits((U16) (119 - g_gx_panda_context.score_str_width), 3, g_gx_panda_context.game_grade);
- }
- else
- {
- mmi_gx_panda_draw_digits((U16) (g_gx_panda_context.score_str_width + 9), 3, g_gx_panda_context.game_grade);
- }
- #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
- if (r2lMMIFlag)
- {
- mmi_gx_panda_draw_digits((U16) (167 - g_gx_panda_context.score_str_width), 3, g_gx_panda_context.game_grade);
- }
- else
- {
- mmi_gx_panda_draw_digits((U16) (g_gx_panda_context.score_str_width + 9), 3, g_gx_panda_context.game_grade);
- }
- //KP Jerry add on 2007-3-23 start
- #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
- if (r2lMMIFlag)
- {
- mmi_gx_panda_draw_digits((U16) (167 - g_gx_panda_context.score_str_width), 3, g_gx_panda_context.game_grade);
- }
- else
- {
- mmi_gx_panda_draw_digits((U16) (g_gx_panda_context.score_str_width + 9), 1, g_gx_panda_context.game_grade);
- }
- //KP Jerry add on 2007-3-23 end
- #endif
- /* drawing clock */
- if (g_gx_panda_context.clock_falling != FALSE)
- {
- g_gx_panda_context.clock_position_y = g_gx_panda_context.clock_position_y + MMI_GX_PANDA_CLOCK_SPEED;
- /* draw new clock image */
- gdi_image_draw_id(
- g_gx_panda_context.clock_x_position,
- g_gx_panda_context.clock_position_y,
- IMG_ID_GX_PANDA_CLOCK);
- g_gx_panda_context.clock_old_position_y = g_gx_panda_context.clock_position_y;
- if (g_gx_panda_context.clock_position_y > MMI_GX_PANDA_LCD_HEIGHT)
- {
- g_gx_panda_context.clock_falling = FALSE;
- }
- }
- /* draw enemies and update their position */
- for (i = LEFT_TREE_LEFT; i <= RIGHT_TREE_RIGHT; i++)
- {
- current_node = g_gx_panda_context.tree[i].first;
- while (current_node != g_gx_panda_context.tree[i].empty)
- {
- /* determine enemy's position_x while not dying */
- if (current_node->is_dying != TRUE)
- {
- enemy_x_position = mmi_gx_panda_get_x_position(i, MMI_GX_PANDA_IS_ENEMY);
- }
- /* determine enemy's position_x while dying */
- else
- {
- enemy_x_position = mmi_gx_panda_get_x_position(i, MMI_GX_PANDA_IS_DYING_ENEMY);
- old_enemy_x_position = mmi_gx_panda_get_x_position(i, MMI_GX_PANDA_IS_ENEMY);
- }
- /* left enemy case */
- if (i % 2 == 0)
- {
- gdi_image_draw_id(
- enemy_x_position,
- current_node->position_y,
- (U16) (IMG_ID_GX_PANDA_ENEMY_1_LEFT + current_node->type + (g_gx_panda_context.tick / 2 % 2) * 3));
- }
- /* right enemy case */
- else
- {
- gdi_image_draw_id(
- enemy_x_position,
- current_node->position_y,
- (U16) (IMG_ID_GX_PANDA_ENEMY_1_RIGHT + current_node->type + (g_gx_panda_context.tick / 2 % 2) * 3));
- }
- /* update information */
- current_node->old_position_y = current_node->position_y;
- if (current_node->is_dying != TRUE)
- {
- current_node->position_y = current_node->position_y - g_gx_panda_context.enemy_speed;
- }
- else
- {
- current_node->position_y = current_node->position_y + MMI_GX_PANDA_FALLING_SPEED;
- }
- next_node = current_node->next;
- /* if the enemy is going out of the boundary, remove it from panda */
- if (current_node->position_y + MMI_GX_PANDA_ENEMY_HEIGHT + 1 < 0 ||
- current_node->position_y > MMI_GX_PANDA_LCD_HEIGHT)
- {
- /* normal case */
- if (current_node->is_dying != TRUE)
- {
- /* remove the first enemy in the list and append to the last position of the list */
- g_gx_panda_context.tree[i].empty_last->next = g_gx_panda_context.tree[i].first;
- g_gx_panda_context.tree[i].first->previous = g_gx_panda_context.tree[i].empty_last;
- g_gx_panda_context.tree[i].empty_last = g_gx_panda_context.tree[i].first;
- g_gx_panda_context.tree[i].first = current_node->next;
- }
- /* enemy dying case */
- else
- {
- /* if the dying enemy is the first enemy on the panda */
- if (current_node == g_gx_panda_context.tree[i].first)
- {
- g_gx_panda_context.tree[i].empty_last->next = g_gx_panda_context.tree[i].first;
- g_gx_panda_context.tree[i].first->previous = g_gx_panda_context.tree[i].empty_last;
- g_gx_panda_context.tree[i].empty_last = g_gx_panda_context.tree[i].first;
- g_gx_panda_context.tree[i].first = current_node->next;
- }
- else
- {
- tmp_node = current_node->previous;
- tmp_node->next = current_node->next;
- current_node->next->previous = tmp_node;
- g_gx_panda_context.tree[i].empty_last->next = current_node;
- current_node->previous = g_gx_panda_context.tree[i].empty_last;
- g_gx_panda_context.tree[i].empty_last = current_node;
- }
- /* because it became empty, need to restore the state */
- current_node->is_dying = FALSE;
- }
- }
- current_node = next_node;
- }
- }
- /* while the role is alive */
- if (g_gx_panda_context.is_dying != TRUE)
- {
- /* determine the role image */
- /* while key pressing, the role is moving as a result we need to draw animation */
- if (g_gx_panda_context.up_key_pressed != FALSE || g_gx_panda_context.down_key_pressed != FALSE)
- {
- switch (g_gx_panda_context.pos_state)
- {
- /* all LEFT cases */
- case LEFT_TREE_LEFT:
- case MID_TREE_LEFT:
- case RIGHT_TREE_LEFT:
- if (g_gx_panda_context.state == ATTACK)
- {
- role_image = IMG_ID_GX_PANDA_ROLE_ATTACK_L_FRAME_0 + (g_gx_panda_context.tick % 2);
- }
- else
- {
- role_image = IMG_ID_GX_PANDA_ROLE_LEFT_FRAME_0 + (g_gx_panda_context.tick % 2);
- }
- break;
- /* all RIGHT cases */
- case LEFT_TREE_RIGHT:
- case MID_TREE_RIGHT:
- case RIGHT_TREE_RIGHT:
- if (g_gx_panda_context.state == ATTACK)
- {
- role_image = IMG_ID_GX_PANDA_ROLE_ATTACK_R_FRAME_0 + (g_gx_panda_context.tick % 2);
- }
- else
- {
- role_image = IMG_ID_GX_PANDA_ROLE_RIGHT_FRAME_0 + (g_gx_panda_context.tick % 2);
- }
- break;
- }
- }
- /* while key not pressing, the role is still */
- else if (g_gx_panda_context.up_key_pressed != TRUE && g_gx_panda_context.down_key_pressed != TRUE)
- {
- switch (g_gx_panda_context.pos_state)
- {
- /* all LEFT cases */
- case LEFT_TREE_LEFT:
- case MID_TREE_LEFT:
- case RIGHT_TREE_LEFT:
- role_image = IMG_ID_GX_PANDA_ROLE_LEFT_FRAME_0;
- break;
- /* all RIGHT cases */
- case LEFT_TREE_RIGHT:
- case MID_TREE_RIGHT:
- case RIGHT_TREE_RIGHT:
- role_image = IMG_ID_GX_PANDA_ROLE_RIGHT_FRAME_0;
- break;
- }
- }
- /* while the role is flying */
- if (g_gx_panda_context.state == FLYING)
- {
- role_image = IMG_ID_GX_PANDA_ROLE_JUMP;
- /* check if the role get the clock */
- if (g_gx_panda_context.clock_falling != FALSE)
- {
- /* the role from left_tree to mid_tree or from mid_tree to left_tree */
- /* or the role from right_tree to mid_tree or from mid_tree to right_tree */
- if ((g_gx_panda_context.clock_pos_state == LEFT_SPACE &&
- ((g_gx_panda_context.old_pos_state == LEFT_TREE_RIGHT &&
- g_gx_panda_context.pos_state == MID_TREE_LEFT) ||
- (g_gx_panda_context.pos_state == LEFT_TREE_RIGHT &&
- g_gx_panda_context.old_pos_state == MID_TREE_LEFT))) ||
- (g_gx_panda_context.clock_pos_state == RIGHT_SPACE &&
- ((g_gx_panda_context.old_pos_state == RIGHT_TREE_LEFT &&
- g_gx_panda_context.pos_state == MID_TREE_RIGHT) ||
- (g_gx_panda_context.pos_state == RIGHT_TREE_LEFT &&
- g_gx_panda_context.old_pos_state == MID_TREE_RIGHT))))
- {
- /* the role does touch the clock */
- if ((g_gx_panda_context.position.y >= g_gx_panda_context.clock_position_y &&
- g_gx_panda_context.position.y <
- g_gx_panda_context.clock_position_y + MMI_GX_PANDA_CLOCK_HEIGHT) ||
- (g_gx_panda_context.clock_position_y >= g_gx_panda_context.position.y &&
- g_gx_panda_context.clock_position_y <
- g_gx_panda_context.position.y + MMI_GX_PANDA_ROLE_HEIGHT))
- {
- /* extend 20 seconds */
- g_gx_panda_context.total_time = g_gx_panda_context.total_time + MMI_GX_PANDA_TIME_EXTENSION;
- g_gx_panda_context.clock_falling = FALSE;
- #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
- GFX_PLAY_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
- #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- GFX_PLAY_AUDIO_DVI(PandaEat_dvi, PANDAEAT_DVI, DEVICE_AUDIO_PLAY_ONCE);
- #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- }
- }
- if (g_gx_panda_context.total_time > 99)
- {
- g_gx_panda_context.total_time = 99;
- }
- }
- }
- }
- /* while the role is dying */
- else
- {
- role_image = IMG_ID_GX_PANDA_ROLE_FALL_FRAME_0 + (g_gx_panda_context.tick % 2);
- }
- g_gx_panda_context.old_position = g_gx_panda_context.position;
- g_gx_panda_context.old_pos_state = g_gx_panda_context.pos_state;
- if (g_gx_panda_context.old_state == FLYING)
- {
- g_gx_panda_context.old_state = NORMAL;
- }
- /* Last, draw the role image because it should be on top of the layer to show correct display order */
- gdi_image_draw_id(g_gx_panda_context.position.x, g_gx_panda_context.position.y, role_image);
- /* set the flying role's position to the landing position */
- if (g_gx_panda_context.state == FLYING)
- {
- g_gx_panda_context.state = NORMAL;
- g_gx_panda_context.old_state = FLYING;
- g_gx_panda_context.position.x = mmi_gx_panda_get_x_position(g_gx_panda_context.pos_state, MMI_GX_PANDA_IS_ROLE);
- }
- /* if the role is dying */
- if (g_gx_panda_context.is_dying != FALSE)
- {
- g_gx_panda_context.position.y = g_gx_panda_context.position.y + MMI_GX_PANDA_FALLING_SPEED;
- if (g_gx_panda_context.position.y > MMI_GX_PANDA_LCD_HEIGHT)
- {
- mmi_gx_panda_gameover();
- gdi_layer_set_active(g_gx_panda_context.background);
- return;
- }
- }
- gdi_layer_blt(
- g_gx_panda_context.background, /* layer 0 */
- g_gx_panda_context.foreground, /* layer 1 */
- 0, /* layer 2 */
- 0, /* layer 3 */
- 0, /* offset x */
- 0, /* offset y */
- UI_device_width - 1, /* widht */
- UI_device_height - 1); /* height */
- gdi_layer_set_active(g_gx_panda_context.background);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_draw_digits
- * DESCRIPTION
- * Drawing digits
- * PARAMETERS
- * x [IN] X position for images
- * y [IN] Y position for images
- * number [IN] The number to be displayed
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_draw_digits(U16 x, U16 y, U16 number)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S8 buf[20];
- S8 buf_USC2[40];
- S32 str_width;
- S32 str_height;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
- gui_set_font(&MMI_small_font);
- #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
- gui_set_font(&MMI_medium_font);
- //KP Jerry add on 2007-3-23 start
- #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
- gui_set_font(&MMI_large_font);
- //KP Jerry add on 2007-3-23 end
- #endif
- gui_set_text_color(gui_color(255, 255, 255));
- gui_set_text_border_color(gui_color(0, 0, 0));
- sprintf(buf, "%d", number);
- AnsiiToUnicodeString(buf_USC2, buf);
- gui_measure_string((UI_string_type) buf_USC2, &str_width, &str_height);
- gui_move_text_cursor(x, y);
- gui_print_bordered_text((UI_string_type) buf_USC2);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_turn_or_fly
- * DESCRIPTION
- * React to turn left or turn right action
- * PARAMETERS
- * action [IN] Indicate the input is left-pressing or right-pressing
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_turn_or_fly(U8 action)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* if the role is dying, we don't need to process the key press */
- if (g_gx_panda_context.is_dying != FALSE)
- {
- return;
- }
- g_gx_panda_context.old_pos_state = g_gx_panda_context.pos_state;
- if (action == MMI_GX_PANDA_GO_LEFT)
- {
- /* it's not in the leftmost position thus there is action happen */
- if (g_gx_panda_context.pos_state != LEFT_TREE_LEFT)
- {
- g_gx_panda_context.pos_state = g_gx_panda_context.pos_state - 1;
- if ((g_gx_panda_context.pos_state - LEFT_TREE_LEFT) % 2 == 1)
- {
- g_gx_panda_context.state = FLYING;
- }
- }
- }
- else if (action == MMI_GX_PANDA_GO_RIGHT)
- {
- /* it's not in the rightmost position thus there is action happen */
- if (g_gx_panda_context.pos_state != RIGHT_TREE_RIGHT)
- {
- g_gx_panda_context.pos_state = g_gx_panda_context.pos_state + 1;
- if ((g_gx_panda_context.pos_state - LEFT_TREE_LEFT) % 2 == 0)
- {
- g_gx_panda_context.state = FLYING;
- }
- }
- }
- g_gx_panda_context.position.x = mmi_gx_panda_get_x_position(g_gx_panda_context.pos_state, MMI_GX_PANDA_IS_ROLE);
- /* adjust the X-position in FLYING state */
- if (g_gx_panda_context.state == FLYING)
- {
- g_gx_panda_context.position.x =
- (g_gx_panda_context.position.x +
- mmi_gx_panda_get_x_position(g_gx_panda_context.old_pos_state, MMI_GX_PANDA_IS_ROLE)) / 2;
- #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
- GFX_PLAY_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
- #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- GFX_PLAY_AUDIO_DVI(PandaBounce_dvi, PANDABOUNCE_DVI, DEVICE_AUDIO_PLAY_ONCE);
- #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_gameover
- * DESCRIPTION
- * Gameover function
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_gameover(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_gx_panda_context.is_gameover = TRUE;
- g_gx_panda_context.is_new_game = TRUE;
- /* call this function to draw gameover screen */
- mmi_gfx_entry_gameover_screen();
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_cyclic_timer
- * DESCRIPTION
- * Timer trigger function - looping
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_cyclic_timer(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_gx_panda_context.tick = g_gx_panda_context.tick + 1;
- gui_start_timer(g_gx_panda_context.timer_elapse, mmi_gx_panda_cyclic_timer);
- if (g_gx_panda_context.is_gameover == FALSE)
- {
- mmi_gx_panda_framemove();
- mmi_gx_panda_render();
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_key_2_press
- * DESCRIPTION
- * Key handling
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_key_2_press(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* if the role is dying, we don't need to process the key press */
- if (g_gx_panda_context.is_dying != FALSE)
- {
- return;
- }
- g_gx_panda_context.up_key_pressed = TRUE;
- #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
- GFX_PLAY_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
- #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- GFX_PLAY_AUDIO_DVI(PandaUp_down_dvi, PANDAUP_DOWN_DVI, DEVICE_AUDIO_PLAY_ONCE);
- #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_key_8_press
- * DESCRIPTION
- * Key handling
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_key_8_press(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* if the role is dying, we don't need to process the key press */
- if (g_gx_panda_context.is_dying != FALSE)
- {
- return;
- }
- g_gx_panda_context.down_key_pressed = TRUE;
- #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
- GFX_PLAY_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
- #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- GFX_PLAY_AUDIO_DVI(PandaUp_down_dvi, PANDAUP_DOWN_DVI, DEVICE_AUDIO_PLAY_ONCE);
- #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_key_5_press
- * DESCRIPTION
- * Key handling
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_key_5_press(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* if the role is dying or flying, we don't need to process the key press */
- if (g_gx_panda_context.is_dying != FALSE || g_gx_panda_context.state == FLYING)
- {
- return;
- }
- /* if at the button, cant go down anymore */
- if (g_gx_panda_context.position.y == MMI_GX_PANDA_LCD_HEIGHT - MMI_GX_PANDA_ROLE_HEIGHT - 1)
- {
- return;
- }
- g_gx_panda_context.state = ATTACK;
- g_gx_panda_context.down_key_pressed = TRUE;
- #ifdef __MMI_GAME_MULTICHANNEL_SOUND__
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.fail_wav);
- GFX_STOP_MULTICHANNEL_WAV(g_gx_panda_context.eating_wav);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.updown_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.bounce_midi);
- GFX_STOP_SOUND_EFFECTS_MIDI(g_gx_panda_context.hit_midi);
- GFX_PLAY_MULTICHANNEL_WAV(g_gx_panda_context.down_wav);
- #else /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- GFX_PLAY_AUDIO_DVI(PandaDown_dvi, PANDADOWN_DVI, DEVICE_AUDIO_PLAY_ONCE);
- #endif /* __MMI_GAME_MULTICHANNEL_SOUND__ */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_key_2_release
- * DESCRIPTION
- * Key handling
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_key_2_release(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_gx_panda_context.up_key_pressed = FALSE;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_key_8_release
- * DESCRIPTION
- * Key handling
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_key_8_release(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_gx_panda_context.down_key_pressed = FALSE;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_key_5_release
- * DESCRIPTION
- * Key handling
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_key_5_release(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_gx_panda_context.down_key_pressed = FALSE;
- g_gx_panda_context.state = NORMAL;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_key_4_press
- * DESCRIPTION
- * Key handling
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_key_4_press(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmi_gx_panda_turn_or_fly(MMI_GX_PANDA_GO_LEFT);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_key_6_press
- * DESCRIPTION
- * Key handling
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_gx_panda_key_6_press(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- mmi_gx_panda_turn_or_fly(MMI_GX_PANDA_GO_RIGHT);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_gx_panda_get_x_position
- * DESCRIPTION
- * Calculate the x position of objects from its position-state
- * PARAMETERS
- * state [IN] Current position-state of object.
- * type [IN] Type of object
- * RETURNS
- * The position in X-direction
- *****************************************************************************/
- S16 mmi_gx_panda_get_x_position(gx_panda_pos_state_enum state, U8 type)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 offset;
- S16 object_width;
- S16 result;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (type == MMI_GX_PANDA_IS_ROLE || type == MMI_GX_PANDA_IS_DYING_ROLE)
- {
- #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
- offset = 8;
- #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
- offset = 11;
- //KP Jerry add on 2007-3-23 start
- #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
- offset = 16;
- //KP Jerry add on 2007-3-23 end
- #endif
- object_width = MMI_GX_PANDA_ROLE_WIDTH;
- }
- else if (type == MMI_GX_PANDA_IS_ENEMY || type == MMI_GX_PANDA_IS_DYING_ENEMY)
- {
- offset = 2;
- object_width = MMI_GX_PANDA_ENEMY_WIDTH;
- }
- else if (type == MMI_GX_PANDA_IS_CLOCK)
- {
- switch (state)
- {
- case LEFT_SPACE:
- #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
- return 38;
- #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
- return 54;
- //KP Jerry add on 2007-3-23 start
- #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
- return 75;
- //KP Jerry add on 2007-3-23 end
- #endif
- break;
- case RIGHT_SPACE:
- #if defined(__MMI_GAME_PANDA_128x160__) || defined(__MMI_GAME_PANDA_128x128__) || defined(__MMI_GAME_MONKEY_128x160__) || defined(__MMI_GAME_MONKEY_128x128__)
- return 78;
- #elif defined(__MMI_GAME_PANDA_176x220__) || defined(__MMI_GAME_MONKEY_176x220__)
- return 109;
- //KP Jerry add on 2007-3-23 start
- #elif defined(__MMI_GAME_PANDA_240x320__) || defined(__MMI_GAME_MONKEY_240x320__)
- return 155;
- //KP Jerry add on 2007-3-23 end
- #endif
- break;
- }
- }
- switch (state)
- {
- case LEFT_TREE_LEFT:
- result = MMI_GX_PANDA_LEFT_PANDA - (object_width - offset);
- if (type == MMI_GX_PANDA_IS_DYING_ROLE)
- {
- result = result - 15;
- }
- else if (type == MMI_GX_PANDA_IS_DYING_ENEMY)
- {
- result = result - 5;
- }
- break;
- case LEFT_TREE_RIGHT:
- result = MMI_GX_PANDA_LEFT_PANDA + MMI_GX_PANDA_PANDA_WIDTH - offset;
- if (type == MMI_GX_PANDA_IS_DYING_ROLE)
- {
- result = result + 15;
- }
- else if (type == MMI_GX_PANDA_IS_DYING_ENEMY)
- {
- result = result + 5;
- }
- break;
- case MID_TREE_LEFT:
- result = MMI_GX_PANDA_MID_PANDA - (object_width - offset);
- if (type == MMI_GX_PANDA_IS_DYING_ROLE)
- {
- result = result - 15;
- }
- else if (type == MMI_GX_PANDA_IS_DYING_ENEMY)
- {
- result = result - 5;
- }
- break;
- case MID_TREE_RIGHT:
- result = MMI_GX_PANDA_MID_PANDA + MMI_GX_PANDA_PANDA_WIDTH - offset;
- if (type == MMI_GX_PANDA_IS_DYING_ROLE)
- {
- result = result + 15;
- }
- else if (type == MMI_GX_PANDA_IS_DYING_ENEMY)
- {
- result = result + 5;
- }
- break;
- case RIGHT_TREE_LEFT:
- result = MMI_GX_PANDA_RIGHT_PANDA - (object_width - offset);
- if (type == MMI_GX_PANDA_IS_DYING_ROLE)
- {
- result = result - 15;
- }
- else if (type == MMI_GX_PANDA_IS_DYING_ENEMY)
- {
- result = result - 5;
- }
- break;
- case RIGHT_TREE_RIGHT:
- result = MMI_GX_PANDA_RIGHT_PANDA + MMI_GX_PANDA_PANDA_WIDTH - offset;
- if (type == MMI_GX_PANDA_IS_DYING_ROLE)
- {
- result = result + 15;
- }
- else if (type == MMI_GX_PANDA_IS_DYING_ENEMY)
- {
- result = result + 5;
- }
- break;
- }
- return result;
- }
- //KP Jerry add on 2007-3-23 start
- #ifdef __MMI_TOUCH_SCREEN__
- typedef enum
- {
- PANDA_MOVE_NONE,
- PANDA_MOVE_UP,
- PANDA_MOVE_DOWN,
- PANDA_MOVE_LEFT,
- PANDA_MOVE_RIGHT,
- PANDA_MOVE_KILLENEMY
- }PANDA_MOVEMENT;
- static PANDA_MOVEMENT PandaState = PANDA_MOVE_NONE;
- /*****************************************************************************
- * FUNCTION
- * mmi_panda_is_panda_moveable
- * DESCRIPTION
- * get the panda move state
- * PARAMETERS
- * pos [IN]
- * RETURNS
- * void
- *****************************************************************************/
- PANDA_MOVEMENT mmi_panda_is_panda_moveable(S32 coord_x, S32 coord_y)
- {
- if(coord_x >= g_gx_panda_context.old_position.x && coord_x <= g_gx_panda_context.old_position.x + MMI_GX_PANDA_ROLE_WIDTH
- && coord_y >= g_gx_panda_context.old_position.y && coord_y <= g_gx_panda_context.old_position.y + MMI_GX_PANDA_ROLE_HEIGHT)
- {
- PandaState = PANDA_MOVE_KILLENEMY;
- return PANDA_MOVE_KILLENEMY;
- }
- else if(coord_x > g_gx_panda_context.old_position.x + MMI_GX_PANDA_ROLE_WIDTH)
- {
- PandaState = PANDA_MOVE_RIGHT;
- return PANDA_MOVE_RIGHT;
- }
- else if(coord_x < g_gx_panda_context.old_position.x )
- {
- PandaState = PANDA_MOVE_LEFT;
- return PANDA_MOVE_LEFT;
- }
- else if(coord_y > g_gx_panda_context.old_position.y)
- {
- PandaState = PANDA_MOVE_DOWN;
- return PANDA_MOVE_DOWN;
- }
- else if(coord_y < g_gx_panda_context.old_position.y)
- {
- PandaState = PANDA_MOVE_UP;
- return PANDA_MOVE_UP;
- }
- else
- {
- PandaState = PANDA_MOVE_NONE;
- return PANDA_MOVE_NONE;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_panda_pen_down_hdlr
- * DESCRIPTION
- *
- * PARAMETERS
- * pos [IN]
- * RETURNS
- * void
- *****************************************************************************/
-
- void mmi_panda_pen_down_hdlr(mmi_pen_point_struct pos)
- {
- S32 pos_x = pos.x, pos_y = pos.y;
- switch(mmi_panda_is_panda_moveable(pos_x,pos_y))
- {
- case PANDA_MOVE_UP:
- mmi_gx_panda_key_2_press();
- break;
- case PANDA_MOVE_DOWN:
- mmi_gx_panda_key_8_press();
- break;
- case PANDA_MOVE_LEFT:
- mmi_gx_panda_key_4_press();
- break;
- case PANDA_MOVE_RIGHT:
- mmi_gx_panda_key_6_press();
- break;
- case PANDA_MOVE_KILLENEMY:
- mmi_gx_panda_key_5_press();
- break;
- default:
- break;
- }
-
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_panda_pen_up_hdlr
- * DESCRIPTION
- *
- * PARAMETERS
- * pos [IN]
- * RETURNS
- * void
- *****************************************************************************/
-
- void mmi_panda_pen_up_hdlr(mmi_pen_point_struct pos)
- {
- switch(PandaState)
- {
- case PANDA_MOVE_UP:
- mmi_gx_panda_key_2_release();
- break;
- case PANDA_MOVE_DOWN:
- mmi_gx_panda_key_8_release();
- break;
- case PANDA_MOVE_LEFT:
- //mmi_gx_panda_key_2_release();
- break;
- case PANDA_MOVE_RIGHT:
- //mmi_gx_panda_key_8_release();
- break;
- case PANDA_MOVE_KILLENEMY:
- mmi_gx_panda_key_5_release();
- break;
- default:
- break;
- }
-
- }
- #endif /* __MMI_TOUCH_SCREEN__ */
- //KP Jerry add on 2007-3-23 end
- #endif /* IS_PANDA_BASE_GAME */