这次参与2024 DigiKey“感知万物,乐享生活”大赛,我选择的板子是“esp32-s3-lcd-ev-board”。这块板子非常豪华地配备了一块480*480的触摸屏,这么大的屏幕,能够非常好滴让单片机与人交互。
set(LV_DEMO_DIR ../components/lvgl/demos)
file(GLOB_RECURSE LV_DEMOS_SOURCES ${LV_DEMO_DIR}/*.c)
void app_main(void)
{
bsp_i2c_init();
lv_disp_t *disp = bsp_display_start();
ESP_LOGI(TAG, "Display LVGL demo");
/**
* To avoid errors caused by multiple tasks simultaneously accessing LVGL,
* should acquire a lock before operating on LVGL.
*/
bsp_display_lock(0);
huarongdao();
/* Release the lock */
bsp_display_unlock();
}
static void move_obj_cb(lv_event_t *e)
{
static lv_point_t click_point1, click_point2;
int movex, movey, direction;
game_obj_type *stage_data = (game_obj_type *)e->user_data;
if (e->code == LV_EVENT_PRESSED)
{
lv_indev_get_point(lv_indev_get_act(), &click_point1);
return;
}
if (e->code == LV_EVENT_RELEASED)
{
lv_indev_get_point(lv_indev_get_act(), &click_point2);
movex = click_point2.x - click_point1.x;
movey = click_point2.y - click_point1.y;
if ((movex == 0 && movey == 0) || (movex == movey) || (movex == -movey))
return;
if ((movex < 0 && movey < 0 && movex > movey) || (movex > 0 && movey < 0 && movex < -movey))
direction = up;
if ((movex > 0 && movey < 0 && movex > -movey) || (movex > 0 && movey > 0 && movex > movey))
direction = right;
if ((movex < 0 && movey < 0 && movex < movey) || (movex < 0 && movey > 0 && movex < -movey))
direction = left;
if ((movex < 0 && movey > 0 && movex > -movey) || (movex > 0 && movey > 0 && movex < movey))
direction = down;
if (direction == up)
{
if (stage_data->obj_type == little)
{
if (stage_data->y == 0)
return;
if (game_map[stage_data->y - 1][stage_data->x] == 0)
{
game_map[stage_data->y - 1][stage_data->x] = 1;
game_map[stage_data->y][stage_data->x] = 0;
stage_data->y--;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
if (stage_data->obj_type == big)
{
if (stage_data->y == 0)
return;
if (game_map[stage_data->y - 1][stage_data->x] == 0 && game_map[stage_data->y - 1][(stage_data->x) + 1] == 0)
{
game_map[stage_data->y - 1][stage_data->x] = 1;
game_map[stage_data->y - 1][(stage_data->x) + 1] = 1;
game_map[stage_data->y + 1][stage_data->x] = 0;
game_map[stage_data->y + 1][(stage_data->x) + 1] = 0;
stage_data->y--;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
if (stage_data->obj_type == hor)
{
if (stage_data->y == 0)
return;
if (game_map[stage_data->y - 1][stage_data->x] == 0 && game_map[stage_data->y - 1][(stage_data->x) + 1] == 0)
{
game_map[stage_data->y - 1][stage_data->x] = 1;
game_map[stage_data->y - 1][(stage_data->x) + 1] = 1;
game_map[stage_data->y][stage_data->x] = 0;
game_map[stage_data->y][(stage_data->x) + 1] = 0;
stage_data->y--;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
if (stage_data->obj_type == ver)
{
if (stage_data->y == 0)
return;
if (game_map[stage_data->y - 1][stage_data->x] == 0)
{
game_map[stage_data->y - 1][stage_data->x] = 1;
game_map[stage_data->y + 1][stage_data->x] = 0;
stage_data->y--;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
}
if (direction == down)
{
if (stage_data->obj_type == little)
{
if (stage_data->y == 4)
return;
if (game_map[stage_data->y + 1][stage_data->x] == 0)
{
game_map[stage_data->y + 1][stage_data->x] = 1;
game_map[stage_data->y][stage_data->x] = 0;
stage_data->y++;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
if (stage_data->obj_type == big)
{
if (stage_data->y == 3)
return;
if (game_map[stage_data->y + 2][stage_data->x] == 0 && game_map[stage_data->y + 2][(stage_data->x) + 1] == 0)
{
game_map[stage_data->y + 2][stage_data->x] = 1;
game_map[stage_data->y + 2][(stage_data->x) + 1] = 1;
game_map[stage_data->y][stage_data->x] = 0;
game_map[stage_data->y][(stage_data->x) + 1] = 0;
stage_data->y++;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
if (stage_data->obj_type == hor)
{
if (stage_data->y == 4)
return;
if (game_map[stage_data->y + 1][stage_data->x] == 0 && game_map[stage_data->y + 1][(stage_data->x) + 1] == 0)
{
game_map[stage_data->y + 1][stage_data->x] = 1;
game_map[stage_data->y + 1][(stage_data->x) + 1] = 1;
game_map[stage_data->y][stage_data->x] = 0;
game_map[stage_data->y][(stage_data->x) + 1] = 0;
stage_data->y++;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
if (stage_data->obj_type == ver)
{
if (stage_data->y == 3)
return;
if (game_map[stage_data->y + 2][stage_data->x] == 0)
{
game_map[stage_data->y + 2][stage_data->x] = 1;
game_map[stage_data->y][stage_data->x] = 0;
stage_data->y++;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
}
if (direction == left)
{
if (stage_data->obj_type == little)
{
if (stage_data->x == 0)
return;
if (game_map[stage_data->y][stage_data->x - 1] == 0)
{
game_map[stage_data->y][stage_data->x - 1] = 1;
game_map[stage_data->y][stage_data->x] = 0;
stage_data->x--;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
if (stage_data->obj_type == big)
{
if (stage_data->x == 0)
return;
if (game_map[stage_data->y][stage_data->x - 1] == 0 && game_map[stage_data->y + 1][(stage_data->x) - 1] == 0)
{
game_map[stage_data->y][stage_data->x - 1] = 1;
game_map[stage_data->y + 1][(stage_data->x) - 1] = 1;
game_map[stage_data->y][stage_data->x + 1] = 0;
game_map[stage_data->y + 1][(stage_data->x) + 1] = 0;
stage_data->x--;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
if (stage_data->obj_type == hor)
{
if (stage_data->x == 0)
return;
if (game_map[stage_data->y][stage_data->x - 1] == 0)
{
game_map[stage_data->y][stage_data->x - 1] = 1;
game_map[stage_data->y][stage_data->x + 1] = 0;
stage_data->x--;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
if (stage_data->obj_type == ver)
{
if (stage_data->x == 0)
return;
if (game_map[stage_data->y][stage_data->x - 1] == 0 && game_map[stage_data->y + 1][(stage_data->x) - 1] == 0)
{
game_map[stage_data->y][stage_data->x - 1] = 1;
game_map[stage_data->y + 1][stage_data->x - 1] = 1;
game_map[stage_data->y][stage_data->x] = 0;
game_map[stage_data->y + 1][stage_data->x] = 0;
stage_data->x--;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
}
if (direction == right)
{
if (stage_data->obj_type == little)
{
if (stage_data->x == 3)
return;
if (game_map[stage_data->y][stage_data->x + 1] == 0)
{
game_map[stage_data->y][stage_data->x + 1] = 1;
game_map[stage_data->y][stage_data->x] = 0;
stage_data->x++;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
if (stage_data->obj_type == big)
{
if (stage_data->x == 2)
return;
if (game_map[stage_data->y][stage_data->x + 2] == 0 && game_map[stage_data->y + 1][(stage_data->x) + 2] == 0)
{
game_map[stage_data->y][stage_data->x + 2] = 1;
game_map[stage_data->y + 1][(stage_data->x) + 2] = 1;
game_map[stage_data->y][stage_data->x] = 0;
game_map[stage_data->y + 1][(stage_data->x)] = 0;
stage_data->x++;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
if (stage_data->obj_type == hor)
{
if (stage_data->x == 2)
return;
if (game_map[stage_data->y][stage_data->x + 2] == 0)
{
game_map[stage_data->y][stage_data->x + 2] = 1;
game_map[stage_data->y][stage_data->x] = 0;
stage_data->x++;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
if (stage_data->obj_type == ver)
{
if (stage_data->x == 3)
return;
if (game_map[stage_data->y][stage_data->x + 1] == 0 && game_map[stage_data->y + 1][(stage_data->x) + 1] == 0)
{
game_map[stage_data->y][stage_data->x + 1] = 1;
game_map[stage_data->y + 1][stage_data->x + 1] = 1;
game_map[stage_data->y][stage_data->x] = 0;
game_map[stage_data->y + 1][stage_data->x] = 0;
stage_data->x++;
step_count++;
lv_label_set_text_fmt(step_lable, "STEP:%d", step_count);
lv_obj_set_pos(stage_data->obj, lv_pct((stage_data->x) * 25), lv_pct((stage_data->y) * 20));
}
}
}
if (stage_data->obj_type == big && stage_data->x == 1 && stage_data->y == 3)
{
lv_obj_t *clear_lable = lv_label_create(game_window);
lv_label_set_text(clear_lable, "STAGE CLEAR");
lv_obj_set_style_text_color(clear_lable, lv_color_hex(0xffffff), 0);
lv_obj_center(clear_lable);
if (current_stage < max_stage - 1)
{
current_stage++;
}
stage_clear();
}
}
}
感谢大佬分享
这游戏有点意思,从零开发的呀?
引用: wangerxian 发表于 2024-10-17 16:29 这游戏有点意思,从零开发的呀?
不是,移植开源的项目!
引用: aramy 发表于 2024-10-18 12:26 不是,移植开源的项目!
厉害,厉害,这样看来其他GUI框架也能移植这个游戏了。
,如果可以,那很多小游戏都可以移植进来玩。。。。。。。。。。。。。。。