#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include "lcdshow.h"
// ÓÎϷ״̬
TetrisGame game;
-// ·½¿éÐÎ×´¶¨Òå (7ÖÖÐÎ×´£¬Ã¿ÖÖ4¸öÐýת״̬)
+// ·½¿éÐÎ×´Êý¾Ý (7ÖÖ·½¿é£¬Ã¿ÖÖ4ÖÖÐýת״̬)
const uint8_t tetrominoes[7][4][4][4] = {
// IÐÍ
{
const uint16_t colors[8] = {
0x0000, // ºÚÉ« (±³¾°)
0x07E0, // ÂÌÉ« (IÐÍ)
- 0xFFFF, // »ÆÉ« (OÐÍ)
- 0x7F00, // רɫ (TÐÍ)
- 0xFFA5, // ³ÈÉ« (LÐÍ)
- 0x1F00, // À¶É« (JÐÍ)
- 0x001F, // ºìÉ« (SÐÍ)
+ 0xFFFF, // °×É« (OÐÍ)
+ 0x7F00, // ºìÉ« (TÐÍ)
+ 0xFFA5, // »ÆÉ« (LÐÍ)
+ 0x1F00, // ÉîÀ¶É« (JÐÍ)
+ 0x001F, // À¶É« (SÐÍ)
0x780F // ×ÏÉ« (ZÐÍ)
};
// ³õʼ»¯ÓÎÏ·
-void tetris_init() {
- // ³õʼ»¯Ëæ»úÊýÖÖ×Ó
- srand(time(NULL));
-
- // Çå¿ÕÓÎÏ·ÇøÓò
+void tetris_init( void ) {
+ extern u32 motor_current_avg_1;
+ // ³õʼ»¯Ëæ»úÊýÉú³ÉÆ÷
+ srand( motor_current_avg_1 );
+
+ // Çå¿ÕÓÎÏ·°å
memset(game.board, 0, sizeof(game.board));
-
+
// ³õʼ»¯ÓÎϷ״̬
game.score = 0;
game.level = 1;
game.game_over = false;
-
+
// Éú³ÉµÚÒ»¸ö·½¿é
tetris_spawn_piece();
+
+ //ÇåÆÁ
+ LCD_Fill(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0x0000);
+ // »æÖÆÓÎÏ·ÇøÓò±ß¿ò
+ //tetris_draw_rect(10, 10, BOARD_WIDTH * cell_size + 10, BOARD_HEIGHT * cell_size + 10, WHITE);
+
}
// Éú³Éз½¿é
-void tetris_spawn_piece() {
+void tetris_spawn_piece( void ) {
// Ëæ»úÑ¡Ôñ·½¿éÀàÐÍ
- game.current_piece.type = rand() % 7;
+ static int flag = 0;
+ if( !flag ){
+ game.next_piece.type = rand() % 7;
+ flag = 1;
+ }
+ game.current_piece.type = game.next_piece.type;
game.current_piece.rotation = 0;
game.current_piece.x = BOARD_WIDTH / 2 - 2;
game.current_piece.y = 0;
-
+
// ¼ì²éÊÇ·ñÓÎÏ·½áÊø
if (!tetris_is_valid_position(game.current_piece.x, game.current_piece.y, game.current_piece.type, game.current_piece.rotation)) {
game.game_over = true;
return;
}
-
+
// Éú³ÉÏÂÒ»¸ö·½¿é
game.next_piece.type = rand() % 7;
game.next_piece.rotation = 0;
}
// ¼ì²éλÖÃÊÇ·ñÓÐЧ
-bool tetris_is_valid_position(int x, int y, int type, int rotation) {
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 4; j++) {
+bool tetris_is_valid_position(int x, int y, int type, int rotation)
+{
+ int i,j;
+
+ for ( i = 0; i < 4; i++) {
+ for ( j = 0; j < 4; j++) {
if (tetrominoes[type][rotation][i][j] != 0) {
int board_x = x + j;
int board_y = y + i;
-
+
// ¼ì²é±ß½ç
if (board_x < 0 || board_x >= BOARD_WIDTH || board_y >= BOARD_HEIGHT) {
return false;
}
-
+
// ¼ì²éÊÇ·ñÓëÒÑÓз½¿éÅöײ
if (board_y >= 0 && game.board[board_y][board_x] != 0) {
return false;
}
// ÒÆ¶¯·½¿é
-bool tetris_move_piece(int dx, int dy) {
+bool tetris_move_piece(int dx, int dy)
+{
int new_x = game.current_piece.x + dx;
int new_y = game.current_piece.y + dy;
-
+
if (tetris_is_valid_position(new_x, new_y, game.current_piece.type, game.current_piece.rotation)) {
game.current_piece.x = new_x;
game.current_piece.y = new_y;
}
// Ðýת·½¿é
-bool tetris_rotate_piece() {
+bool tetris_rotate_piece( void ) {
int new_rotation = (game.current_piece.rotation + 1) % 4;
-
+
if (tetris_is_valid_position(game.current_piece.x, game.current_piece.y, game.current_piece.type, new_rotation)) {
game.current_piece.rotation = new_rotation;
return true;
}
// ·½¿éÏÂÂäÒ»¸ñ
-bool tetris_drop_piece() {
+bool tetris_drop_piece( void ) {
return tetris_move_piece(0, 1);
}
-// ·½¿éÖ±½ÓÂäµ½µ×²¿
-void tetris_hard_drop() {
+// ·½¿éÖ±½ÓÏÂÂäµ½µ×²¿
+void tetris_hard_drop( void ) {
while (tetris_drop_piece());
tetris_lock_piece();
}
-// Ëø¶¨·½¿éµ½ÓÎÏ·°å
-void tetris_lock_piece() {
+// ½«·½¿é¹Ì¶¨µ½ÓÎÏ·°å
+void tetris_lock_piece( void )
+{
+ int i,j;
+
// ½«·½¿é¹Ì¶¨µ½ÓÎÏ·°å
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 4; j++) {
+ for ( i = 0; i < 4; i++) {
+ for ( j = 0; j < 4; j++) {
if (tetrominoes[game.current_piece.type][game.current_piece.rotation][i][j] != 0) {
int board_x = game.current_piece.x + j;
int board_y = game.current_piece.y + i;
}
}
}
-
- // ¼ì²é²¢Ïû³ýÍêÕûµÄÐÐ
+
+ // ¼ì²é²¢Ïû³ýÍêÕûÐÐ
tetris_clear_lines();
-
+
// Éú³Éз½¿é
tetris_spawn_piece();
}
-// Ïû³ýÍêÕûµÄÐÐ
-void tetris_clear_lines() {
+// Ïû³ýÍêÕûÐÐ
+void tetris_clear_lines( void )
+{
+ int i,j,k;
int lines_cleared = 0;
-
- for (int i = BOARD_HEIGHT - 1; i >= 0; i--) {
+
+ for ( i = BOARD_HEIGHT - 1; i >= 0; i--) {
bool line_complete = true;
-
+
// ¼ì²éÐÐÊÇ·ñÍêÕû
- for (int j = 0; j < BOARD_WIDTH; j++) {
+ for ( j = 0; j < BOARD_WIDTH; j++) {
if (game.board[i][j] == 0) {
line_complete = false;
break;
}
}
-
- // Èç¹ûÐÐÍêÕû£¬Ïû³ý²¢ÏÂÒÆÉÏÃæµÄÐÐ
+
+ // Èç¹ûÐÐÍêÕû£¬½«ÉÏÃæµÄÐÐÏòÏÂÒÆ¶¯
if (line_complete) {
- for (int k = i; k > 0; k--) {
+ for ( k = i; k > 0; k--) {
memcpy(game.board[k], game.board[k-1], sizeof(game.board[0]));
}
memset(game.board[0], 0, sizeof(game.board[0]));
lines_cleared++;
- i++; // ¼ì²éÐÂÏÂÒÆµÄÐÐ
+ i++; // ÖØÐ¼ì²éµ±Ç°ÐÐ
}
}
-
+
// ¸üзÖÊýºÍµÈ¼¶
if (lines_cleared > 0) {
// ·ÖÊý¼ÆË㣺1ÐÐ100·Ö£¬2ÐÐ300·Ö£¬3ÐÐ600·Ö£¬4ÐÐ1000·Ö
int line_scores[] = {0, 100, 300, 600, 1000};
game.score += line_scores[lines_cleared] * game.level;
-
- // ÿÏû³ý10ÐÐÉýÒ»¼¶
+
+ // ÿµÃ1000·ÖÉýÒ»¼¶
game.level = game.score / 1000 + 1;
}
}
if (game.game_over) {
return;
}
-
- // ³¢ÊÔÏÂÂä·½¿é
+
+ // ·½¿éÏÂÂäÂß¼
if (!tetris_drop_piece()) {
- // ·½¿éÎÞ·¨ÏÂÂä£¬Ëø¶¨µ½ÓÎÏ·°å
+ // ·½¿éÎÞ·¨ÏÂÂ䣬¹Ì¶¨µ½ÓÎÏ·°å
tetris_lock_piece();
}
}
+typedef struct{
+ uint8_t board[BOARD_HEIGHT][BOARD_WIDTH];
+ uint8_t next[4][4];
+ int score;
+ int level;
+ bool game_over;
+} disp_info_t;
+
+void draw_board_block( int row, int col, int color )
+{
+ int x,y;
+ int cell_size = 12;
+ x = 0 + col * cell_size + 1;
+ y = 0 + row * cell_size + 1;
+ tetris_draw_cell(x, y, cell_size - 1, cell_size - 1, color);
+}
+
+void draw_next_block( int row, int col, int color )
+{
+ int x,y;
+ int cell_size = 12;
+ x = 144 + col * cell_size + 1;
+ y = 0 + row * cell_size + 1;
+ tetris_draw_cell(x, y, cell_size - 1, cell_size - 1, color);
+}
+
// »æÖÆÓÎÏ·
-void tetris_draw(uint16_t *framebuffer) {
+void tetris_draw( void )
+{
+ int i,j;
+ int cell_size;
+ int preview_x;
+ int preview_y;
+ disp_info_t to_disp;
+ static disp_info_t disp_info = {0};
+
// Çå¿ÕÆÁÄ»
- memset(framebuffer, 0, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(uint16_t));
-
+ //LCD_Fill(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0x0000);
+
// ¼ÆËã·½¿é´óС
- int cell_size = (SCREEN_WIDTH - 20) / (BOARD_WIDTH + 6); // 6ÁÐÓÃÓÚÏÂÒ»¸ö·½¿éÔ¤ÀÀ
-
+ cell_size = 10; // (SCREEN_WIDTH - 20) / (BOARD_WIDTH + 6); // 6ΪÓÒ²àÔ¤ÀÀÇøÓòµÄ¿í¶È
+
// »æÖÆÓÎÏ·ÇøÓò±ß¿ò
- tetris_draw_rect(framebuffer, 10, 10, BOARD_WIDTH * cell_size + 10, BOARD_HEIGHT * cell_size + 10, 0xFFFF);
-
+ //tetris_draw_rect(10, 10, BOARD_WIDTH * cell_size + 10, BOARD_HEIGHT * cell_size + 10, WHITE);
+
// »æÖÆÓÎÏ·°å
- for (int i = 0; i < BOARD_HEIGHT; i++) {
- for (int j = 0; j < BOARD_WIDTH; j++) {
- if (game.board[i][j] != 0) {
- tetris_draw_cell(framebuffer, 10 + j * cell_size + 1, 10 + i * cell_size + 1, cell_size - 1, cell_size - 1, colors[game.board[i][j]]);
- }
- }
- }
-
+ for ( i = 0; i < BOARD_HEIGHT; i++)
+ for ( j = 0; j < BOARD_WIDTH; j++)
+ to_disp.board[i][j] = game.board[i][j];
// »æÖƵ±Ç°·½¿é
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 4; j++) {
- if (tetrominoes[game.current_piece.type][game.current_piece.rotation][i][j] != 0) {
- int x = game.current_piece.x + j;
- int y = game.current_piece.y + i;
- if (y >= 0) {
- tetris_draw_cell(framebuffer, 10 + x * cell_size + 1, 10 + y * cell_size + 1, cell_size - 1, cell_size - 1, colors[tetrominoes[game.current_piece.type][game.current_piece.rotation][i][j]]);
- }
- }
+ for ( i = 0; i < 4; i++){
+ int row = game.current_piece.y + i;
+ for ( j = 0; j < 4; j++){
+ int col = game.current_piece.x + j;
+ int color = tetrominoes[game.current_piece.type][game.current_piece.rotation][i][j];
+ if( color )
+ to_disp.board[row][col] = color;
}
}
-
- // »æÖÆÏÂÒ»¸ö·½¿éÔ¤ÀÀÇøÓò
- int preview_x = 10 + BOARD_WIDTH * cell_size + 20;
- int preview_y = 10;
- tetris_draw_rect(framebuffer, preview_x, preview_y, preview_x + 6 * cell_size, preview_y + 6 * cell_size, 0xFFFF);
-
+
// »æÖÆÏÂÒ»¸ö·½¿é
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 4; j++) {
- if (tetrominoes[game.next_piece.type][game.next_piece.rotation][i][j] != 0) {
- tetris_draw_cell(framebuffer, preview_x + (j + 1) * cell_size + 1, preview_y + (i + 1) * cell_size + 1, cell_size - 1, cell_size - 1, colors[tetrominoes[game.next_piece.type][game.next_piece.rotation][i][j]]);
- }
- }
- }
-
+ for ( i = 0; i < 4; i++)
+ for ( j = 0; j < 4; j++)
+ to_disp.next[i][j] = tetrominoes[game.next_piece.type][game.next_piece.rotation][i][j];
+#if 0
// »æÖÆ·ÖÊýºÍµÈ¼¶
- tetris_draw_text(framebuffer, "Score:", preview_x, preview_y + 7 * cell_size, 0xFFFF);
- tetris_draw_number(framebuffer, game.score, preview_x + 40, preview_y + 7 * cell_size, 0xFFFF);
-
- tetris_draw_text(framebuffer, "Level:", preview_x, preview_y + 8 * cell_size, 0xFFFF);
- tetris_draw_number(framebuffer, game.level, preview_x + 40, preview_y + 8 * cell_size, 0xFFFF);
-
- // Èç¹ûÓÎÏ·½áÊø£¬»æÖÆÓÎÏ·½áÊøÐÅÏ¢
+ tetris_draw_text("Score:", preview_x, preview_y + 7 * cell_size, WHITE);
+ tetris_draw_number(game.score, preview_x + 40, preview_y + 7 * cell_size, WHITE);
+
+ tetris_draw_text("Level:", preview_x, preview_y + 8 * cell_size, WHITE);
+ tetris_draw_number(game.level, preview_x + 40, preview_y + 8 * cell_size, WHITE);
+
+ // Èç¹ûÓÎÏ·½áÊø£¬ÏÔʾÓÎÏ·½áÊøÐÅÏ¢
if (game.game_over) {
- tetris_draw_rect(framebuffer, SCREEN_WIDTH / 2 - 60, SCREEN_HEIGHT / 2 - 30, SCREEN_WIDTH / 2 + 60, SCREEN_HEIGHT / 2 + 30, 0x0000);
- tetris_draw_rect(framebuffer, SCREEN_WIDTH / 2 - 62, SCREEN_HEIGHT / 2 - 32, SCREEN_WIDTH / 2 + 62, SCREEN_HEIGHT / 2 + 32, 0xFFFF);
- tetris_draw_text(framebuffer, "GAME OVER", SCREEN_WIDTH / 2 - 40, SCREEN_HEIGHT / 2 - 10, 0xFFFF);
- tetris_draw_text(framebuffer, "Score:", SCREEN_WIDTH / 2 - 30, SCREEN_HEIGHT / 2 + 10, 0xFFFF);
- tetris_draw_number(framebuffer, game.score, SCREEN_WIDTH / 2 + 10, SCREEN_HEIGHT / 2 + 10, 0xFFFF);
+ tetris_draw_rect(SCREEN_WIDTH / 2 - 60, SCREEN_HEIGHT / 2 - 30, SCREEN_WIDTH / 2 + 60, SCREEN_HEIGHT / 2 + 30, BLACK);
+ tetris_draw_rect(SCREEN_WIDTH / 2 - 62, SCREEN_HEIGHT / 2 - 32, SCREEN_WIDTH / 2 + 62, SCREEN_HEIGHT / 2 + 32, WHITE);
+ tetris_draw_text("GAME OVER", SCREEN_WIDTH / 2 - 40, SCREEN_HEIGHT / 2 - 10, WHITE);
+ tetris_draw_text("Score:", SCREEN_WIDTH / 2 - 30, SCREEN_HEIGHT / 2 + 10, WHITE);
+ tetris_draw_number(game.score, SCREEN_WIDTH / 2 + 10, SCREEN_HEIGHT / 2 + 10, WHITE);
}
-}
+#else
+ to_disp.score = game.score;
+ to_disp.level = game.level;
+ to_disp.game_over = game.game_over;
+#endif
-// »æÖƾØÐÎ
-void tetris_draw_rect(uint16_t *framebuffer, int x1, int y1, int x2, int y2, uint16_t color) {
- for (int y = y1; y < y2; y++) {
- for (int x = x1; x < x2; x++) {
- if (x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT) {
- framebuffer[y * SCREEN_WIDTH + x] = color;
- }
- }
+ if( memcmp( &to_disp, &disp_info, sizeof(disp_info_t)) != 0)
+ {
+ int board_x = 10;
+ int board_y = 10;
+ int preview_x = 10 + BOARD_WIDTH * cell_size + 20;
+ int preview_y = 10;
+ int row, col;
+
+ for( row=0; row<20; row++)
+ for( col=0; col<10; col++)
+ if( to_disp.board[row][col] != disp_info.board[row][col])
+ draw_board_block(row, col, colors[to_disp.board[row][col]]);
+ for( row=0; row<4; row++)
+ for( col=0; col<4; col++)
+ if( to_disp.next[row][col] != disp_info.next[row][col])
+ draw_next_block(row, col, colors[to_disp.next[row][col]]);
+ memcpy( &disp_info, &to_disp, sizeof(disp_info_t));
}
}
-// »æÖƵ¥Ôª¸ñ
-void tetris_draw_cell(uint16_t *framebuffer, int x, int y, int width, int height, uint16_t color) {
- // »æÖƵ¥Ôª¸ñÖ÷Ìå
- tetris_draw_rect(framebuffer, x, y, x + width, y + height, color);
-
- // »æÖƵ¥Ôª¸ñ±ß¿ò
- uint16_t border_color = color > 0x7FFF ? color - 0x1010 : color + 0x1010;
- tetris_draw_line(framebuffer, x, y, x + width - 1, y, border_color);
- tetris_draw_line(framebuffer, x, y, x, y + height - 1, border_color);
-
- // »æÖƵ¥Ôª¸ñ¸ß¹â
- uint16_t highlight_color = color + 0x2020;
- tetris_draw_line(framebuffer, x + width - 1, y + 1, x + width - 1, y + height - 1, highlight_color);
- tetris_draw_line(framebuffer, x + 1, y + height - 1, x + width - 1, y + height - 1, highlight_color);
+// »æÖƾØÐÎ
+void tetris_draw_rect(int x1, int y1, int x2, int y2, uint16_t color) {
+ LCD_Fill(x1, y1, x2, y2, color);
}
-// »æÖÆÏß¶Î
-void tetris_draw_line(uint16_t *framebuffer, int x1, int y1, int x2, int y2, uint16_t color) {
- // BresenhamÖ±ÏßËã·¨
- int dx = abs(x2 - x1);
- int dy = abs(y2 - y1);
- int sx = x1 < x2 ? 1 : -1;
- int sy = y1 < y2 ? 1 : -1;
- int err = dx - dy;
-
- while (1) {
- if (x1 >= 0 && x1 < SCREEN_WIDTH && y1 >= 0 && y1 < SCREEN_HEIGHT) {
- framebuffer[y1 * SCREEN_WIDTH + x1] = color;
- }
-
- if (x1 == x2 && y1 == y2) {
- break;
- }
-
- int e2 = 2 * err;
- if (e2 > -dy) {
- err -= dy;
- x1 += sx;
- }
- if (e2 < dx) {
- err += dx;
- y1 += sy;
- }
- }
+// »æÖÆ·½¿é
+void tetris_draw_cell(int x, int y, int width, int height, uint16_t color)
+{
+ uint16_t border_color;
+ uint16_t highlight_color;
+
+ // »æÖÆ·½¿éÖ÷Ìå
+ LCD_Fill(x, y, x + width, y + height, color);
+ if( color == 0 )
+ return;
+ // »æÖÆ·½¿é±ß¿ò
+ border_color = color > 0x7FFF ? color - 0x1010 : color + 0x1010;
+ LCD_DrawLine(x, y, x + width - 1, y, border_color);
+ LCD_DrawLine(x, y, x, y + height - 1, border_color);
+
+ // »æÖÆ·½¿é¸ß¹â
+ highlight_color = color + 0x2020;
+ LCD_DrawLine(x + width - 1, y + 1, x + width - 1, y + height - 1, highlight_color);
+ LCD_DrawLine(x + 1, y + height - 1, x + width - 1, y + height - 1, highlight_color);
}
// »æÖÆÎı¾
-void tetris_draw_text(uint16_t *framebuffer, const char *text, int x, int y, uint16_t color) {
- // ¼òµ¥µÄÎı¾»æÖƺ¯Êý£¬Ö»Ö§³ÖÊý×ֺʹóд×Öĸ
- const uint8_t font[] = {
- // 0
- 0x3E, 0x41, 0x41, 0x41, 0x3E,
- // 1
- 0x00, 0x21, 0x7F, 0x01, 0x00,
- // 2
- 0x21, 0x43, 0x45, 0x49, 0x31,
- // 3
- 0x22, 0x41, 0x49, 0x49, 0x36,
- // 4
- 0x0C, 0x14, 0x24, 0x7F, 0x04,
- // 5
- 0x72, 0x51, 0x51, 0x51, 0x4E,
- // 6
- 0x1E, 0x29, 0x49, 0x49, 0x06,
- // 7
- 0x40, 0x47, 0x48, 0x50, 0x60,
- // 8
- 0x36, 0x49, 0x49, 0x49, 0x36,
- // 9
- 0x30, 0x49, 0x49, 0x4A, 0x3C,
- // A
- 0x1E, 0x21, 0x21, 0x21, 0x1E,
- // B
- 0x3F, 0x49, 0x49, 0x49, 0x26,
- // C
- 0x1E, 0x21, 0x21, 0x21, 0x21,
- // D
- 0x3F, 0x21, 0x21, 0x21, 0x1E,
- // E
- 0x3F, 0x49, 0x49, 0x49, 0x41,
- // F
- 0x3F, 0x48, 0x48, 0x48, 0x40,
- // G
- 0x1E, 0x21, 0x29, 0x29, 0x3E,
- // H
- 0x3F, 0x08, 0x08, 0x08, 0x3F,
- // I
- 0x00, 0x41, 0x3F, 0x41, 0x00,
- // J
- 0x06, 0x01, 0x41, 0x3F, 0x00,
- // K
- 0x3F, 0x08, 0x14, 0x22, 0x41,
- // L
- 0x3F, 0x01, 0x01, 0x01, 0x01,
- // M
- 0x3F, 0x20, 0x10, 0x20, 0x3F,
- // N
- 0x3F, 0x20, 0x10, 0x08, 0x3F,
- // O
- 0x1E, 0x21, 0x21, 0x21, 0x1E,
- // P
- 0x3F, 0x48, 0x48, 0x48, 0x30,
- // Q
- 0x1E, 0x21, 0x25, 0x22, 0x1D,
- // R
- 0x3F, 0x48, 0x4C, 0x4A, 0x31,
- // S
- 0x26, 0x49, 0x49, 0x49, 0x32,
- // T
- 0x40, 0x40, 0x7F, 0x40, 0x40,
- // U
- 0x3F, 0x01, 0x01, 0x01, 0x3F,
- // V
- 0x3F, 0x02, 0x04, 0x02, 0x3F,
- // W
- 0x3F, 0x10, 0x0C, 0x10, 0x3F,
- // X
- 0x21, 0x12, 0x0C, 0x12, 0x21,
- // Y
- 0x21, 0x12, 0x0C, 0x04, 0x04,
- // Z
- 0x41, 0x43, 0x45, 0x49, 0x41
- };
-
- int char_width = 6;
- int char_height = 5;
-
- while (*text) {
- char c = *text++;
- int index = -1;
-
- if (c >= '0' && c <= '9') {
- index = (c - '0') * 5;
- } else if (c >= 'A' && c <= 'Z') {
- index = (c - 'A' + 10) * 5;
- } else if (c == ':') {
- index = 35 * 5; // ðºÅµÄλÖÃ
- }
-
- if (index >= 0) {
- for (int i = 0; i < char_height; i++) {
- uint8_t row = font[index + i];
- for (int j = 0; j < 5; j++) {
- if (row & (1 << (4 - j))) {
- if (x + j < SCREEN_WIDTH && y + i < SCREEN_HEIGHT) {
- framebuffer[(y + i) * SCREEN_WIDTH + (x + j)] = color;
- }
- }
- }
- }
- }
-
- x += char_width;
- }
+void tetris_draw_text(const char *text, int x, int y, uint16_t color) {
+ // ʹÓÃLCD_ShowStringº¯Êý»æÖÆÎı¾
+ LCD_ShowString(x, y, (u8*)text, color, BLACK, 16, 0);
}
// »æÖÆÊý×Ö
-void tetris_draw_number(uint16_t *framebuffer, int number, int x, int y, uint16_t color) {
+void tetris_draw_number(int number, int x, int y, uint16_t color) {
char buffer[10];
sprintf(buffer, "%d", number);
- tetris_draw_text(framebuffer, buffer, x, y, color);
+ tetris_draw_text(buffer, x, y, color);
}