summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2006-09-15 06:24:36 +0000
committerJens Arnold <amiconn@rockbox.org>2006-09-15 06:24:36 +0000
commit1350d57751f30f1700912e6abaa1d845af973f75 (patch)
tree360853ac291757da82ec2fbbd9ee278ea76bc451
parent2fb102ef04f12080ed5e26f2504cd4e78b5ff33e (diff)
downloadrockbox-1350d57751f30f1700912e6abaa1d845af973f75.tar.gz
rockbox-1350d57751f30f1700912e6abaa1d845af973f75.zip
Solitaire: * Even more 'natural' bouncing cards. * Only load the config from disk once, and only save it on exit if it changed.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10949 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/solitaire.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c
index 707d9b5c00..129f5c5d3e 100644
--- a/apps/plugins/solitaire.c
+++ b/apps/plugins/solitaire.c
@@ -589,12 +589,15 @@ enum help solitaire_help( void )
589 * 589 *
590 * TODO: use rockbox api menus instead 590 * TODO: use rockbox api menus instead
591 */ 591 */
592 592
593#define CFGFILE_VERSION 0 593#define CFGFILE_VERSION 0
594int draw_type; 594
595/* introduce a struct if there's more than one setting */
596int draw_type_disk = 0;
597int draw_type;
595 598
596static struct configdata config[] = { 599static struct configdata config[] = {
597 { TYPE_INT, 0, 1, &draw_type, "draw_type", NULL, NULL } 600 { TYPE_INT, 0, 1, &draw_type_disk, "draw_type", NULL, NULL }
598}; 601};
599 602
600/* menu return codes */ 603/* menu return codes */
@@ -1072,7 +1075,7 @@ enum { SOLITAIRE_WIN, SOLITAIRE_QUIT, SOLITAIRE_USB };
1072 */ 1075 */
1073int bouncing_cards( void ) 1076int bouncing_cards( void )
1074{ 1077{
1075 int i, j, x, y, vx, vy, button; 1078 int i, j, x, vx, y, fp_y, fp_vy, button;
1076 1079
1077 /* flush the button queue */ 1080 /* flush the button queue */
1078 while( ( button = rb->button_get( false ) ) != BUTTON_NONE ) 1081 while( ( button = rb->button_get( false ) ) != BUTTON_NONE )
@@ -1087,23 +1090,24 @@ int bouncing_cards( void )
1087 for( j = 0; j < SUITS; j++ ) 1090 for( j = 0; j < SUITS; j++ )
1088 { 1091 {
1089 x = LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*j+j+1; 1092 x = LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*j+j+1;
1090 y = MARGIN; 1093 fp_y = MARGIN<<8;
1091 1094
1092 vx = rb->rand()%8-5; 1095 vx = rb->rand()%8-5;
1093 if( !vx ) vx = -6; 1096 if( !vx ) vx = -6;
1094 1097
1095 vy = -rb->rand()%(6<<8); 1098 fp_vy = -rb->rand()%(6<<8);
1096 1099
1097 while( x < LCD_WIDTH && x + CARD_WIDTH > 0 ) 1100 while( x < LCD_WIDTH && x + CARD_WIDTH > 0 )
1098 { 1101 {
1099 vy += (1<<8); 1102 fp_vy += 1<<8;
1100 x += vx; 1103 x += vx;
1101 y += vy >> 8; 1104 fp_y += fp_vy;
1102 if( y + CARD_HEIGHT >= LCD_HEIGHT ) 1105 if( fp_y >= (LCD_HEIGHT-CARD_HEIGHT) << 8 )
1103 { 1106 {
1104 vy = -vy*3/4; 1107 fp_vy = -fp_vy*3/4;
1105 y = LCD_HEIGHT - CARD_HEIGHT; 1108 fp_y = (LCD_HEIGHT-CARD_HEIGHT) << 8;
1106 } 1109 }
1110 y = fp_y >> 8;
1107 draw_card( deck[j*CARDS_PER_SUIT+i], x, y, 1111 draw_card( deck[j*CARDS_PER_SUIT+i], x, y,
1108 false, false, false ); 1112 false, false, false );
1109 rb->lcd_update_rect( x<0?0:x, y<0?0:y, 1113 rb->lcd_update_rect( x<0?0:x, y<0?0:y,
@@ -1132,9 +1136,6 @@ int solitaire( void )
1132 unsigned char c,h,prevcard; 1136 unsigned char c,h,prevcard;
1133 int biggest_col_length; 1137 int biggest_col_length;
1134 1138
1135 configfile_init(rb);
1136 configfile_load(CONFIG_FILENAME, config, 1, 0);
1137
1138 rb->srand( *rb->current_tick ); 1139 rb->srand( *rb->current_tick );
1139 switch( solitaire_menu( draw_type == 0 ? MENU_BEFOREGAME 1140 switch( solitaire_menu( draw_type == 0 ? MENU_BEFOREGAME
1140 : MENU_BEFOREGAMEOP ) ) 1141 : MENU_BEFOREGAMEOP ) )
@@ -1147,7 +1148,6 @@ int solitaire( void )
1147 1148
1148 case MENU_OPT: 1149 case MENU_OPT:
1149 draw_type = (draw_type+1)%2; 1150 draw_type = (draw_type+1)%2;
1150 configfile_save(CONFIG_FILENAME, config, 1, 0);
1151 return 0; 1151 return 0;
1152 } 1152 }
1153 solitaire_init(); 1153 solitaire_init();
@@ -1614,10 +1614,20 @@ enum plugin_status plugin_start( struct plugin_api* api, void* parameter )
1614 1614
1615 rb->splash( HZ, true, "Welcome to Solitaire!" ); 1615 rb->splash( HZ, true, "Welcome to Solitaire!" );
1616 1616
1617 configfile_init(rb);
1618 configfile_load(CONFIG_FILENAME, config, 1, 0);
1619 draw_type = draw_type_disk;
1620
1617 /* play the game :) 1621 /* play the game :)
1618 * Keep playing if a game was won (that means display the menu after 1622 * Keep playing if a game was won (that means display the menu after
1619 * winning instead of quiting) */ 1623 * winning instead of quiting) */
1620 while( ( result = solitaire() ) == SOLITAIRE_WIN ); 1624 while( ( result = solitaire() ) == SOLITAIRE_WIN );
1625
1626 if (draw_type != draw_type_disk)
1627 {
1628 draw_type_disk = draw_type;
1629 configfile_save(CONFIG_FILENAME, config, 1, 0);
1630 }
1621 1631
1622 /* Exit the plugin */ 1632 /* Exit the plugin */
1623 return ( result == SOLITAIRE_USB ) ? PLUGIN_USB_CONNECTED : PLUGIN_OK; 1633 return ( result == SOLITAIRE_USB ) ? PLUGIN_USB_CONNECTED : PLUGIN_OK;