tetris impl

This commit is contained in:
2024-08-09 11:20:42 -05:00
parent b6eac70c2c
commit 074faf8879
6 changed files with 78 additions and 1735 deletions
-1
View File
@@ -8,7 +8,6 @@ set(SOURCES
"step5.cpp"
"step6.cpp"
"wires_puzzle.cpp"
"tetris.c"
)
target_sources(${COMPONENT_LIB} PRIVATE ${SOURCES})
+46 -13
View File
@@ -3,6 +3,7 @@
static const char *TAG = "step2";
static lv_obj_t* scr;
static lv_style_t scr_style;
static lv_obj_t* img;
static bool invisible_blocks = false;
@@ -12,6 +13,20 @@ static const int height = 22;
static const int width = 10;
static int board[height][width] = {0};
static lv_obj_t* visual_board[height][width] = {0};
static const char* BACKGROUND_FILE_NAME = "A:/sdcard/bg.bin";
static const char* PIECE_IMG_SRC[] = {
"A:/sdcard/red.bin",
"A:/sdcard/lb.bin",
"A:/sdcard/db.bin",
"A:/sdcard/orange.bin",
"A:/sdcard/yellow.bin",
"A:/sdcard/green.bin",
"A:/sdcard/purple.bin",
};
static bool game = true;
static int score = 0;
@@ -25,13 +40,11 @@ static int piece_nodes[4][2] = {
{0, 0},
};
static lv_color_t piece_colors[] = {
(lv_color_t { .full = 0xfee0 }),
};
lv_obj_t* piece_imgs[4] = {};
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> piece_dist(2, 7);
std::uniform_int_distribution<> piece_dist(2, 6);
static void generate_block(void);
static void show_board(void);
@@ -100,22 +113,30 @@ static int bdca(int i) { // [0,1,2,3] -> [ 0,+2,+1,-1]
static void init_screen(void) {
LV_IMG_DECLARE(tetris);
// scr = lv_obj_create(screen);
// img = lv_img_create(lv_scr_act());
// lv_img_set_src(img, &tetris);
// lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
// create new screen
// scr = lv_obj_create(NULL);
// lv_style_init(&scr_style);
// lv_style_set_bg_color(&scr_style, lv_color_black());
// lv_obj_add_style(scr, &scr_style, LV_STATE_DEFAULT);
// lv_scr_load(scr);
img = lv_img_create(lv_scr_act());
lv_img_set_src(img, "A:/sdcard/db.bin");
lv_img_set_src(img, BACKGROUND_FILE_NAME);
lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
for (int i = 0; i < 4; i++) {
piece_imgs[i] = lv_img_create(lv_scr_act());
lv_obj_align(piece_imgs[i], LV_ALIGN_BOTTOM_LEFT, 159, -320);
}
// play_raw(MOUNT_POINT "/tetris.pcm");
}
static void deinit_screen(void) {
lv_obj_clean(scr);
while (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdFALSE) vTaskDelay(pdMS_TO_TICKS(10));
lv_obj_clean(lv_scr_act());
xSemaphoreGive(xGuiSemaphore);
}
void step2(void) {
@@ -185,8 +206,14 @@ static void show_board(void) {
printf("|\n");
}
printf("\n");
} else {
}
for (int i = 0; i < sizeof(piece_nodes)/sizeof(piece_nodes[0]); i++) {
int* p = piece_nodes[i];
lv_obj_t* piece_img = piece_imgs[i];
// lv_img_set_src(piece_img, FILE_NAME[piece]);
lv_obj_align(piece_img, LV_ALIGN_BOTTOM_LEFT, 159 + p[1]*16, -(p[0]*16));
}
}
@@ -215,6 +242,11 @@ static void generate_block(void) {
}
}
}
for (int i = 0; i < 4; i++) {
lv_obj_t* piece_img = piece_imgs[i];
lv_img_set_src(piece_img, PIECE_IMG_SRC[piece]);
}
}
static void rotate_block(void) {
@@ -415,3 +447,4 @@ static void line_clear(int height) {
}
score++;
}
-1647
View File
File diff suppressed because one or more lines are too long