📄 star.c
字号:
/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id: star.c,v 1.3 2003/12/23 22:24:48 hohensoh Exp $ * * Copyright (C) 2002 Frederic Dang Ngoc * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/#include "plugin.h"#ifdef HAVE_LCD_BITMAP/* file which contains the levels */#define STAR_LEVELS_FILE "/.rockbox/star/levels.txt"/* title of the game */#define STAR_TITLE "Star"/* font used to display title */#define STAR_TITLE_FONT 2/* size of a level in file */#define STAR_LEVEL_SIZE ((STAR_WIDTH + 1) * STAR_HEIGHT + 1)/* size of the game board */#define STAR_WIDTH 16#define STAR_HEIGHT 9/* left and top margin */#define STAR_OFFSET_X 8#define STAR_OFFSET_Y 0/* number of level */#define STAR_LEVEL_COUNT 20/* size of a tile */#define STAR_TILE_SIZE 6/* values of object in the board */#define STAR_VOID '.' #define STAR_WALL '*' #define STAR_STAR 'o' #define STAR_BALL 'X' #define STAR_BLOCK 'x' /* sleep time between two frames */#define STAR_SLEEP 1/* value of ball and block control */#define STAR_CONTROL_BALL 0#define STAR_CONTROL_BLOCK 1/* position of the ball */static int ball_x, ball_y;/* position of the block */static int block_x, block_y;/* number of stars to get to finish the level */static int star_count;/* the object we control : ball or block */static int control;/* the current board */static char board[STAR_HEIGHT][STAR_WIDTH];/* bitmap of the wall */static unsigned char wall_bmp[STAR_TILE_SIZE] = {0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55};/* bitmap of the star */static unsigned char star_bmp[STAR_TILE_SIZE] = {0x00, 0x0c, 0x12, 0x12, 0x0c, 0x00};/* bitmap of the ball */static unsigned char ball_bmp[STAR_TILE_SIZE] = {0x00, 0x0c, 0x1e, 0x1a, 0x0c, 0x00};/* bitmap of the block */static unsigned char block_bmp[STAR_TILE_SIZE] = {0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00};/* bitmap of the arrow animation */static unsigned char arrow_bmp[4][7] = { {0x7f, 0x7f, 0x3e, 0x3e, 0x1c, 0x1c, 0x08}, {0x3e, 0x3e, 0x1c, 0x1c, 0x08, 0x08, 0x08}, {0x1c, 0x1c, 0x1c, 0x1c, 0x08, 0x08, 0x08}, {0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08} };/* sequence of the bitmap arrow to follow to do one turn */static unsigned char anim_arrow[8] = {0, 1, 2, 3, 2, 1, 0};/* current_level */static int current_level = 0;/* char font size */static int char_width = -1;static int char_height = -1;static struct plugin_api* rb;/* this arrays contains a group of levels loaded into memory */static unsigned char* levels = "****************\n""*X**........o*x*\n""*..........o.***\n""*.......**o....*\n""*...**.o......**\n""**.o..o.....o..*\n""*.o......o**.o.*\n""*.....**o.....o*\n""****************\n""\n"".*..*.*.*...*.**\n""*...o.........X*\n""...*o..*o...o...\n""*.*.o.....o..*.*\n""......*...o...*.\n""*....*x*..o....*\n""...*..*.*...*oo*\n""*.............*.\n"".*..*........*..\n""\n""****************\n""*...........o*x*\n""*...**......**X*\n""*...*o.........*\n""*.o.....o**...o*\n""*.*o..o..o*..o**\n""*.**o.*o..o.o***\n""*o....**o......*\n""****************\n""\n""****************\n""*............*x*\n""*.....*........*\n""**o*o.o*o*o*o*o*\n""*.*.*o.o*.*.*.**\n""**o*o*o.o*o*o*o*\n""*.....*........*\n""*...*.......*X.*\n""****************\n""\n"".**************.\n""*X..*...*..*...*\n""*..*o.*.o..o.*.*\n""**......*..*...*\n""*o.*o*........**\n""**.....*.o.*...*\n""*o*..*.*.*...*x*\n""*...*....o*..*o*\n"".**************.\n""\n""....************\n""...*...o...*o.o*\n""..*....o....*.**\n"".*.....o.......*\n""*X.....o.......*\n""**.....o..*...**\n""*......o....*..*\n""*x.*...o..**o..*\n""****************\n""\n""****************\n""*..............*\n"".**.***..*o.**o*\n"".*o..*o.*.*.*.*.\n""..*..*..***.**..\n"".**..*..*o*.*o**\n""*..............*\n""*..X*o....x..*o*\n""****************\n""\n""***************.\n""*..o**.........*\n""*..*o..**.o....*\n""*..o**.*.*o....*\n""**.....**..*o*.*\n""**.*.......o*o.*\n""*oxo*...o..*X*.*\n""**.............*\n"".***************\n""\n""..*.***********.\n"".*o*o......*..X*\n""*o.o*....o....*.\n"".*.*..o**..o*..*\n""*..*o.*oxo....o*\n""*.....o**.....*.\n""*o*o.........*..\n""*...........*...\n"".***********....\n""\n""....***********.\n""*****.o........*\n""*...x.***o.o*.o*\n""*.o...*o.*o...*.\n""*.....*..o..*.o*\n""*o*o..*.o*..*X*.\n"".*o...***..***..\n""*.........*.*.*.\n"".*********..*..*\n""\n""****************\n""*......*......X*\n""*..*oo.....oo.**\n""**...o...**...o*\n""*o....*o*oo..***\n""**.**....**....*\n""*o..o*.o....x.o*\n""**o***....*...**\n""***************.\n""\n""**.....**..****.\n""*X*****o.***.o**\n""*....oo.....o..*\n""*.**..**o..*o*.*\n""*.*.o.*.*o.**..*\n""*.**..**...*x*.*\n""*.....o........*\n""*........o.....*\n""****************\n""\n"".**************.\n""*.X*........o.**\n""*.*...*o...o**.*\n""*.......o....*.*\n""*.o..........*o*\n""*.*......o.....*\n""**......o.o..*o*\n""*x..*....o.*.*.*\n"".**************.\n""\n""****************\n""*o*o........o*o*\n""*.o*X......**..*\n""*.x........o...*\n""*........o*....*\n""*......o.......*\n""*.o*........*..*\n""*o*o........o*o*\n""****************\n""\n"".******.********\n""*.....o*.....o.*\n""*.*.o.*..*...o.*\n""*..X*...*oo.*o.*\n"".*.*...*.o..x*.*\n""*o.......*..*o.*\n"".*......o.....*.\n""*o............o*\n""****************\n""\n""****************\n""**.x*o.o......o*\n""*o.Xo*o.......**\n""**.***........**\n""**.....o*o*....*\n""*oo.......o*o..*\n""**.o....****o..*\n""**o*..*........*\n""****************\n""\n""****************\n""*.o*........*X.*\n""*.*..o*oo*o..*.*\n""*....*o**o*.o..*\n""*.o*.......o*..*\n""*..o*o....o*...*\n""*.*..*.**o*..*.*\n""*....o.*o...x..*\n""****************\n""\n""****************\n""*.o....o..x*...*\n""*..*o*o...*o...*\n""*...*o*....*o..*\n""*...o..*...o*o.*\n""*.*o*...*.o*...*\n""*.o*o.*.o.*....*\n""*o*X..*.....*..*\n""****************\n""\n""****************\n""*o...**.....**o*\n""*.*..*......*o.*\n""*.o*...o**..o..*\n""*.*....*o......*\n""*....*...o*....*\n""*.**.o*.**o..*x*\n""*.o*.*o.....**X*\n""****************\n""\n""****************\n""*...o*o........*\n""**o..o*.**o...**\n""*.*.*.o...*..*.*\n""*.x.*..**..*.Xo*\n""*.*..*...o.*.*.*\n""**...o**.*o..o**\n""*........o*o...*\n""****************";/** * Display text. */static void star_display_text(char *str, bool waitkey){ int chars_by_line; int lines_by_screen; int chars_for_line; int current_line = 0; int first_char_index = 0; char *ptr_char; char *ptr_line; int i; char line[255]; int key; rb->lcd_clear_display(); chars_by_line = LCD_WIDTH / char_width; lines_by_screen = LCD_HEIGHT / char_height; do { ptr_char = str + first_char_index; chars_for_line = 0; i = 0; ptr_line = line; while (i < chars_by_line) { switch (*ptr_char) { case '\t': case ' ': *(ptr_line++) = ' '; case '\n': case '\0': chars_for_line = i; break; default: *(ptr_line++) = *ptr_char; } if (*ptr_char == '\n' || *ptr_char == '\0') break; ptr_char++; i++; } if (chars_for_line == 0) chars_for_line = i; line[chars_for_line] = '\0'; // test if we have cutted a word. If it is the case we don't have to // skip the space if (i == chars_by_line && chars_for_line == chars_by_line) first_char_index += chars_for_line; else first_char_index += chars_for_line + 1; // print the line on the screen rb->lcd_putsxy(0, current_line * char_height, line); // if the number of line showed on the screen is equals to the // maximum number of line we can show, we wait for a key pressed to // clear and show the remaining text. current_line++; if (current_line == lines_by_screen || *ptr_char == '\0') { current_line = 0; rb->lcd_update(); if (waitkey) while ((key = rb->button_get(true)) != BUTTON_PLAY && key != BUTTON_ON && key != BUTTON_DOWN); rb->lcd_clear_display(); } } while (*ptr_char != '\0');}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -