with colors!

This commit is contained in:
Gwenhael Le Moine 2011-07-01 17:22:14 +02:00
parent d20d0885b4
commit 6ffa3ef86d

37
star.c
View file

@ -8,6 +8,15 @@
#define LEVEL_HEIGHT 9
#define LEVEL_WIDTH 16
enum { color_BALL = 1,
color_CUBE,
color_VOID,
color_GIFT,
color_WALL,
color_BALL_SELECTED,
color_CUBE_SELECTED,
};
typedef enum {
WALL ='#',
BALL ='@',
@ -396,14 +405,22 @@ void display_level( struct state *s )
for( j = 0 ; j < LEVEL_WIDTH ; j++ ) {
switch( get_cell( s, j, i ) ) {
case WALL:
attron( COLOR_PAIR( color_WALL ));
mvprintw( i+1, j*2, "##" );
attroff( COLOR_PAIR( color_WALL ));
break;
case VOID:
attron( COLOR_PAIR( color_VOID ));
mvprintw( i+1, j*2, " " );
attroff( COLOR_PAIR( color_VOID ));
break;
case BALL:
if ( s->moving == BALL ) {
attron( A_BOLD );
attron( COLOR_PAIR( color_BALL_SELECTED ));
}
else {
attron( COLOR_PAIR( color_BALL ));
}
mvprintw( i+1, j*2, "()" );
if ( s->moving == BALL ) {
@ -413,14 +430,24 @@ void display_level( struct state *s )
case CUBE:
if ( s->moving == CUBE ) {
attron( A_BOLD );
attron( COLOR_PAIR( color_BALL_SELECTED ));
}
else {
attron( COLOR_PAIR( color_BALL ));
}
mvprintw( i+1, j*2, "[]" );
if ( s->moving == CUBE ) {
attroff( A_BOLD );
attroff( COLOR_PAIR( color_CUBE_SELECTED ));
}
else {
attroff( COLOR_PAIR( color_CUBE ));
}
break;
case GIFT:
attron( COLOR_PAIR( color_GIFT ));
mvprintw( i+1, j*2, "<>" );
attroff( COLOR_PAIR( color_GIFT ));
break;
default: break; /* ignore newlines */
}
@ -444,6 +471,16 @@ int main( int argc, char* argv[] )
nonl();
intrflush( w_main, FALSE );
keypad( w_main, TRUE );
/* if ( has_colors( ) == TRUE ) { */
start_color( );
init_pair( color_CUBE, COLOR_RED, COLOR_BLACK );
init_pair( color_BALL, COLOR_BLUE, COLOR_BLACK );
init_pair( color_GIFT, COLOR_YELLOW, COLOR_BLACK );
init_pair( color_WALL, COLOR_WHITE, COLOR_WHITE );
init_pair( color_VOID, COLOR_BLACK, COLOR_BLACK );
init_pair( color_CUBE_SELECTED, COLOR_RED, COLOR_YELLOW );
init_pair( color_BALL_SELECTED, COLOR_BLUE, COLOR_YELLOW );
/* } */
/* load the first level to start the loop in a correct state */
load_level( s, levels[ lvl ] );