1793 lines
56 KiB
C
1793 lines
56 KiB
C
#include "include.h"
|
|
#include "func.h"
|
|
|
|
#if TRACE_EN
|
|
#define TRACE(...) printf(__VA_ARGS__)
|
|
#else
|
|
#define TRACE(...)
|
|
#endif
|
|
|
|
#define CENTER_X(w) ((GUI_SCREEN_WIDTH - w) >> 1)
|
|
#define GAME_ABS(x) ((x) > 0 ? (x) : (-(x)))
|
|
|
|
#define LEVEL_ICO_X 40 // 92
|
|
#define LEVEL_ICO_Y 4 // 18
|
|
#define LEVEL_X (LEVEL_ICO_X + 30)
|
|
#define LEVEL_Y (LEVEL_ICO_Y + 6)
|
|
|
|
#define SCORE_ICO_X (LEVEL_X + 40)
|
|
#define SCORE_ICO_Y LEVEL_ICO_Y
|
|
#define SCORE_X (SCORE_ICO_X + 30)
|
|
#define SCORE_Y (LEVEL_Y)
|
|
|
|
#define DLG_BG_CX 130
|
|
#define DLG_BG_X CENTER_X(DLG_BG_CX)
|
|
#define DLG_BG_Y 120
|
|
|
|
#define PASS_LABLE_X CENTER_X(49)
|
|
#define PASS_LABLE_Y (DLG_BG_Y + 15)
|
|
|
|
#define PASS_DLG_BTN_CX 84
|
|
#define PASS_DLG_BTN_CY 28
|
|
|
|
#define PASS_DLG_BTN_START_X CENTER_X(PASS_DLG_BTN_CX)
|
|
#define PASS_DLG_BTN_START_Y (PASS_LABLE_Y + 28)
|
|
|
|
#define PASS_DLG_BTN_END_X (PASS_DLG_BTN_START_X + PASS_DLG_BTN_CX)
|
|
#define PASS_DLG_BTN_END_Y (PASS_DLG_BTN_START_Y + PASS_DLG_BTN_CY)
|
|
|
|
#define PASS_ALL_LABLE_X CENTER_X(115)
|
|
#define PASS_ALL_LABLE_Y PASS_LABLE_Y
|
|
|
|
#define GAME_OVER_LABLE_X CENTER_X(100)
|
|
#define GAME_OVER_LABLE_Y PASS_LABLE_Y
|
|
|
|
#define GAME_OVER_BTN_OK_CX 64
|
|
#define GAME_OVER_BTN_OK_CY 28
|
|
|
|
#define BTN_OK_START_X CENTER_X(64)
|
|
#define BTN_OK_START_Y PASS_DLG_BTN_START_Y
|
|
|
|
#define NORMAL_BARRIER 0x00
|
|
#define RLS_UP_BARRIER 0x10 /*释放上面的障碍物*/
|
|
#define RLS_DOWN_BARRIER 0x20 /*释放下面的障碍物*/
|
|
#define RLS_UPDOWN_BARRIER 0x30 /*释放上面和下面的障碍物*/
|
|
|
|
#define BARRIER_TYPE_NUM BARRIER_UP_DOWN
|
|
|
|
#define RESOURCE_CX 32
|
|
#define RESOURCE_CY 32
|
|
#define BARRIER_1_CX 26
|
|
#define BARRIER_1_CY 26
|
|
|
|
#define BIRD_FLY_V 12 /*小鸟向上飞行初速度*/
|
|
#define BIRD_FALL_G 2 /*小鸟向下掉的重力加速度*/
|
|
|
|
#define BIRDFLY_ZOOM_X 0
|
|
#define BIRDFLY_ZOOM_Y 30
|
|
#define BIRDFLY_ZOOM_CX 240
|
|
#define BIRDFLY_ZOOM_CY 264
|
|
|
|
#define BIRDFLY_GROUND_HEIGHT 0 // 地面高度
|
|
|
|
#define BIRD_VALID_STARTX 2
|
|
#define BIRD_VALID_STARTY 16
|
|
|
|
#define BIRD_VALID_ENDX 62
|
|
#define BIRD_VALID_ENDY 46
|
|
|
|
#define BIRD_VALID_WIDTH (BIRD_VALID_ENDX - BIRD_VALID_STARTX)
|
|
#define BIRD_VALID_HEIGHT (BIRD_VALID_ENDY - BIRD_VALID_STARTY)
|
|
|
|
#define BIRD_WIDTH 54
|
|
#define BIRD_HEIGHT 54
|
|
|
|
#define HIT_WIDTH 59
|
|
#define HIT_HEIGHT 59
|
|
#define START_HEIGHT 82
|
|
|
|
#define MAX_RESOURCE_DATA_NUM 10 /* 资源数据个数*/
|
|
#define MAX_BARRIER_DATA_NUM 4 /* 障碍物数据个数*/
|
|
|
|
#define MAX_BARRIER_NUM 4 /* 最多障碍物块个数 */
|
|
#define SCORE_MAX_NUM 4 /* 得分最多位数 */
|
|
|
|
#define BIRDFLY_ANI_TIME_GAP 40
|
|
#define BIRDFLY_TIME_GAP 80
|
|
#define QUICKFLY_TIMEOUT_TIME 5000 // 快速飞5秒
|
|
#define RLS_BARRIER_TIMEOUT_TIME 5000
|
|
|
|
#define INIT_MAKE_BARRIER_TIME 60
|
|
#define INIT_MAKE_RESOURCE_RAND_MAX_NUM 360
|
|
|
|
#define DIGIT_CX 14
|
|
|
|
enum
|
|
{
|
|
LEVENT_NULL,
|
|
LEVENT_READY,
|
|
LEVENT_BIRD_FLYING_ON, // 向上飞
|
|
LEVENT_BIRD_GLIDING, // 滑翔模式
|
|
LEVENT_BIRD_QUICK_RIGHT_FLY, // 快速右飞
|
|
LEVENT_BIRD_DIE_FALLDOWN, // 小鸟被撞死
|
|
|
|
LEVENT_GAMEOVER_DLG,
|
|
};
|
|
|
|
enum
|
|
{
|
|
RES_NULL,
|
|
RES_GOLD,
|
|
RES_UP,
|
|
RES_DOWN,
|
|
RES_UP_DOWN,
|
|
RES_RIGHT,
|
|
RES_LIFE,
|
|
RES_DEATH
|
|
};
|
|
|
|
enum
|
|
{
|
|
BARRIER_NULL,
|
|
BARRIER_UP,
|
|
BARRIER_DOWN,
|
|
BARRIER_UP_DOWN
|
|
};
|
|
|
|
typedef struct Bird_st
|
|
{
|
|
short x; // 该小鸟x坐标
|
|
short y; // 该小鸟y坐标
|
|
short cx; // 该飞机图标的宽度
|
|
short cy; // 该飞机图标的高度
|
|
u8 idx;
|
|
u8 flag; // 为0表示不显示任何图标, 即无数据
|
|
u8 reserved[2];
|
|
} Bird_t;
|
|
|
|
typedef struct Resource_st
|
|
{
|
|
short x; // 该资源x坐标
|
|
short y; // 该资源y坐标
|
|
short cx; // 该资源图标的宽度
|
|
short cy; // 该资源图标的高度
|
|
u8 idx;
|
|
u8 attrib; // 资源属性: 0: 无资源; 1:金币; 2: UP; 3:DOWN; 4: UP_DOWN; 5: RIGHT; 6: LIFE; 7: DEATH;
|
|
u8 reserved[2];
|
|
} Resource_t;
|
|
|
|
typedef struct Barrier_st
|
|
{
|
|
short x; // 该障碍物x坐标
|
|
short cx; // 该障碍物宽度
|
|
short cy; // 该障碍物高度
|
|
u8 attrib; // 障碍物属性, 0:表示无障碍物
|
|
u8 num; //
|
|
u8 reserved[3]; //
|
|
} Barrier_t;
|
|
|
|
typedef struct f_game_t_
|
|
{
|
|
/* 游戏运行参数 */
|
|
Bird_t *pBird;
|
|
Bird_t *pBirdHit;
|
|
Barrier_t *pBarrier;
|
|
Resource_t *pResource;
|
|
|
|
u8 bird_num; // 剩余小鸟个数
|
|
u8 gold_spin_idx;
|
|
u8 BirdFly_status;
|
|
u8 Barrier_status;
|
|
bool has_to_redraw;
|
|
|
|
short bird_y_speed; // 小鸟速度, >0: 向上飞; <0: 向下掉
|
|
u16 make_barrier_time;
|
|
u16 make_resource_max_rand;
|
|
|
|
u32 x_offset;
|
|
u32 game_score;
|
|
|
|
/* 游戏运行任务*/
|
|
bool bird_fly_task_flag;
|
|
bool animation_task_flag;
|
|
bool quick_fly_task_flag;
|
|
bool rls_barrier_task_flag;
|
|
|
|
u32 bird_fly_task_tick;
|
|
u32 animation_task_tick;
|
|
u32 quick_fly_task_tick;
|
|
u32 rls_barrier_task_tick;
|
|
} f_game_t;
|
|
|
|
enum
|
|
{
|
|
COMPO_ID_GAME_PIC_BG = 0x01,
|
|
COMPO_ID_GAME_PIC_BIRD,
|
|
COMPO_ID_GAME_PIC_START,
|
|
|
|
/* 障碍物 */
|
|
COMPO_ID_GAME_PIC_BARRIER,
|
|
COMPO_ID_GAME_PIC_BARRIER_MAX = COMPO_ID_GAME_PIC_BARRIER + (MAX_BARRIER_NUM * MAX_BARRIER_DATA_NUM * 2),
|
|
|
|
/* 资源 */
|
|
COMPO_ID_GAME_RESOURCE_PIC,
|
|
COMPO_ID_GAME_RESOURCE_PIC_MAX = COMPO_ID_GAME_RESOURCE_PIC + MAX_RESOURCE_DATA_NUM,
|
|
|
|
/* 小鸟生命 */
|
|
COMPO_ID_GAME_PIC_BIRD_LIFE,
|
|
COMPO_ID_GAME_PIC_BIRD_LIFE_MAX = COMPO_ID_GAME_PIC_BIRD_LIFE + SCORE_MAX_NUM,
|
|
|
|
/* 得分 */
|
|
COMPO_ID_GAME_PIC_SCORE,
|
|
COMPO_ID_GAME_PIC_SCORE_MAX = COMPO_ID_GAME_PIC_SCORE + SCORE_MAX_NUM,
|
|
|
|
/* 击中 */
|
|
COMPO_ID_GAME_PIC_BOOM,
|
|
|
|
/* 游戏结束 */
|
|
COMPO_ID_GAME_PIC_END_BG,
|
|
COMPO_ID_GAME_BTN_END_ANEW,
|
|
COMPO_ID_GAME_BTN_END_EXIT,
|
|
};
|
|
|
|
static const u32 Flying_Bird_Pic_arr[] = {
|
|
UI_BUF_GAME_BIRD_FLY0_BIN,
|
|
UI_BUF_GAME_BIRD_FLY1_BIN,
|
|
UI_BUF_GAME_BIRD_FLY2_BIN,
|
|
UI_BUF_GAME_BIRD_FLY3_BIN,
|
|
UI_BUF_GAME_BIRD_FLY4_BIN};
|
|
|
|
static const u32 Hit_Bird_Boom_pic_arr[] = {
|
|
UI_BUF_GAME_HIT_0_BIN,
|
|
UI_BUF_GAME_HIT_1_BIN,
|
|
UI_BUF_GAME_HIT_2_BIN,
|
|
UI_BUF_GAME_HIT_3_BIN,
|
|
UI_BUF_GAME_HIT_4_BIN,
|
|
UI_BUF_GAME_HIT_5_BIN};
|
|
|
|
static const u32 Death_Bird_Fall_pic_arr[] = {
|
|
UI_BUF_GAME_BIRD_FALL0_BIN,
|
|
UI_BUF_GAME_BIRD_FALL1_BIN,
|
|
UI_BUF_GAME_BIRD_FALL2_BIN,
|
|
UI_BUF_GAME_BIRD_FALL3_BIN,
|
|
UI_BUF_GAME_BIRD_FALL4_BIN,
|
|
UI_BUF_GAME_BIRD_FALL5_BIN,
|
|
UI_BUF_GAME_BIRD_FALL6_BIN,
|
|
UI_BUF_GAME_BIRD_FALL7_BIN,
|
|
UI_BUF_GAME_BIRD_FALL8_BIN,
|
|
UI_BUF_GAME_BIRD_FALL9_BIN,
|
|
};
|
|
|
|
static const u32 gold_pic_arr[] = {
|
|
UI_BUF_GAME_GOLD_0_BIN,
|
|
UI_BUF_GAME_GOLD_1_BIN,
|
|
UI_BUF_GAME_GOLD_2_BIN,
|
|
UI_BUF_GAME_GOLD_3_BIN,
|
|
UI_BUF_GAME_GOLD_4_BIN,
|
|
UI_BUF_GAME_GOLD_5_BIN,
|
|
UI_BUF_GAME_GOLD_6_BIN,
|
|
UI_BUF_GAME_GOLD_7_BIN,
|
|
};
|
|
|
|
static const u32 digit_id_arr[] = {
|
|
UI_BUF_GAME_GAME_DIGIT_0_BIN,
|
|
UI_BUF_GAME_GAME_DIGIT_1_BIN,
|
|
UI_BUF_GAME_GAME_DIGIT_2_BIN,
|
|
UI_BUF_GAME_GAME_DIGIT_3_BIN,
|
|
UI_BUF_GAME_GAME_DIGIT_4_BIN,
|
|
UI_BUF_GAME_GAME_DIGIT_5_BIN,
|
|
UI_BUF_GAME_GAME_DIGIT_6_BIN,
|
|
UI_BUF_GAME_GAME_DIGIT_7_BIN,
|
|
UI_BUF_GAME_GAME_DIGIT_8_BIN,
|
|
UI_BUF_GAME_GAME_DIGIT_9_BIN,
|
|
};
|
|
|
|
void tjd_show_game_over_dlg(void)
|
|
{
|
|
compo_button_t *anew_btn = compo_getobj_byid(COMPO_ID_GAME_BTN_END_ANEW);
|
|
compo_button_t *exit_btn = compo_getobj_byid(COMPO_ID_GAME_BTN_END_EXIT);
|
|
compo_picturebox_t *bg_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_END_BG);
|
|
|
|
compo_button_set_visible(anew_btn, true);
|
|
compo_button_set_visible(exit_btn, true);
|
|
compo_picturebox_set_visible(bg_pic, true);
|
|
}
|
|
|
|
static void tjd_malloc_bird_fly_buffer(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
if (!game->pBird)
|
|
{
|
|
game->pBird = func_zalloc(sizeof(Bird_t));
|
|
}
|
|
if (!game->pBirdHit)
|
|
{
|
|
game->pBirdHit = func_zalloc(sizeof(Bird_t));
|
|
}
|
|
|
|
if (!game->pResource)
|
|
{
|
|
game->pResource = func_zalloc(sizeof(Resource_t) * MAX_RESOURCE_DATA_NUM);
|
|
}
|
|
if (!game->pBarrier)
|
|
{
|
|
game->pBarrier = func_zalloc(sizeof(Barrier_t) * MAX_BARRIER_DATA_NUM);
|
|
}
|
|
}
|
|
|
|
static void tjd_free_bird_fly_buffer(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
if (game->pBird)
|
|
{
|
|
func_free(game->pBird);
|
|
game->pBird = NULL;
|
|
}
|
|
if (game->pBirdHit)
|
|
{
|
|
func_free(game->pBirdHit);
|
|
game->pBirdHit = NULL;
|
|
}
|
|
if (game->pResource)
|
|
{
|
|
func_free(game->pResource);
|
|
game->pResource = NULL;
|
|
}
|
|
if (game->pBarrier)
|
|
{
|
|
func_free(game->pBarrier);
|
|
game->pBarrier = NULL;
|
|
}
|
|
}
|
|
|
|
static void tjd_init_birdfly_data(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
game->x_offset = 0;
|
|
game->bird_y_speed = 0; // 小鸟速度, >0: 向上飞; <0: 向下掉
|
|
|
|
game->pBird->x = BIRDFLY_ZOOM_X + CENTER_X(BIRD_WIDTH);
|
|
game->pBird->y = BIRDFLY_ZOOM_Y + ((BIRDFLY_ZOOM_CY - BIRDFLY_GROUND_HEIGHT - BIRD_HEIGHT) >> 1);
|
|
game->pBird->cx = BIRD_VALID_WIDTH;
|
|
game->pBird->cy = BIRD_VALID_HEIGHT;
|
|
game->pBird->idx = 4;
|
|
game->pBird->flag = 1;
|
|
}
|
|
|
|
void tjd_ready_birdfly(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
game->has_to_redraw = TRUE;
|
|
|
|
tjd_init_birdfly_data();
|
|
|
|
memset(game->pBirdHit, 0, sizeof(Bird_t));
|
|
memset(game->pResource, 0, sizeof(Resource_t) * MAX_RESOURCE_DATA_NUM);
|
|
memset(game->pBarrier, 0, sizeof(Barrier_t) * MAX_BARRIER_DATA_NUM);
|
|
|
|
game->BirdFly_status = LEVENT_READY;
|
|
}
|
|
|
|
void tjd_reset_birdfly(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
game->has_to_redraw = TRUE;
|
|
game->game_score = 0;
|
|
game->bird_num = 1; // 剩余小鸟个数
|
|
game->make_barrier_time = INIT_MAKE_BARRIER_TIME;
|
|
game->make_resource_max_rand = INIT_MAKE_RESOURCE_RAND_MAX_NUM;
|
|
|
|
tjd_init_birdfly_data();
|
|
memset(game->pBirdHit, 0, sizeof(Bird_t));
|
|
memset(game->pResource, 0, sizeof(Resource_t) * MAX_RESOURCE_DATA_NUM);
|
|
memset(game->pBarrier, 0, sizeof(Barrier_t) * MAX_BARRIER_DATA_NUM);
|
|
|
|
game->BirdFly_status = LEVENT_READY;
|
|
}
|
|
|
|
static void tjd_birdfly_start_play(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
game->bird_fly_task_flag = true;
|
|
|
|
game->animation_task_flag = true;
|
|
}
|
|
|
|
void tjd_birdfly_stop(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
game->bird_fly_task_flag = false;
|
|
|
|
game->animation_task_flag = false;
|
|
|
|
game->quick_fly_task_flag = false;
|
|
|
|
game->rls_barrier_task_flag = false;
|
|
}
|
|
|
|
static void tjd_change_all_resource_to_gold(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
u16 i;
|
|
Resource_t *pRes;
|
|
|
|
for (i = 0; i < MAX_RESOURCE_DATA_NUM; i++)
|
|
{
|
|
pRes = game->pResource + i;
|
|
if (pRes->attrib)
|
|
{
|
|
pRes->attrib = RES_GOLD;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void tjd_end_rls_barrier_mode(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
// printf("<<<<<<< NORMAL_BARRIER >>>>>>>>>>");
|
|
game->rls_barrier_task_flag = false;
|
|
game->Barrier_status = NORMAL_BARRIER;
|
|
}
|
|
|
|
static void set_rls_barrier_mode(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
game->rls_barrier_task_flag = true;
|
|
game->rls_barrier_task_tick = tick_get();
|
|
}
|
|
|
|
static void tjd_end_quick_fly_mode(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
game->quick_fly_task_flag = false;
|
|
game->Barrier_status = NORMAL_BARRIER;
|
|
game->BirdFly_status = LEVENT_BIRD_GLIDING;
|
|
}
|
|
|
|
static void set_quick_fly_mode(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
game->quick_fly_task_tick = tick_get();
|
|
game->quick_fly_task_flag = true;
|
|
}
|
|
|
|
static void tjd_bird_die(Bird_t *pBird)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
if (game->bird_num > 0)
|
|
{
|
|
game->bird_num--;
|
|
}
|
|
|
|
game->pBirdHit->x = pBird->x + (BIRD_WIDTH >> 1) - (HIT_WIDTH >> 1);
|
|
game->pBirdHit->y = pBird->y + (BIRD_HEIGHT >> 1) - (HIT_HEIGHT >> 1);
|
|
|
|
game->pBirdHit->cx = HIT_WIDTH;
|
|
game->pBirdHit->cy = HIT_HEIGHT;
|
|
game->pBirdHit->idx = 0;
|
|
game->pBirdHit->flag = 1;
|
|
}
|
|
|
|
// 检查小鸟是否得到资源
|
|
static bool tjd_check_bird_get_resource(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
u16 i;
|
|
long x1, x2, y1, y2, xd, yd;
|
|
short delta_x, delta_y;
|
|
Resource_t *pRes;
|
|
|
|
x1 = game->pBird->x + (BIRD_WIDTH >> 1);
|
|
y1 = game->pBird->y + (BIRD_HEIGHT >> 1);
|
|
for (i = 0; i < MAX_RESOURCE_DATA_NUM; i++)
|
|
{
|
|
pRes = game->pResource + i;
|
|
if (pRes->attrib)
|
|
{
|
|
x2 = pRes->x + (pRes->cx >> 1);
|
|
y2 = pRes->y + (pRes->cy >> 1);
|
|
xd = ((BIRD_VALID_WIDTH + RESOURCE_CX) >> 1) - 4;
|
|
yd = ((BIRD_VALID_HEIGHT + RESOURCE_CY) >> 1) - 2;
|
|
delta_x = GAME_ABS(x1 - x2);
|
|
delta_y = GAME_ABS(y1 - y2);
|
|
if (delta_x < xd && delta_y < yd)
|
|
{
|
|
// Get到资源
|
|
if (pRes->attrib == RES_GOLD)
|
|
{
|
|
game->game_score += 1;
|
|
}
|
|
else if (pRes->attrib == RES_UP)
|
|
{
|
|
if (game->Barrier_status == NORMAL_BARRIER)
|
|
{
|
|
set_rls_barrier_mode();
|
|
game->Barrier_status = RLS_UP_BARRIER;
|
|
}
|
|
}
|
|
else if (pRes->attrib == RES_DOWN)
|
|
{
|
|
if (game->Barrier_status == NORMAL_BARRIER)
|
|
{
|
|
set_rls_barrier_mode();
|
|
game->Barrier_status = RLS_DOWN_BARRIER;
|
|
}
|
|
}
|
|
else if (pRes->attrib == RES_UP_DOWN)
|
|
{
|
|
if (game->Barrier_status == NORMAL_BARRIER)
|
|
{
|
|
set_rls_barrier_mode();
|
|
game->Barrier_status = RLS_UPDOWN_BARRIER;
|
|
}
|
|
}
|
|
else if (pRes->attrib == RES_RIGHT)
|
|
{
|
|
game->BirdFly_status = LEVENT_BIRD_QUICK_RIGHT_FLY;
|
|
game->Barrier_status = RLS_UPDOWN_BARRIER;
|
|
tjd_change_all_resource_to_gold();
|
|
game->pBird->y = BIRDFLY_ZOOM_Y + (BIRDFLY_ZOOM_CY >> 1) - (BIRD_HEIGHT >> 1);
|
|
game->pBird->idx = 4; // 展翅的图片
|
|
set_quick_fly_mode();
|
|
}
|
|
else if (pRes->attrib == RES_LIFE)
|
|
{
|
|
game->bird_num += 1;
|
|
}
|
|
else if (pRes->attrib == RES_DEATH)
|
|
{
|
|
game->BirdFly_status = LEVENT_BIRD_DIE_FALLDOWN;
|
|
game->pBird->idx = 0;
|
|
game->bird_y_speed = 0;
|
|
tjd_bird_die(game->pBird);
|
|
}
|
|
pRes->attrib = 0;
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
#define X_DEVIATION 2
|
|
#define Y_DEVIATION 2
|
|
|
|
// 检查小鸟是否撞到障碍物
|
|
static bool tjd_check_bird_ram_barrier(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
u16 i;
|
|
long x1, x2, xd, yd, y1, y2;
|
|
Barrier_t *pBarrier;
|
|
if (LEVENT_BIRD_FLYING_ON != game->BirdFly_status // 正常飞翔模式
|
|
&& LEVENT_BIRD_GLIDING != game->BirdFly_status // 滑翔模式
|
|
&& LEVENT_BIRD_QUICK_RIGHT_FLY != game->BirdFly_status) // 快速右飞
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
x1 = game->pBird->x + (BIRD_WIDTH >> 1);
|
|
y1 = game->pBird->y + (BIRD_HEIGHT >> 1);
|
|
for (i = 0; i < MAX_BARRIER_DATA_NUM; i++)
|
|
{
|
|
pBarrier = game->pBarrier + i;
|
|
|
|
if (pBarrier->attrib == BARRIER_UP)
|
|
{
|
|
if ((game->Barrier_status != RLS_UP_BARRIER && game->Barrier_status != RLS_UPDOWN_BARRIER))
|
|
{
|
|
x2 = pBarrier->x + (pBarrier->cx >> 1);
|
|
xd = ((BIRD_VALID_WIDTH + pBarrier->cx) >> 1) - X_DEVIATION;
|
|
if (GAME_ABS(x1 - x2) < xd)
|
|
{
|
|
y2 = BIRDFLY_ZOOM_Y + pBarrier->cy * pBarrier->num;
|
|
yd = GAME_ABS(y1 - y2) - Y_DEVIATION;
|
|
// if (yd <= (BIRD_VALID_HEIGHT>>1))
|
|
if (game->pBird->y <= y2)
|
|
{
|
|
// 撞击到上边沿
|
|
|
|
game->BirdFly_status = LEVENT_BIRD_DIE_FALLDOWN;
|
|
game->pBird->idx = 0;
|
|
game->bird_y_speed = 0;
|
|
tjd_bird_die(game->pBird);
|
|
// printf("BIRD RAM A \n x1:%d, y1:%d, x2:%d, y2:%d, xd:%d, yd:%d\n", x1, y1, x2, y2, xd, yd);
|
|
if (game->pBird->x + (BIRD_WIDTH >> 1) < pBarrier->x)
|
|
{
|
|
game->pBird->x -= 6;
|
|
}
|
|
return FALSE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (pBarrier->attrib == BARRIER_DOWN)
|
|
{
|
|
if ((game->Barrier_status != RLS_DOWN_BARRIER && game->Barrier_status != RLS_UPDOWN_BARRIER))
|
|
{
|
|
x2 = pBarrier->x + (pBarrier->cx >> 1);
|
|
xd = ((BIRD_VALID_WIDTH + pBarrier->cx) >> 1) - X_DEVIATION;
|
|
if (GAME_ABS(x1 - x2) < xd)
|
|
{
|
|
y2 = BIRDFLY_ZOOM_Y + BIRDFLY_ZOOM_CY - pBarrier->cy * pBarrier->num;
|
|
yd = GAME_ABS(y1 - y2) - Y_DEVIATION;
|
|
if ((y1 + (BIRD_VALID_HEIGHT >> 1)) >= y2) //(yd <= (BIRD_VALID_HEIGHT>>1))
|
|
{
|
|
// 撞击到下边沿
|
|
game->BirdFly_status = LEVENT_BIRD_DIE_FALLDOWN;
|
|
game->pBird->idx = 0;
|
|
game->bird_y_speed = 0;
|
|
tjd_bird_die(game->pBird);
|
|
// printf("BIRD RAM B x1:%d, y1:%d, x2:%d, y2:%d, xd:%d, yd:%d, num:%d\n", x1, y1, x2, y2, xd, yd, pBarrier->num);
|
|
if (game->pBird->x + (BIRD_VALID_WIDTH >> 1) > pBarrier->x)
|
|
{
|
|
game->pBird->x = pBarrier->x + pBarrier->cx;
|
|
}
|
|
else
|
|
{
|
|
game->pBird->x -= 6;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (pBarrier->attrib == BARRIER_UP_DOWN)
|
|
{
|
|
x2 = pBarrier->x + (pBarrier->cx >> 1);
|
|
xd = ((BIRD_VALID_WIDTH + pBarrier->cx) >> 1) - X_DEVIATION;
|
|
if (GAME_ABS(x1 - x2) < xd)
|
|
{
|
|
if ((game->Barrier_status != RLS_UP_BARRIER && game->Barrier_status != RLS_UPDOWN_BARRIER))
|
|
{
|
|
y2 = BIRDFLY_ZOOM_Y + pBarrier->cy * pBarrier->num - Y_DEVIATION;
|
|
yd = GAME_ABS(y1 - y2) - Y_DEVIATION;
|
|
if ((y1 - (BIRD_VALID_HEIGHT >> 1)) <= y2) //(yd <= (BIRD_VALID_HEIGHT>>1))
|
|
{
|
|
// 撞击到上边沿
|
|
game->BirdFly_status = LEVENT_BIRD_DIE_FALLDOWN;
|
|
game->bird_y_speed = 0;
|
|
game->pBird->idx = 0;
|
|
tjd_bird_die(game->pBird);
|
|
// printf("BIRD RAM C x1:%d, y1:%d, x2:%d, y2:%d, xd:%d, yd:%d\n", x1, y1, x2, y2, xd, yd);
|
|
|
|
if (game->pBird->x + (BIRD_WIDTH >> 1) < pBarrier->x)
|
|
{
|
|
game->pBird->x -= 6;
|
|
}
|
|
return FALSE;
|
|
}
|
|
}
|
|
if ((game->Barrier_status != RLS_DOWN_BARRIER && game->Barrier_status != RLS_UPDOWN_BARRIER))
|
|
{
|
|
y2 = BIRDFLY_ZOOM_Y + BIRDFLY_ZOOM_CY - pBarrier->cy * (MAX_BARRIER_NUM - pBarrier->num);
|
|
yd = GAME_ABS(y1 - y2) - Y_DEVIATION;
|
|
if ((y1 + (BIRD_VALID_HEIGHT >> 1)) >= y2) //(yd <= (BIRD_VALID_HEIGHT>>1))
|
|
{
|
|
// 撞击到下边沿
|
|
game->BirdFly_status = LEVENT_BIRD_DIE_FALLDOWN;
|
|
game->bird_y_speed = 0;
|
|
// 小鸟被撞击到地面
|
|
game->pBird->idx = 0;
|
|
tjd_bird_die(game->pBird);
|
|
// printf("BIRD RAM D x1:%d, y1:%d, x2:%d, y2:%d, xd:%d, yd:%d, num:%d\n", x1, y1, x2, y2, xd, yd, pBarrier->num);
|
|
|
|
if (game->pBird->x + (BIRD_WIDTH >> 1) > pBarrier->x)
|
|
{
|
|
game->pBird->x = pBarrier->x + pBarrier->cx;
|
|
}
|
|
else
|
|
{
|
|
game->pBird->x -= 6;
|
|
}
|
|
return FALSE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
static void tjd_birdfly_send_draw_evt(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
game->has_to_redraw = TRUE;
|
|
}
|
|
|
|
void tjd_show_digit(u16 x, u16 y, char *pDigitStr, u32 id)
|
|
{
|
|
u16 i;
|
|
char *pStr;
|
|
u32 temp;
|
|
pStr = pDigitStr;
|
|
|
|
/* 显示得分 */
|
|
for (i = 0; i < SCORE_MAX_NUM && *pStr; i++)
|
|
{
|
|
compo_picturebox_t *digit_pic = compo_getobj_byid(id + i);
|
|
|
|
if (*pStr >= '0' && *pStr <= '9')
|
|
{
|
|
temp = *pStr - '0';
|
|
|
|
compo_picturebox_set(digit_pic, digit_id_arr[temp]);
|
|
compo_picturebox_set_pos(digit_pic, x, y);
|
|
compo_picturebox_set_visible(digit_pic, true);
|
|
|
|
x += DIGIT_CX;
|
|
}
|
|
pStr++;
|
|
}
|
|
|
|
/* 隐藏掉不需要显示部分 */
|
|
for (; i < SCORE_MAX_NUM; i++)
|
|
{
|
|
compo_picturebox_t *digit_pic = compo_getobj_byid(id + i);
|
|
compo_picturebox_set_visible(digit_pic, false);
|
|
}
|
|
}
|
|
|
|
void tjd_show_score(u16 x, u16 y, u32 score)
|
|
{
|
|
char str[6] = {0};
|
|
sprintf(str, "%d", score);
|
|
|
|
tjd_show_digit(x + 32, y + 3, str, COMPO_ID_GAME_PIC_SCORE);
|
|
}
|
|
|
|
static void tjd_make_resource(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
static u8 re_idx = 0;
|
|
Resource_t *pRes;
|
|
if (LEVENT_BIRD_QUICK_RIGHT_FLY == game->BirdFly_status)
|
|
{
|
|
pRes = game->pResource + re_idx;
|
|
pRes->idx = 0;
|
|
pRes->attrib = RES_GOLD;
|
|
pRes->cx = RESOURCE_CX;
|
|
pRes->cy = RESOURCE_CY;
|
|
|
|
pRes->x = BIRDFLY_ZOOM_X + BIRDFLY_ZOOM_CX;
|
|
pRes->y = BIRDFLY_ZOOM_Y + (BIRDFLY_ZOOM_CY >> 1) - (RESOURCE_CY >> 1);
|
|
re_idx++;
|
|
if (re_idx >= MAX_RESOURCE_DATA_NUM)
|
|
{
|
|
re_idx = 0;
|
|
}
|
|
}
|
|
else if (LEVENT_BIRD_FLYING_ON == game->BirdFly_status || LEVENT_BIRD_GLIDING == game->BirdFly_status)
|
|
{
|
|
u8 rand;
|
|
rand = get_random(game->make_resource_max_rand);
|
|
|
|
pRes = game->pResource + re_idx;
|
|
pRes->idx = 0;
|
|
pRes->cx = RESOURCE_CX;
|
|
pRes->cy = RESOURCE_CY;
|
|
pRes->x = BIRDFLY_ZOOM_X + BIRDFLY_ZOOM_CX;
|
|
pRes->y = BIRDFLY_ZOOM_Y + (BIRDFLY_ZOOM_CY >> 1) - (RESOURCE_CY >> 1);
|
|
|
|
if (rand == 0 || rand == 1 || rand == 2)
|
|
{
|
|
pRes->attrib = RES_DEATH;
|
|
if (game->make_resource_max_rand >= 10)
|
|
{
|
|
game->make_resource_max_rand--;
|
|
}
|
|
}
|
|
else if (rand == 10)
|
|
{
|
|
pRes->attrib = RES_UP;
|
|
if (game->make_resource_max_rand >= 10)
|
|
{
|
|
game->make_resource_max_rand--;
|
|
}
|
|
}
|
|
else if (rand == 15)
|
|
{
|
|
pRes->attrib = RES_DOWN;
|
|
if (game->make_resource_max_rand >= 10)
|
|
{
|
|
game->make_resource_max_rand--;
|
|
}
|
|
}
|
|
else if (rand == 20)
|
|
{
|
|
pRes->attrib = RES_UP_DOWN;
|
|
if (game->make_resource_max_rand >= 10)
|
|
{
|
|
game->make_resource_max_rand--;
|
|
}
|
|
}
|
|
else if (rand == 30 || rand == 31 || rand == 32 || rand == 32)
|
|
{
|
|
pRes->attrib = RES_RIGHT;
|
|
if (game->make_resource_max_rand >= 10)
|
|
{
|
|
game->make_resource_max_rand--;
|
|
}
|
|
}
|
|
else if (rand == 50)
|
|
{
|
|
pRes->attrib = RES_LIFE;
|
|
if (game->make_resource_max_rand >= 10)
|
|
{
|
|
game->make_resource_max_rand--;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
pRes->attrib = RES_GOLD;
|
|
if (game->make_resource_max_rand >= 10)
|
|
{
|
|
game->make_resource_max_rand--;
|
|
}
|
|
}
|
|
|
|
re_idx++;
|
|
if (re_idx >= MAX_RESOURCE_DATA_NUM)
|
|
{
|
|
re_idx = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void tjd_make_barrier(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
static u8 Barrier_idx = 0;
|
|
Barrier_t *pBarrier;
|
|
|
|
// printf("Barrier_idx:%d\n", Barrier_idx);
|
|
|
|
pBarrier = game->pBarrier + Barrier_idx;
|
|
pBarrier->x = BIRDFLY_ZOOM_X + BIRDFLY_ZOOM_CX + BARRIER_1_CX;
|
|
pBarrier->cx = BARRIER_1_CX;
|
|
pBarrier->cy = BARRIER_1_CY;
|
|
pBarrier->attrib = get_random(BARRIER_TYPE_NUM) + 1;
|
|
if (pBarrier->attrib == BARRIER_UP_DOWN)
|
|
{
|
|
pBarrier->num = get_random(MAX_BARRIER_NUM - 1) + 1;
|
|
}
|
|
else
|
|
{
|
|
pBarrier->num = get_random(MAX_BARRIER_NUM) + 1;
|
|
}
|
|
Barrier_idx++;
|
|
if (Barrier_idx >= MAX_BARRIER_DATA_NUM)
|
|
{
|
|
Barrier_idx = 0;
|
|
}
|
|
}
|
|
|
|
static void tjd_bird_fly_proc(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
static u8 ani_cnt;
|
|
|
|
u16 idx;
|
|
u16 speed;
|
|
u16 flying_bird_pic_num;
|
|
|
|
flying_bird_pic_num = sizeof(Flying_Bird_Pic_arr) / sizeof(Flying_Bird_Pic_arr[0]);
|
|
|
|
/* 金币旋转 */
|
|
game->gold_spin_idx = (game->gold_spin_idx + 1) % (sizeof(gold_pic_arr) / sizeof(gold_pic_arr[0]));
|
|
|
|
if (LEVENT_BIRD_FLYING_ON == game->BirdFly_status)
|
|
{
|
|
game->bird_y_speed = game->bird_y_speed - BIRD_FALL_G;
|
|
speed = game->bird_y_speed;
|
|
if (game->bird_y_speed > -2)
|
|
{
|
|
speed = game->bird_y_speed;
|
|
idx = flying_bird_pic_num - 1 - speed * flying_bird_pic_num / BIRD_FLY_V;
|
|
if (idx < 0)
|
|
{
|
|
idx = 0;
|
|
}
|
|
else if (idx >= flying_bird_pic_num)
|
|
{
|
|
idx = flying_bird_pic_num - 1;
|
|
}
|
|
|
|
game->pBird->idx = idx;
|
|
}
|
|
else
|
|
{
|
|
game->pBird->idx = 3;
|
|
}
|
|
game->pBird->y -= game->bird_y_speed;
|
|
if (game->pBird->y <= (BIRDFLY_ZOOM_Y))
|
|
{
|
|
game->pBird->y = BIRDFLY_ZOOM_Y;
|
|
game->bird_y_speed = 0;
|
|
}
|
|
if (game->bird_y_speed <= 0)
|
|
{
|
|
|
|
game->BirdFly_status = LEVENT_BIRD_GLIDING;
|
|
}
|
|
}
|
|
else if (LEVENT_BIRD_GLIDING == game->BirdFly_status)
|
|
{
|
|
game->bird_y_speed = game->bird_y_speed - BIRD_FALL_G;
|
|
game->pBird->idx = 3;
|
|
game->pBird->y -= game->bird_y_speed;
|
|
if ((game->pBird->y + (BIRD_HEIGHT >> 1) - (BIRD_VALID_HEIGHT >> 1)) > (BIRDFLY_ZOOM_Y + BIRDFLY_ZOOM_CY - BIRDFLY_GROUND_HEIGHT))
|
|
{
|
|
game->BirdFly_status = LEVENT_BIRD_DIE_FALLDOWN;
|
|
game->pBird->idx = 0;
|
|
game->pBird->flag = 0;
|
|
// 小鸟被撞击到地面
|
|
game->pBird->y = (BIRDFLY_ZOOM_Y + BIRDFLY_ZOOM_CY - BIRDFLY_GROUND_HEIGHT + 3);
|
|
tjd_bird_die(game->pBird);
|
|
}
|
|
}
|
|
else if (LEVENT_BIRD_DIE_FALLDOWN == game->BirdFly_status)
|
|
{
|
|
game->pBird->y -= game->bird_y_speed;
|
|
|
|
if (game->pBirdHit->flag)
|
|
{
|
|
game->pBirdHit->idx++;
|
|
|
|
if (game->pBirdHit->idx >= sizeof(Hit_Bird_Boom_pic_arr) / sizeof(Hit_Bird_Boom_pic_arr[0]))
|
|
{
|
|
// printf("end bird boom\n");
|
|
game->pBirdHit->idx = 0;
|
|
game->pBirdHit->flag = 0;
|
|
}
|
|
}
|
|
if (game->pBird->flag)
|
|
{
|
|
game->pBird->idx++;
|
|
|
|
if (game->pBird->idx >= sizeof(Death_Bird_Fall_pic_arr) / sizeof(Death_Bird_Fall_pic_arr[0]) || (game->pBird->y + (BIRD_HEIGHT >> 1) - BIRD_VALID_HEIGHT >> 1) >= (BIRDFLY_ZOOM_Y + BIRDFLY_ZOOM_CY - BIRDFLY_GROUND_HEIGHT))
|
|
{
|
|
// printf("end bird fall\n");
|
|
game->pBird->idx = 0;
|
|
game->pBird->flag = 0;
|
|
}
|
|
game->bird_y_speed = game->bird_y_speed - BIRD_FALL_G;
|
|
}
|
|
if (game->pBirdHit->flag == 0 && game->pBird->flag == 0)
|
|
{
|
|
if (game->bird_num > 0)
|
|
{
|
|
tjd_ready_birdfly();
|
|
tjd_birdfly_send_draw_evt();
|
|
}
|
|
else
|
|
{
|
|
// printf("GAMEOVER\n");
|
|
game->BirdFly_status = LEVENT_GAMEOVER_DLG;
|
|
tjd_birdfly_stop();
|
|
|
|
tjd_birdfly_send_draw_evt();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void tjd_bird_fly_task(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
static u16 cnt = 0;
|
|
|
|
cnt++;
|
|
if (cnt >= 200)
|
|
{
|
|
cnt = 0;
|
|
if (game->make_barrier_time > 10)
|
|
{
|
|
game->make_barrier_time--;
|
|
}
|
|
}
|
|
tjd_bird_fly_proc();
|
|
if (game->BirdFly_status == LEVENT_BIRD_QUICK_RIGHT_FLY)
|
|
{
|
|
if (cnt % 2 == 0)
|
|
{
|
|
// 生成资源
|
|
tjd_make_resource();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (cnt % 10 == 0)
|
|
{
|
|
// 生成资源
|
|
tjd_make_resource();
|
|
}
|
|
}
|
|
if (cnt % game->make_barrier_time == 3)
|
|
{
|
|
// 生成障碍物
|
|
if (game->Barrier_status == NORMAL_BARRIER)
|
|
{
|
|
tjd_make_barrier();
|
|
}
|
|
}
|
|
}
|
|
|
|
static void TJD_Bird_FlyOn(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
printf("TJD_Bird_FlyOn");
|
|
|
|
game->bird_y_speed = BIRD_FLY_V;
|
|
|
|
game->BirdFly_status = LEVENT_BIRD_FLYING_ON;
|
|
game->pBird->idx = 0;
|
|
}
|
|
|
|
static void tjd_resource_move(u16 x_offset)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
u16 i;
|
|
Resource_t *pRes;
|
|
|
|
/* 资源位置移动 */
|
|
for (i = 0; i < MAX_RESOURCE_DATA_NUM; i++)
|
|
{
|
|
pRes = game->pResource + i;
|
|
if (pRes->attrib)
|
|
{
|
|
pRes->x -= x_offset;
|
|
if (pRes->x + pRes->cx <= BIRDFLY_ZOOM_X)
|
|
{
|
|
pRes->attrib = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void TJD_barrier_move(u16 x_offset)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
u16 i;
|
|
Barrier_t *pBarrier;
|
|
|
|
for (i = 0; i < MAX_BARRIER_DATA_NUM; i++)
|
|
{
|
|
pBarrier = game->pBarrier + i;
|
|
if (pBarrier->attrib)
|
|
{
|
|
if (pBarrier->x <= BIRDFLY_ZOOM_X - pBarrier->cx)
|
|
{
|
|
pBarrier->attrib = 0;
|
|
}
|
|
else
|
|
{
|
|
pBarrier->x -= x_offset;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void tjd_bird_fly_animation_task(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
u16 x_offset;
|
|
if (LEVENT_BIRD_QUICK_RIGHT_FLY == game->BirdFly_status)
|
|
{
|
|
x_offset = 10;
|
|
}
|
|
else if (LEVENT_BIRD_FLYING_ON == game->BirdFly_status || LEVENT_BIRD_GLIDING == game->BirdFly_status)
|
|
{
|
|
x_offset = 2;
|
|
}
|
|
else
|
|
{
|
|
x_offset = 0;
|
|
}
|
|
game->x_offset += x_offset;
|
|
if (game->x_offset > 10000)
|
|
{
|
|
game->x_offset = 0;
|
|
}
|
|
|
|
tjd_resource_move(x_offset);
|
|
TJD_barrier_move(x_offset);
|
|
tjd_check_bird_ram_barrier();
|
|
tjd_check_bird_get_resource();
|
|
|
|
tjd_birdfly_send_draw_evt();
|
|
}
|
|
|
|
static void tjd_draw_bird(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
compo_picturebox_t *bird_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BIRD);
|
|
if ((game->pBird->y + (BIRD_HEIGHT >> 1) - (BIRD_VALID_HEIGHT >> 1)) >= BIRDFLY_ZOOM_Y && (game->pBird->y + (BIRD_HEIGHT >> 1) - (BIRD_VALID_HEIGHT >> 1)) <= (BIRDFLY_ZOOM_Y + BIRDFLY_ZOOM_CY - BIRDFLY_GROUND_HEIGHT))
|
|
{
|
|
if (game->pBird->flag)
|
|
{
|
|
compo_picturebox_set(bird_pic, Flying_Bird_Pic_arr[game->pBird->idx]);
|
|
compo_picturebox_set_pos(bird_pic, game->pBird->x, game->pBird->y);
|
|
compo_picturebox_set_visible(bird_pic, true);
|
|
}
|
|
}
|
|
|
|
compo_picturebox_t *start_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_START);
|
|
if (LEVENT_READY == game->BirdFly_status) {
|
|
compo_picturebox_set_visible(start_pic, true);
|
|
} else {
|
|
compo_picturebox_set_visible(start_pic, false);
|
|
}
|
|
}
|
|
|
|
static void tjd_draw_bird_hit(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
compo_picturebox_t *hit_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BOOM);
|
|
if (game->pBirdHit->flag)
|
|
{
|
|
compo_picturebox_set(hit_pic, Hit_Bird_Boom_pic_arr[game->pBirdHit->idx]);
|
|
compo_picturebox_set_pos(hit_pic, game->pBirdHit->x, game->pBirdHit->y);
|
|
compo_picturebox_set_visible(hit_pic, true);
|
|
}
|
|
}
|
|
|
|
static void tjd_draw_falling_death_bird(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
compo_picturebox_t *bird_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BIRD);
|
|
if ((game->pBird->y + (BIRD_HEIGHT >> 1) - (BIRD_VALID_HEIGHT >> 1)) >= BIRDFLY_ZOOM_Y && (game->pBird->y + (BIRD_HEIGHT >> 1) - (BIRD_VALID_HEIGHT >> 1)) <= (BIRDFLY_ZOOM_Y + BIRDFLY_ZOOM_CY - BIRDFLY_GROUND_HEIGHT))
|
|
{
|
|
if (game->pBird->flag)
|
|
{
|
|
compo_picturebox_set(bird_pic, Death_Bird_Fall_pic_arr[game->pBird->idx]);
|
|
compo_picturebox_set_pos(bird_pic, game->pBird->x, game->pBird->y);
|
|
compo_picturebox_set_visible(bird_pic, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void tjd_draw_resource(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
Resource_t *pRes;
|
|
|
|
for (u16 i = 0; i < MAX_RESOURCE_DATA_NUM; i++)
|
|
{
|
|
compo_picturebox_t *resource_pic = compo_getobj_byid(COMPO_ID_GAME_RESOURCE_PIC + i);
|
|
compo_picturebox_set_visible(resource_pic, false);
|
|
|
|
pRes = game->pResource + i;
|
|
if (pRes->attrib)
|
|
{
|
|
if (pRes->x >= BIRDFLY_ZOOM_X && (pRes->x <= (BIRDFLY_ZOOM_X + BIRDFLY_ZOOM_CX - pRes->cx)))
|
|
{
|
|
compo_picturebox_set_visible(resource_pic, true);
|
|
|
|
if (pRes->attrib == RES_GOLD)
|
|
{
|
|
compo_picturebox_set(resource_pic, gold_pic_arr[game->gold_spin_idx]);
|
|
compo_picturebox_set_pos(resource_pic, pRes->x, pRes->y);
|
|
}
|
|
else if (pRes->attrib == RES_UP)
|
|
{
|
|
compo_picturebox_set(resource_pic, UI_BUF_GAME_BIRD_UP_BIN);
|
|
compo_picturebox_set_pos(resource_pic, pRes->x, pRes->y);
|
|
}
|
|
else if (pRes->attrib == RES_DOWN)
|
|
{
|
|
compo_picturebox_set(resource_pic, UI_BUF_GAME_BIRD_DOWN_BIN);
|
|
compo_picturebox_set_pos(resource_pic, pRes->x, pRes->y);
|
|
}
|
|
else if (pRes->attrib == RES_UP_DOWN)
|
|
{
|
|
compo_picturebox_set(resource_pic, UI_BUF_GAME_BIRD_UP_DOWN_BIN);
|
|
compo_picturebox_set_pos(resource_pic, pRes->x, pRes->y);
|
|
}
|
|
else if (pRes->attrib == RES_RIGHT)
|
|
{
|
|
compo_picturebox_set(resource_pic, UI_BUF_GAME_BIRD_RIGHT_BIN);
|
|
compo_picturebox_set_pos(resource_pic, pRes->x, pRes->y);
|
|
}
|
|
else if (pRes->attrib == RES_LIFE)
|
|
{
|
|
compo_picturebox_set(resource_pic, UI_BUF_GAME_BIRD_LIFE_BIN);
|
|
compo_picturebox_set_pos(resource_pic, pRes->x, pRes->y);
|
|
}
|
|
else if (pRes->attrib == RES_DEATH)
|
|
{
|
|
compo_picturebox_set(resource_pic, UI_BUF_GAME_BIRD_DEATH_BIN);
|
|
compo_picturebox_set_pos(resource_pic, pRes->x, pRes->y);
|
|
}
|
|
else
|
|
{
|
|
compo_picturebox_set_visible(resource_pic, false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void tjd_draw_barrier(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
Barrier_t *pBarrier;
|
|
// if (LEVENT_PLAYING == g_Airscraft_status)
|
|
{
|
|
for (int i = 0; i < MAX_BARRIER_DATA_NUM; i++)
|
|
{
|
|
pBarrier = game->pBarrier + i;
|
|
|
|
/* 释放资源不需要显示 */
|
|
if (pBarrier->attrib == BARRIER_NULL || game->Barrier_status == RLS_UPDOWN_BARRIER || game->Barrier_status == RLS_UP_BARRIER || game->Barrier_status == RLS_DOWN_BARRIER)
|
|
{
|
|
if (pBarrier->attrib == BARRIER_NULL || game->Barrier_status == RLS_UPDOWN_BARRIER)
|
|
{
|
|
for (int j = 0; j < MAX_BARRIER_NUM * 2; j++)
|
|
{
|
|
compo_picturebox_t *barrier_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BARRIER + (i * 8 + j));
|
|
compo_picturebox_set_visible(barrier_pic, false);
|
|
}
|
|
continue;
|
|
}
|
|
else if (game->Barrier_status == RLS_UP_BARRIER)
|
|
{
|
|
for (int j = 0; j < MAX_BARRIER_NUM; j++)
|
|
{
|
|
compo_picturebox_t *barrier_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BARRIER + (i * 8 + j));
|
|
compo_picturebox_set_visible(barrier_pic, false);
|
|
}
|
|
}
|
|
else if (game->Barrier_status == RLS_DOWN_BARRIER)
|
|
{
|
|
for (int j = 0; j < MAX_BARRIER_NUM; j++)
|
|
{
|
|
compo_picturebox_t *barrier_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BARRIER + ((i * 8 + MAX_BARRIER_NUM) + j));
|
|
compo_picturebox_set_visible(barrier_pic, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* 显示有效移动部分 */
|
|
if (pBarrier->x >= BIRDFLY_ZOOM_X - pBarrier->cx && pBarrier->x <= (BIRDFLY_ZOOM_X + BIRDFLY_ZOOM_CX + pBarrier->cx))
|
|
{
|
|
if (pBarrier->attrib == BARRIER_UP && (game->Barrier_status != RLS_UP_BARRIER && game->Barrier_status != RLS_UPDOWN_BARRIER))
|
|
{
|
|
u16 y;
|
|
y = BIRDFLY_ZOOM_Y;
|
|
for (int j = 0; j < pBarrier->num; j++)
|
|
{
|
|
compo_picturebox_t *barrier_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BARRIER + (i * 8 + j));
|
|
compo_picturebox_set_pos(barrier_pic, pBarrier->x, y);
|
|
compo_picturebox_set_visible(barrier_pic, true);
|
|
|
|
y += pBarrier->cy;
|
|
}
|
|
}
|
|
else if (pBarrier->attrib == BARRIER_DOWN && (game->Barrier_status != RLS_DOWN_BARRIER && game->Barrier_status != RLS_UPDOWN_BARRIER))
|
|
{
|
|
u16 y;
|
|
y = BIRDFLY_ZOOM_Y + BIRDFLY_ZOOM_CY - pBarrier->cy;
|
|
for (int j = 0; j < pBarrier->num; j++)
|
|
{
|
|
compo_picturebox_t *barrier_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BARRIER + ((i * 8 + MAX_BARRIER_NUM) + j));
|
|
compo_picturebox_set_pos(barrier_pic, pBarrier->x, y);
|
|
compo_picturebox_set_visible(barrier_pic, true);
|
|
|
|
y -= pBarrier->cy;
|
|
}
|
|
}
|
|
else if (pBarrier->attrib == BARRIER_UP_DOWN)
|
|
{
|
|
u16 y;
|
|
|
|
if ((game->Barrier_status != RLS_UP_BARRIER && game->Barrier_status != RLS_UPDOWN_BARRIER))
|
|
{
|
|
y = BIRDFLY_ZOOM_Y;
|
|
for (int j = 0; j < pBarrier->num; j++)
|
|
{
|
|
compo_picturebox_t *barrier_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BARRIER + (i * 8 + j));
|
|
compo_picturebox_set_pos(barrier_pic, pBarrier->x, y);
|
|
compo_picturebox_set_visible(barrier_pic, true);
|
|
|
|
y += pBarrier->cy;
|
|
}
|
|
}
|
|
|
|
if ((game->Barrier_status != RLS_DOWN_BARRIER && game->Barrier_status != RLS_UPDOWN_BARRIER))
|
|
{
|
|
y = BIRDFLY_ZOOM_Y + BIRDFLY_ZOOM_CY - pBarrier->cy;
|
|
for (int j = 0; j < MAX_BARRIER_NUM - pBarrier->num; j++)
|
|
{
|
|
compo_picturebox_t *barrier_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BARRIER + ((i * 8 + MAX_BARRIER_NUM) + j));
|
|
compo_picturebox_set_pos(barrier_pic, pBarrier->x, y);
|
|
compo_picturebox_set_visible(barrier_pic, true);
|
|
|
|
y -= pBarrier->cy;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void tjd_show_bird_life(u16 x, u16 y, u16 level)
|
|
{
|
|
char str[6] = {0};
|
|
sprintf(str, "%d", level);
|
|
tjd_show_digit(x + 32, y + 3, str, COMPO_ID_GAME_PIC_BIRD_LIFE);
|
|
}
|
|
|
|
static void tjd_bird_fly_redraw_proc(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
// printf("TJD_Bird_Fly_redraw_proc:%d\n", game->BirdFly_status);
|
|
if (game->has_to_redraw)
|
|
{
|
|
game->has_to_redraw = false;
|
|
if (LEVENT_BIRD_FLYING_ON == game->BirdFly_status || LEVENT_BIRD_GLIDING == game->BirdFly_status || LEVENT_BIRD_QUICK_RIGHT_FLY == game->BirdFly_status)
|
|
{
|
|
/* 显示部分 */
|
|
tjd_draw_bird();
|
|
tjd_draw_barrier();
|
|
tjd_draw_resource();
|
|
tjd_show_bird_life(LEVEL_ICO_X, LEVEL_ICO_Y, game->bird_num);
|
|
tjd_show_score(SCORE_ICO_X, SCORE_ICO_Y, game->game_score);
|
|
|
|
/* 隐藏部分 */
|
|
compo_picturebox_t *hit_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BOOM);
|
|
compo_picturebox_set_visible(hit_pic, false);
|
|
}
|
|
else if (LEVENT_BIRD_DIE_FALLDOWN == game->BirdFly_status)
|
|
{
|
|
/* 显示部分 */
|
|
tjd_draw_falling_death_bird();
|
|
tjd_draw_bird_hit();
|
|
tjd_draw_resource();
|
|
tjd_draw_barrier();
|
|
tjd_show_bird_life(LEVEL_ICO_X, LEVEL_ICO_Y, game->bird_num);
|
|
tjd_show_score(SCORE_ICO_X, SCORE_ICO_Y, game->game_score);
|
|
}
|
|
else if (LEVENT_GAMEOVER_DLG == game->BirdFly_status)
|
|
{
|
|
/* 显示部分 */
|
|
tjd_draw_resource();
|
|
tjd_draw_barrier();
|
|
tjd_show_bird_life(LEVEL_ICO_X, LEVEL_ICO_Y, game->bird_num);
|
|
tjd_show_score(SCORE_ICO_X, SCORE_ICO_Y, game->game_score);
|
|
tjd_show_game_over_dlg();
|
|
|
|
/* 隐藏部分 */
|
|
compo_picturebox_t *bird_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BIRD);
|
|
compo_picturebox_t *start_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_START);
|
|
compo_picturebox_set_visible(bird_pic, false);
|
|
compo_picturebox_set_visible(start_pic, false);
|
|
|
|
compo_picturebox_t *hit_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BOOM);
|
|
compo_picturebox_set_visible(hit_pic, false);
|
|
}
|
|
else if (LEVENT_READY == game->BirdFly_status)
|
|
{
|
|
/* 显示部分 */
|
|
tjd_draw_bird();
|
|
|
|
tjd_show_bird_life(LEVEL_ICO_X, LEVEL_ICO_Y, game->bird_num);
|
|
tjd_show_score(SCORE_ICO_X, SCORE_ICO_Y, game->game_score);
|
|
|
|
/* 隐藏部分 */
|
|
compo_picturebox_t *hit_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BOOM);
|
|
compo_picturebox_set_visible(hit_pic, false);
|
|
|
|
for (int i = 0; i < MAX_BARRIER_DATA_NUM; i++)
|
|
{
|
|
for (int j = 0; j < (MAX_BARRIER_NUM * 2); j++)
|
|
{
|
|
compo_picturebox_t *barrier_pic = compo_getobj_byid(COMPO_ID_GAME_PIC_BARRIER + (i * (MAX_BARRIER_NUM * 2) + j));
|
|
compo_picturebox_set_visible(barrier_pic, false);
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < MAX_RESOURCE_DATA_NUM; i++)
|
|
{
|
|
compo_picturebox_t *resource_pic = compo_getobj_byid(COMPO_ID_GAME_RESOURCE_PIC + i);
|
|
compo_picturebox_set_visible(resource_pic, false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void tjd_bird_fly_entry(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
game->has_to_redraw = TRUE;
|
|
game->bird_num = 1;
|
|
game->game_score = 0;
|
|
|
|
tjd_malloc_bird_fly_buffer();
|
|
|
|
game->BirdFly_status = LEVENT_READY;
|
|
tjd_reset_birdfly();
|
|
|
|
tjd_birdfly_send_draw_evt();
|
|
}
|
|
|
|
void tjd_birdfly_exit(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
// printf("BirdFly_exit\n");
|
|
|
|
tjd_birdfly_stop();
|
|
game->BirdFly_status = LEVENT_NULL;
|
|
tjd_free_bird_fly_buffer();
|
|
}
|
|
|
|
// 创建游戏界面
|
|
compo_form_t *func_game_form_create(void)
|
|
{
|
|
compo_form_t *frm;
|
|
|
|
// 新建窗体和背景
|
|
frm = compo_form_create(true);
|
|
|
|
/* 主背景 */
|
|
compo_picturebox_t *pic = compo_picturebox_create(frm, UI_BUF_GAME_BIRD_BG1_BIN);
|
|
compo_setid(pic, COMPO_ID_GAME_PIC_BG);
|
|
compo_picturebox_set_pos(pic, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y);
|
|
|
|
/* 小鸟 */
|
|
pic = compo_picturebox_create(frm, UI_BUF_GAME_BIRD_FLY4_BIN);
|
|
compo_setid(pic, COMPO_ID_GAME_PIC_BIRD);
|
|
widget_set_align_center(pic->img, false);
|
|
compo_picturebox_set_pos(pic, BIRDFLY_ZOOM_X + CENTER_X(BIRD_WIDTH), BIRDFLY_ZOOM_Y + ((BIRDFLY_ZOOM_CY - BIRDFLY_GROUND_HEIGHT - BIRD_HEIGHT) >> 1));
|
|
|
|
/* 开始指示 */
|
|
pic = compo_picturebox_create(frm, UI_BUF_GAME_START_BIN);
|
|
compo_setid(pic, COMPO_ID_GAME_PIC_START);
|
|
compo_picturebox_set_pos(pic, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y + START_HEIGHT);
|
|
|
|
/* 障碍物 - 箱子 */
|
|
for (int i = 0; i < COMPO_ID_GAME_PIC_BARRIER_MAX - COMPO_ID_GAME_PIC_BARRIER; i++)
|
|
{
|
|
pic = compo_picturebox_create(frm, UI_BUF_GAME_BARRIER_1_BIN);
|
|
compo_setid(pic, COMPO_ID_GAME_PIC_BARRIER + i);
|
|
widget_set_align_center(pic->img, false);
|
|
compo_picturebox_set_visible(pic, false);
|
|
}
|
|
|
|
/* 生成资源 */
|
|
for (int i = 0; i < COMPO_ID_GAME_RESOURCE_PIC_MAX - COMPO_ID_GAME_RESOURCE_PIC; i++)
|
|
{
|
|
pic = compo_picturebox_create(frm, gold_pic_arr[0]);
|
|
compo_setid(pic, COMPO_ID_GAME_RESOURCE_PIC + i);
|
|
widget_set_align_center(pic->img, false);
|
|
compo_picturebox_set_visible(pic, false);
|
|
}
|
|
|
|
/* 头部背景 */
|
|
pic = compo_picturebox_create(frm, UI_BUF_GAME_GAME_HEAD_BIN);
|
|
widget_set_align_center(pic->img, false);
|
|
compo_picturebox_set_pos(pic, 0, 0);
|
|
|
|
/* 小鸟生命 */
|
|
pic = compo_picturebox_create(frm, UI_BUF_GAME_BIRD_LIFE_BIN);
|
|
widget_set_align_center(pic->img, false);
|
|
compo_picturebox_set_pos(pic, LEVEL_ICO_X, LEVEL_ICO_Y);
|
|
for (int i = 0; i < COMPO_ID_GAME_PIC_BIRD_LIFE_MAX - COMPO_ID_GAME_PIC_BIRD_LIFE; i++)
|
|
{
|
|
|
|
pic = compo_picturebox_create(frm, digit_id_arr[1]);
|
|
compo_setid(pic, COMPO_ID_GAME_PIC_BIRD_LIFE + i);
|
|
widget_set_align_center(pic->img, false);
|
|
compo_picturebox_set_pos(pic, LEVEL_ICO_X + 32, LEVEL_ICO_Y + 3);
|
|
}
|
|
|
|
/* 得分 */
|
|
pic = compo_picturebox_create(frm, UI_BUF_GAME_GOLD_0_BIN);
|
|
widget_set_align_center(pic->img, false);
|
|
compo_picturebox_set_pos(pic, SCORE_ICO_X, SCORE_ICO_Y);
|
|
for (int i = 0; i < COMPO_ID_GAME_PIC_SCORE_MAX - COMPO_ID_GAME_PIC_SCORE; i++)
|
|
{
|
|
pic = compo_picturebox_create(frm, digit_id_arr[0]);
|
|
compo_setid(pic, COMPO_ID_GAME_PIC_SCORE + i);
|
|
widget_set_align_center(pic->img, false);
|
|
compo_picturebox_set_pos(pic, SCORE_ICO_X + 32, SCORE_ICO_Y + 3);
|
|
}
|
|
|
|
/* 击中 */
|
|
pic = compo_picturebox_create(frm, Hit_Bird_Boom_pic_arr[0]);
|
|
compo_setid(pic, COMPO_ID_GAME_PIC_BOOM);
|
|
widget_set_align_center(pic->img, false);
|
|
compo_picturebox_set_visible(pic, false);
|
|
|
|
/* 游戏结束图片 */
|
|
pic = compo_picturebox_create(frm, UI_BUF_GAME_END_BIN);
|
|
compo_setid(pic, COMPO_ID_GAME_PIC_END_BG);
|
|
compo_picturebox_set_pos(pic, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y + 9);
|
|
compo_picturebox_set_visible(pic, false);
|
|
|
|
compo_button_t *btn = compo_button_create(frm);
|
|
compo_setid(btn, COMPO_ID_GAME_BTN_END_ANEW);
|
|
compo_button_set_location(btn, GUI_SCREEN_CENTER_X, 191, 180, 60);
|
|
compo_button_set_visible(btn, false);
|
|
|
|
btn = compo_button_create(frm);
|
|
compo_setid(btn, COMPO_ID_GAME_BTN_END_EXIT);
|
|
compo_button_set_location(btn, GUI_SCREEN_CENTER_X, 240, 180, 60);
|
|
compo_button_set_visible(btn, false);
|
|
|
|
return frm;
|
|
}
|
|
|
|
static void func_game_click(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
int btn_id = compo_get_button_id();
|
|
|
|
if (game->BirdFly_status != LEVENT_GAMEOVER_DLG)
|
|
{
|
|
if (LEVENT_BIRD_FLYING_ON == game->BirdFly_status || LEVENT_BIRD_GLIDING == game->BirdFly_status)
|
|
{
|
|
TJD_Bird_FlyOn();
|
|
}
|
|
else if (game->BirdFly_status == LEVENT_READY)
|
|
{
|
|
game->BirdFly_status = LEVENT_BIRD_FLYING_ON;
|
|
tjd_birdfly_start_play();
|
|
TJD_Bird_FlyOn();
|
|
}
|
|
}
|
|
else if (btn_id == COMPO_ID_GAME_BTN_END_ANEW || btn_id == COMPO_ID_GAME_BTN_END_EXIT)
|
|
{
|
|
if (game->BirdFly_status == LEVENT_GAMEOVER_DLG)
|
|
{
|
|
if (btn_id == COMPO_ID_GAME_BTN_END_ANEW) {
|
|
/* 重新开始 */
|
|
if (func_cb.frm_main != NULL) {
|
|
compo_form_destroy(func_cb.frm_main);
|
|
}
|
|
func_cb.frm_main = func_game_form_create();
|
|
|
|
tjd_reset_birdfly();
|
|
|
|
game->BirdFly_status = LEVENT_BIRD_FLYING_ON;
|
|
tjd_birdfly_start_play();
|
|
TJD_Bird_FlyOn();
|
|
} else {
|
|
/* 结束游戏 */
|
|
func_back_to();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 消息处理
|
|
static void func_game_message(size_msg_t msg)
|
|
{
|
|
switch (msg)
|
|
{
|
|
case MSG_CTP_CLICK:
|
|
func_game_click();
|
|
break;
|
|
|
|
case MSG_CTP_SHORT_UP:
|
|
case MSG_CTP_SHORT_DOWN:
|
|
break;
|
|
|
|
case MSG_CTP_SHORT_LEFT:
|
|
if (func_cb.flag_sort)
|
|
{
|
|
func_message(msg);
|
|
}
|
|
break;
|
|
|
|
case MSG_CTP_LONG:
|
|
break;
|
|
|
|
default:
|
|
func_message(msg);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 游戏过程状态机
|
|
static void func_game_process(void)
|
|
{
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
if (game == NULL) {
|
|
return;
|
|
}
|
|
|
|
/* 游戏运行任务 */
|
|
if (tick_check_expire(game->bird_fly_task_tick, BIRDFLY_TIME_GAP) && game->bird_fly_task_flag)
|
|
{
|
|
game->bird_fly_task_tick = tick_get();
|
|
tjd_bird_fly_task();
|
|
}
|
|
if (tick_check_expire(game->animation_task_tick, BIRDFLY_ANI_TIME_GAP) && game->animation_task_flag)
|
|
{
|
|
game->animation_task_tick = tick_get();
|
|
tjd_bird_fly_animation_task();
|
|
}
|
|
if (tick_check_expire(game->quick_fly_task_tick, QUICKFLY_TIMEOUT_TIME) && game->quick_fly_task_flag)
|
|
{
|
|
game->quick_fly_task_tick = tick_get();
|
|
tjd_end_quick_fly_mode();
|
|
}
|
|
if (tick_check_expire(game->rls_barrier_task_tick, RLS_BARRIER_TIMEOUT_TIME) && game->rls_barrier_task_flag)
|
|
{
|
|
game->rls_barrier_task_tick = tick_get();
|
|
tjd_end_rls_barrier_mode();
|
|
}
|
|
|
|
/* 游戏过程不熄灭屏幕 */
|
|
reset_sleep_delay_all();
|
|
|
|
/* 更新游戏画面 */
|
|
tjd_bird_fly_redraw_proc();
|
|
}
|
|
|
|
// 进入游戏功能
|
|
static void func_game_enter(void)
|
|
{
|
|
func_cb.f_cb = func_zalloc(sizeof(f_game_t));
|
|
|
|
func_cb.frm_main = func_game_form_create();
|
|
f_game_t *game = (f_game_t *)func_cb.f_cb;
|
|
|
|
tjd_bird_fly_entry();
|
|
}
|
|
|
|
// 退出游戏功能
|
|
static void func_game_exit(void)
|
|
{
|
|
tjd_birdfly_exit();
|
|
|
|
func_cb.last = FUNC_GAME;
|
|
}
|
|
|
|
// 游戏功能
|
|
void func_game(void)
|
|
{
|
|
printf("%s\n", __func__);
|
|
func_game_enter();
|
|
while (func_cb.sta == FUNC_GAME) {
|
|
func_game_process();
|
|
func_process();
|
|
func_game_message(msg_dequeue());
|
|
}
|
|
func_game_exit();
|
|
}
|