forked from len0rd/rockbox
Scale and use color bitmaps on color lcd targets.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10100 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
74a3f2144c
commit
40a92eaed9
2 changed files with 146 additions and 52 deletions
|
@ -24,6 +24,10 @@
|
|||
|
||||
PLUGIN_HEADER
|
||||
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
extern const fb_data sokoban_tiles[];
|
||||
#endif
|
||||
|
||||
#define SOKOBAN_TITLE "Sokoban"
|
||||
#define SOKOBAN_TITLE_FONT 2
|
||||
|
||||
|
@ -33,7 +37,7 @@ PLUGIN_HEADER
|
|||
#define COLS 20
|
||||
/* Use all but 8k of the plugin buffer for board data */
|
||||
#define SOKOBAN_LEVEL_SIZE (ROWS*COLS)
|
||||
#define MAX_BUFFERED_BOARDS (PLUGIN_BUFFER_SIZE - 0x2000)/SOKOBAN_LEVEL_SIZE
|
||||
#define MAX_BUFFERED_BOARDS (PLUGIN_BUFFER_SIZE - 0x3000)/SOKOBAN_LEVEL_SIZE
|
||||
#define MAX_UNDOS 5
|
||||
|
||||
/* variable button definitions */
|
||||
|
@ -423,11 +427,14 @@ static void update_screen(void)
|
|||
int rows = 0, cols = 0;
|
||||
char s[25];
|
||||
|
||||
#if LCD_HEIGHT == 128 /* magnify is the number of pixels for each block */
|
||||
int magnify = 6; /* 6 on h1x0, 9 on h3x0, and 4 on everything else */
|
||||
#elif LCD_HEIGHT >= 176
|
||||
/* magnify is the number of pixels for each block */
|
||||
#if LCD_HEIGHT >= 240 /* ipod 5g */
|
||||
int magnify = 14;
|
||||
#elif LCD_HEIGHT >= 176 /* h3x0, ipod color/photo */
|
||||
int magnify = 9;
|
||||
#else
|
||||
#elif LCD_HEIGHT >= 128 /* h1x0, ipod nano */
|
||||
int magnify = 6;
|
||||
#else /* other */
|
||||
int magnify = 4;
|
||||
#endif
|
||||
|
||||
|
@ -443,9 +450,8 @@ static void update_screen(void)
|
|||
|
||||
case '#': /* this is a wall */
|
||||
#if HAVE_LCD_COLOR
|
||||
rb->lcd_set_foreground(WALL_COLOR);
|
||||
rb->lcd_fillrect(c, b, magnify, magnify);
|
||||
rb->lcd_set_foreground(LCD_BLACK);
|
||||
rb->lcd_bitmap_part( sokoban_tiles, 0, 1*magnify, magnify,
|
||||
c, b, magnify, magnify );
|
||||
#elif LCD_DEPTH > 1
|
||||
rb->lcd_set_foreground(MEDIUM_GRAY);
|
||||
rb->lcd_fillrect(c, b, magnify, magnify);
|
||||
|
@ -463,9 +469,8 @@ static void update_screen(void)
|
|||
|
||||
case '.': /* this is a home location */
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
rb->lcd_set_foreground(FREE_TARGET_COLOR);
|
||||
rb->lcd_fillrect(c+(magnify/2)-1, b+(magnify/2)-1, magnify/2,
|
||||
magnify/2);
|
||||
rb->lcd_bitmap_part( sokoban_tiles, 0, 4*magnify, magnify,
|
||||
c, b, magnify, magnify );
|
||||
#else
|
||||
rb->lcd_drawrect(c+(magnify/2)-1, b+(magnify/2)-1, magnify/2,
|
||||
magnify/2);
|
||||
|
@ -474,19 +479,22 @@ static void update_screen(void)
|
|||
|
||||
case '$': /* this is a box */
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
rb->lcd_set_foreground(FREE_BLOCK_COLOR);
|
||||
#endif
|
||||
rb->lcd_bitmap_part( sokoban_tiles, 0, 2*magnify, magnify,
|
||||
c, b, magnify, magnify );
|
||||
#else
|
||||
rb->lcd_drawrect(c, b, magnify, magnify); /* Free boxes are not filled in */
|
||||
#endif
|
||||
break;
|
||||
|
||||
case '@': /* this is you */
|
||||
{
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
rb->lcd_bitmap_part( sokoban_tiles, 0, 5*magnify, magnify,
|
||||
c, b, magnify, magnify );
|
||||
#else
|
||||
int max = magnify - 1;
|
||||
int middle = max / 2;
|
||||
int ldelta = (middle + 1) / 2;
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
rb->lcd_set_foreground(CHAR_COLOR);
|
||||
#endif
|
||||
rb->lcd_drawline(c, b+middle, c+max, b+middle);
|
||||
rb->lcd_drawline(c+middle, b, c+middle, b+max-ldelta);
|
||||
rb->lcd_drawline(c+max-middle, b,
|
||||
|
@ -495,26 +503,27 @@ static void update_screen(void)
|
|||
c+middle-ldelta, b+max);
|
||||
rb->lcd_drawline(c+max-middle, b+max-ldelta,
|
||||
c+max-middle+ldelta, b+max);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case '%': /* this is a box on a home spot */
|
||||
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
rb->lcd_set_foreground(USED_BLOCK_COLOR);
|
||||
rb->lcd_fillrect(c, b, magnify, magnify);
|
||||
rb->lcd_bitmap_part( sokoban_tiles, 0, 3*magnify, magnify,
|
||||
c, b, magnify, magnify );
|
||||
#else
|
||||
rb->lcd_drawrect(c, b, magnify, magnify);
|
||||
#endif
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
rb->lcd_set_foreground(USED_TARGET_COLOR);
|
||||
rb->lcd_fillrect(c+(magnify/2)-1, b+(magnify/2)-1, magnify/2,
|
||||
magnify/2);
|
||||
#else
|
||||
rb->lcd_drawrect(c+(magnify/2)-1, b+(magnify/2)-1, magnify/2,
|
||||
magnify/2);
|
||||
#endif
|
||||
break;
|
||||
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
default:
|
||||
rb->lcd_bitmap_part( sokoban_tiles, 0, 0*magnify, magnify,
|
||||
c, b, magnify, magnify );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,16 +37,9 @@ PLUGIN_HEADER
|
|||
#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 '*'
|
||||
|
@ -155,6 +148,38 @@ static int control;
|
|||
/* the current board */
|
||||
static char board[STAR_HEIGHT][STAR_WIDTH];
|
||||
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
|
||||
extern const fb_data star_tiles[];
|
||||
|
||||
/* size of a tile */
|
||||
#if LCD_WIDTH >= 320
|
||||
# define STAR_TILE_SIZE 20
|
||||
#elif LCD_WIDTH >= 220
|
||||
# define STAR_TILE_SIZE 13
|
||||
#else
|
||||
# define STAR_TILE_SIZE 10
|
||||
#endif
|
||||
|
||||
/* left and top margin */
|
||||
#define STAR_OFFSET_X ( ( LCD_WIDTH - STAR_WIDTH * STAR_TILE_SIZE ) / 2 )
|
||||
#define STAR_OFFSET_Y ( ( LCD_HEIGHT - ( STAR_HEIGHT + 1 ) * STAR_TILE_SIZE ) / 2 )
|
||||
|
||||
#define wall 0
|
||||
#define space 1
|
||||
#define block 2
|
||||
#define star 3
|
||||
#define ball 4
|
||||
|
||||
#else
|
||||
|
||||
/* left and top margin */
|
||||
#define STAR_OFFSET_X 8
|
||||
#define STAR_OFFSET_Y 0
|
||||
|
||||
/* size of a tile */
|
||||
#define STAR_TILE_SIZE 6
|
||||
|
||||
/* bitmap of the wall */
|
||||
static unsigned char wall_bmp[STAR_TILE_SIZE]
|
||||
= {0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55};
|
||||
|
@ -171,6 +196,8 @@ static unsigned char ball_bmp[STAR_TILE_SIZE]
|
|||
static unsigned char block_bmp[STAR_TILE_SIZE]
|
||||
= {0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00};
|
||||
|
||||
#endif
|
||||
|
||||
/* bitmap of the arrow animation */
|
||||
static unsigned char arrow_bmp[4][7] =
|
||||
{
|
||||
|
@ -523,13 +550,26 @@ static void star_transition_update(void)
|
|||
*/
|
||||
static void star_display_board_info(void)
|
||||
{
|
||||
int label_offset_y = label_offset_y = LCD_HEIGHT - char_height;
|
||||
int label_offset_y = label_offset_y = LCD_HEIGHT - char_height - ( STAR_TILE_SIZE - char_height ) / 2 ;
|
||||
char str_info[32];
|
||||
|
||||
rb->snprintf(str_info, sizeof(str_info), "L:%02d S:%02d C:",
|
||||
current_level, star_count);
|
||||
rb->lcd_putsxy(0, label_offset_y, str_info);
|
||||
|
||||
#if HAVE_LCD_COLOR
|
||||
if( control == STAR_CONTROL_BALL )
|
||||
rb->lcd_bitmap_part( star_tiles, 0,
|
||||
ball*STAR_TILE_SIZE, STAR_TILE_SIZE,
|
||||
107, label_offset_y - ( STAR_TILE_SIZE - char_height ) / 2 + 1,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
else
|
||||
rb->lcd_bitmap_part( star_tiles, 0,
|
||||
block*STAR_TILE_SIZE, STAR_TILE_SIZE,
|
||||
107, label_offset_y - ( STAR_TILE_SIZE - char_height ) / 2 + 1,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
rb->lcd_update_rect(0, label_offset_y - ( STAR_TILE_SIZE - char_height ) / 2 + 1, LCD_WIDTH, STAR_TILE_SIZE );
|
||||
#else
|
||||
if (control == STAR_CONTROL_BALL)
|
||||
rb->lcd_mono_bitmap (ball_bmp, 103, label_offset_y + 1, STAR_TILE_SIZE,
|
||||
STAR_TILE_SIZE);
|
||||
|
@ -538,6 +578,8 @@ static void star_display_board_info(void)
|
|||
STAR_TILE_SIZE);
|
||||
|
||||
rb->lcd_update_rect(0, label_offset_y, LCD_WIDTH, char_height);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -562,41 +604,46 @@ static int star_load_level(int current_level)
|
|||
board[y][x] = *ptr_tab;
|
||||
switch (*ptr_tab)
|
||||
{
|
||||
#if HAVE_LCD_COLOR
|
||||
# define DRAW_TILE( a ) \
|
||||
rb->lcd_bitmap_part( star_tiles, 0, \
|
||||
a*STAR_TILE_SIZE, STAR_TILE_SIZE, \
|
||||
STAR_OFFSET_X + x * STAR_TILE_SIZE, \
|
||||
STAR_OFFSET_Y + y * STAR_TILE_SIZE, \
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
#else
|
||||
# define DRAW_TILE( a ) \
|
||||
rb->lcd_mono_bitmap ( a # bmp, \
|
||||
STAR_OFFSET_X + x * STAR_TILE_SIZE, \
|
||||
STAR_OFFSET_Y + y * STAR_TILE_SIZE, \
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
#endif
|
||||
case STAR_VOID:
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
DRAW_TILE( space );
|
||||
#endif
|
||||
break;
|
||||
|
||||
case STAR_WALL:
|
||||
rb->lcd_mono_bitmap (wall_bmp,
|
||||
STAR_OFFSET_X + x * STAR_TILE_SIZE,
|
||||
STAR_OFFSET_Y + y * STAR_TILE_SIZE,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
DRAW_TILE( wall );
|
||||
break;
|
||||
|
||||
case STAR_STAR:
|
||||
rb->lcd_mono_bitmap (star_bmp,
|
||||
STAR_OFFSET_X + x * STAR_TILE_SIZE,
|
||||
STAR_OFFSET_Y + y * STAR_TILE_SIZE,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
DRAW_TILE( star );
|
||||
star_count++;
|
||||
break;
|
||||
|
||||
case STAR_BALL:
|
||||
ball_x = x;
|
||||
ball_y = y;
|
||||
rb->lcd_mono_bitmap (ball_bmp,
|
||||
STAR_OFFSET_X + x * STAR_TILE_SIZE,
|
||||
STAR_OFFSET_Y + y * STAR_TILE_SIZE,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
DRAW_TILE( ball );
|
||||
break;
|
||||
|
||||
|
||||
case STAR_BLOCK:
|
||||
block_x = x;
|
||||
block_y = y;
|
||||
rb->lcd_mono_bitmap (block_bmp,
|
||||
STAR_OFFSET_X + x * STAR_TILE_SIZE,
|
||||
STAR_OFFSET_Y + y * STAR_TILE_SIZE,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
DRAW_TILE( block );
|
||||
break;
|
||||
}
|
||||
ptr_tab++;
|
||||
|
@ -709,18 +756,35 @@ static int star_run_game(void)
|
|||
|| board[ball_y + move_y][ball_x + move_x] == STAR_STAR))
|
||||
|
||||
{
|
||||
for (i = 0 ; i < 7 ; i++)
|
||||
for (i = 0 ; i <= STAR_TILE_SIZE ; i++)
|
||||
{
|
||||
#if HAVE_LCD_COLOR
|
||||
rb->lcd_bitmap_part(
|
||||
star_tiles, 0, space * STAR_TILE_SIZE, STAR_TILE_SIZE,
|
||||
STAR_OFFSET_X + ball_x * STAR_TILE_SIZE,
|
||||
STAR_OFFSET_Y + ball_y * STAR_TILE_SIZE,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
rb->lcd_bitmap_part(
|
||||
star_tiles, 0, ball * STAR_TILE_SIZE, STAR_TILE_SIZE,
|
||||
STAR_OFFSET_X + ball_x * STAR_TILE_SIZE + move_x * i,
|
||||
STAR_OFFSET_Y + ball_y * STAR_TILE_SIZE + move_y * i,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
rb->lcd_update_rect(
|
||||
STAR_OFFSET_X + ball_x * STAR_TILE_SIZE + move_x * (i>0?i-1:0),
|
||||
STAR_OFFSET_Y + ball_y * STAR_TILE_SIZE + move_y * (i>0?i-1:0),
|
||||
STAR_TILE_SIZE+(i>0?0:1), STAR_TILE_SIZE+(i>0?0:1));
|
||||
#else
|
||||
rb->lcd_mono_bitmap(
|
||||
ball_bmp,
|
||||
STAR_OFFSET_X + ball_x * STAR_TILE_SIZE + move_x * i,
|
||||
STAR_OFFSET_Y + ball_y * STAR_TILE_SIZE + move_y * i,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
|
||||
rb->lcd_update_rect(
|
||||
STAR_OFFSET_X + ball_x * STAR_TILE_SIZE + move_x * i,
|
||||
STAR_OFFSET_Y + ball_y * STAR_TILE_SIZE + move_y * i,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
#endif
|
||||
|
||||
rb->sleep(STAR_SLEEP);
|
||||
}
|
||||
ball_x += move_x;
|
||||
|
@ -741,18 +805,34 @@ static int star_run_game(void)
|
|||
board[block_y][block_x] = STAR_VOID;
|
||||
while (board[block_y + move_y][block_x + move_x] == STAR_VOID)
|
||||
{
|
||||
for (i = 0 ; i < 7 ; i++)
|
||||
for (i = 0 ; i <= STAR_TILE_SIZE ; i++)
|
||||
{
|
||||
#if HAVE_LCD_COLOR
|
||||
rb->lcd_bitmap_part(
|
||||
star_tiles, 0, space * STAR_TILE_SIZE, STAR_TILE_SIZE,
|
||||
STAR_OFFSET_X + block_x * STAR_TILE_SIZE,
|
||||
STAR_OFFSET_Y + block_y * STAR_TILE_SIZE,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
rb->lcd_bitmap_part(
|
||||
star_tiles, 0, block * STAR_TILE_SIZE, STAR_TILE_SIZE,
|
||||
STAR_OFFSET_X + block_x * STAR_TILE_SIZE + move_x * i,
|
||||
STAR_OFFSET_Y + block_y * STAR_TILE_SIZE + move_y * i,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
rb->lcd_update_rect(
|
||||
STAR_OFFSET_X + block_x * STAR_TILE_SIZE + move_x * (i>0?i-1:0),
|
||||
STAR_OFFSET_Y + block_y * STAR_TILE_SIZE + move_y * (i>0?i-1:0),
|
||||
STAR_TILE_SIZE+(i>0?0:1), STAR_TILE_SIZE+(i>0?0:1));
|
||||
#else
|
||||
rb->lcd_mono_bitmap(
|
||||
block_bmp,
|
||||
STAR_OFFSET_X + block_x * STAR_TILE_SIZE + move_x * i,
|
||||
STAR_OFFSET_Y + block_y * STAR_TILE_SIZE + move_y * i,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
|
||||
rb->lcd_update_rect(
|
||||
STAR_OFFSET_X + block_x * STAR_TILE_SIZE + move_x * i,
|
||||
STAR_OFFSET_Y + block_y * STAR_TILE_SIZE + move_y * i,
|
||||
STAR_TILE_SIZE, STAR_TILE_SIZE);
|
||||
#endif
|
||||
|
||||
rb->sleep(STAR_SLEEP);
|
||||
}
|
||||
|
@ -912,6 +992,11 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|||
if (char_width == -1)
|
||||
rb->lcd_getstringsize("a", &char_width, &char_height);
|
||||
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
rb->lcd_set_background( LCD_BLACK );
|
||||
rb->lcd_set_foreground( LCD_WHITE );
|
||||
#endif
|
||||
|
||||
/* display choice menu */
|
||||
return star_menu();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue