summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/snake2.c171
1 files changed, 129 insertions, 42 deletions
diff --git a/apps/plugins/snake2.c b/apps/plugins/snake2.c
index dae20344f0..d858976a31 100644
--- a/apps/plugins/snake2.c
+++ b/apps/plugins/snake2.c
@@ -543,44 +543,62 @@ void init_snake(void)
543 new_level(level_from_file); 543 new_level(level_from_file);
544} 544}
545 545
546#if (LCD_WIDTH >= 160) && (LCD_HEIGHT >= 128)
547void draw_frame_bitmap(int header_type)
548{
549 rb->lcd_bitmap(header_type==1? snake2_header1: snake2_header2, 0, 0,
550 BMPWIDTH_snake2_header, BMPHEIGHT_snake2_header);
551 rb->lcd_bitmap(snake2_left, 0, BMPHEIGHT_snake2_header,
552 BMPWIDTH_snake2_left, BMPHEIGHT_snake2_left);
553 rb->lcd_bitmap(snake2_right,
554 LCD_WIDTH - BMPWIDTH_snake2_right, BMPHEIGHT_snake2_header,
555 BMPWIDTH_snake2_right, BMPHEIGHT_snake2_right);
556 rb->lcd_bitmap(snake2_bottom,
557 0, BMPHEIGHT_snake2_header + BMPHEIGHT_snake2_left,
558 BMPWIDTH_snake2_bottom, BMPHEIGHT_snake2_bottom);
559}
560#endif
561
546/* 562/*
547** Draws the apple. If it doesn't exist then 563** Draws the apple. If it doesn't exist then
548** a new one get's created. 564** a new one get's created.
549*/ 565*/
566void draw_apple_bit(int x, int y)
567{
568 rb->lcd_fillrect((CENTER_X+x*MULTIPLIER)+1, CENTER_Y+y*MULTIPLIER,
569 MODIFIER_2, MODIFIER_1);
570 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER, (CENTER_Y+y*MULTIPLIER)+1,
571 MODIFIER_1, MODIFIER_2);
572}
573
550void draw_apple( void ) 574void draw_apple( void )
551{ 575{
552 int x,y; 576 int x,y;
553 577
554#if LCD_WIDTH >= 160 && LCD_HEIGHT >= 128 578#if LCD_WIDTH >= 160 && LCD_HEIGHT >= 128
555 char pscore[5], counter[4]; 579 draw_frame_bitmap(2);
556
557 rb->lcd_bitmap(snake2_header2,0,0,BMPWIDTH_snake2_header, BMPHEIGHT_snake2_header);
558 rb->lcd_bitmap(snake2_left,0,BMPHEIGHT_snake2_header,BMPWIDTH_snake2_left, BMPHEIGHT_snake2_left);
559 rb->lcd_bitmap(snake2_right,LCD_WIDTH-BMPWIDTH_snake2_right,BMPHEIGHT_snake2_header,BMPWIDTH_snake2_right, BMPHEIGHT_snake2_right);
560 rb->lcd_bitmap(snake2_bottom,0,BMPHEIGHT_snake2_header+BMPHEIGHT_snake2_left,BMPWIDTH_snake2_bottom, BMPHEIGHT_snake2_bottom);
561 580
562 rb->snprintf(counter,sizeof(counter),"%d",applecount); 581 rb->snprintf(strbuf, sizeof(strbuf), "%d", applecount);
563 rb->lcd_getstringsize(counter,&strwdt,&strhgt); 582 rb->lcd_getstringsize(strbuf, &strwdt, &strhgt);
564 rb->lcd_putsxy(TOP_X3-strwdt/2,TOP_Y2,counter); 583 rb->lcd_putsxy(TOP_X3 - strwdt/2, TOP_Y2, strbuf);
565 584
566 rb->snprintf(pscore,sizeof(pscore),"%d",score); 585 rb->snprintf(strbuf, sizeof(strbuf), "%d", score);
567 rb->lcd_getstringsize(pscore,&strwdt,&strhgt); 586 rb->lcd_getstringsize(strbuf, &strwdt, &strhgt);
568 rb->lcd_putsxy(TOP_X4-strwdt/2,TOP_Y2,pscore); 587 rb->lcd_putsxy(TOP_X4 - strwdt/2, TOP_Y2, strbuf);
569#endif 588#endif
570 589
571 if (!apple) 590 if (!apple)
572 { 591 {
573 do 592 do
574 { 593 {
575 x = (rb->rand() % (WIDTH-1))+1; 594 x = (rb->rand() % (WIDTH-1))+1;
576 y = (rb->rand() % (HEIGHT-1))+1; 595 y = (rb->rand() % (HEIGHT-1))+1;
577 } while (board[x][y]); 596 } while (board[x][y]);
578 apple=1; 597 apple = 1;
579 board[x][y]=-1; 598 board[x][y] = -1;
580 applex = x;appley = y; 599 applex = x;appley = y;
581 } 600 }
582 rb->lcd_fillrect((CENTER_X+applex*MULTIPLIER)+1,CENTER_Y+appley*MULTIPLIER,MODIFIER_2,MODIFIER_1); 601 draw_apple_bit(applex, appley);
583 rb->lcd_fillrect(CENTER_X+applex*MULTIPLIER,(CENTER_Y+appley*MULTIPLIER)+1,MODIFIER_1,MODIFIER_2);
584} 602}
585 603
586/* 604/*
@@ -591,7 +609,8 @@ void draw_apple( void )
591*/ 609*/
592void draw_vertical_bit(int x, int y) 610void draw_vertical_bit(int x, int y)
593{ 611{
594 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+1,CENTER_Y+y*MULTIPLIER,MODIFIER_2,MODIFIER_1); 612 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+1, CENTER_Y+y*MULTIPLIER,
613 MODIFIER_2, MODIFIER_1);
595} 614}
596 615
597/* 616/*
@@ -602,7 +621,8 @@ void draw_vertical_bit(int x, int y)
602*/ 621*/
603void draw_horizontal_bit(int x, int y) 622void draw_horizontal_bit(int x, int y)
604{ 623{
605 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER,CENTER_Y+y*MULTIPLIER+1,MODIFIER_1,MODIFIER_2); 624 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER, CENTER_Y+y*MULTIPLIER+1,
625 MODIFIER_1, MODIFIER_2);
606} 626}
607 627
608/* 628/*
@@ -613,8 +633,10 @@ void draw_horizontal_bit(int x, int y)
613*/ 633*/
614void draw_n_to_e_bit(int x, int y) 634void draw_n_to_e_bit(int x, int y)
615{ 635{
616 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+1,CENTER_Y+y*MULTIPLIER+2,MODIFIER_2,MODIFIER_2); 636 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+1, CENTER_Y+y*MULTIPLIER+2,
617 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+2,CENTER_Y+y*MULTIPLIER+1,MODIFIER_2,MODIFIER_2); 637 MODIFIER_2, MODIFIER_2);
638 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+2, CENTER_Y+y*MULTIPLIER+1,
639 MODIFIER_2, MODIFIER_2);
618} 640}
619 641
620/* 642/*
@@ -636,8 +658,10 @@ void draw_w_to_s_bit(int x, int y)
636*/ 658*/
637void draw_n_to_w_bit(int x, int y) 659void draw_n_to_w_bit(int x, int y)
638{ 660{
639 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER,CENTER_Y+y*MULTIPLIER+1,MODIFIER_2,MODIFIER_2); 661 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER, CENTER_Y+y*MULTIPLIER+1,
640 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+1,CENTER_Y+y*MULTIPLIER+2,MODIFIER_2,MODIFIER_2); 662 MODIFIER_2, MODIFIER_2);
663 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+1, CENTER_Y+y*MULTIPLIER+2,
664 MODIFIER_2, MODIFIER_2);
641} 665}
642 666
643/* 667/*
@@ -659,8 +683,10 @@ void draw_e_to_s_bit(int x, int y)
659*/ 683*/
660void draw_s_to_e_bit(int x, int y) 684void draw_s_to_e_bit(int x, int y)
661{ 685{
662 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+1,CENTER_Y+y*MULTIPLIER,MODIFIER_2,MODIFIER_2); 686 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+1, CENTER_Y+y*MULTIPLIER,
663 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+2,CENTER_Y+y*MULTIPLIER+1,MODIFIER_2,MODIFIER_2); 687 MODIFIER_2, MODIFIER_2);
688 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+2, CENTER_Y+y*MULTIPLIER+1,
689 MODIFIER_2, MODIFIER_2);
664} 690}
665 691
666/* 692/*
@@ -682,8 +708,10 @@ void draw_w_to_n_bit(int x, int y)
682*/ 708*/
683void draw_e_to_n_bit(int x, int y) 709void draw_e_to_n_bit(int x, int y)
684{ 710{
685 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+1,CENTER_Y+y*MULTIPLIER,MODIFIER_2,MODIFIER_2); 711 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER+1, CENTER_Y+y*MULTIPLIER,
686 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER,CENTER_Y+y*MULTIPLIER+1,MODIFIER_2,MODIFIER_2); 712 MODIFIER_2, MODIFIER_2);
713 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER, CENTER_Y+y*MULTIPLIER+1,
714 MODIFIER_2, MODIFIER_2);
687} 715}
688 716
689/* 717/*
@@ -697,6 +725,12 @@ void draw_s_to_w_bit(int x, int y)
697 draw_e_to_n_bit(x, y); 725 draw_e_to_n_bit(x, y);
698} 726}
699 727
728void draw_head_bit(int x, int y)
729{
730 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER, CENTER_Y+y*MULTIPLIER,
731 MODIFIER_1, MODIFIER_1);
732}
733
700/* 734/*
701** Draws a wall/obsticals 735** Draws a wall/obsticals
702*/ 736*/
@@ -748,8 +782,7 @@ void redraw (void)
748 switch (board[x][y]) 782 switch (board[x][y])
749 { 783 {
750 case -1: 784 case -1:
751 rb->lcd_fillrect((CENTER_X+x*MULTIPLIER)+1,CENTER_Y+y*MULTIPLIER,MODIFIER_2,MODIFIER_1); 785 draw_apple_bit(x, y);
752 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER,(CENTER_Y+y*MULTIPLIER)+1,MODIFIER_1,MODIFIER_2);
753 break; 786 break;
754 case 0: 787 case 0:
755 break; 788 break;
@@ -765,11 +798,23 @@ void redraw (void)
765 break; 798 break;
766 799
767 default: 800 default:
768 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER,CENTER_Y+y*MULTIPLIER,MODIFIER_1,MODIFIER_1); 801 draw_head_bit(x, y);
769 break; 802 break;
770 } 803 }
771 } 804 }
772 } 805 }
806
807#if LCD_WIDTH >= 160 && LCD_HEIGHT >= 128
808 draw_frame_bitmap(2);
809
810 rb->snprintf(strbuf, sizeof(strbuf), "%d", applecount);
811 rb->lcd_getstringsize(strbuf, &strwdt, &strhgt);
812 rb->lcd_putsxy(TOP_X3 - strwdt/2, TOP_Y2, strbuf);
813
814 rb->snprintf(strbuf, sizeof(strbuf), "%d", score);
815 rb->lcd_getstringsize(strbuf, &strwdt, &strhgt);
816 rb->lcd_putsxy(TOP_X4 - strwdt/2, TOP_Y2, strbuf);
817#endif
773} 818}
774 819
775/* 820/*
@@ -779,7 +824,7 @@ void redraw (void)
779void draw_snake_bit(int currentbit, int previousbit, int x, int y) 824void draw_snake_bit(int currentbit, int previousbit, int x, int y)
780{ 825{
781 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); 826 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
782 rb->lcd_fillrect(CENTER_X+x*MULTIPLIER,CENTER_Y+y*MULTIPLIER,MODIFIER_1,MODIFIER_1); 827 draw_head_bit(x, y);
783 rb->lcd_set_drawmode(DRMODE_SOLID); 828 rb->lcd_set_drawmode(DRMODE_SOLID);
784 829
785 switch(currentbit) 830 switch(currentbit)
@@ -858,6 +903,50 @@ void draw_snake_bit(int currentbit, int previousbit, int x, int y)
858 } 903 }
859} 904}
860 905
906void redraw_snake(void)
907{
908 int x = tailx, y = taily;
909 int olddir, newdir = board[x][y];
910
911 while (x != headx || y != heady)
912 {
913 olddir = newdir;
914
915 switch (olddir)
916 {
917 case(NORTH):
918 y--;
919 break;
920
921 case(EAST):
922 x++;
923 break;
924
925 case(SOUTH):
926 y++;
927 break;
928
929 case(WEST):
930 x--;
931 break;
932 }
933
934 if(x == WIDTH)
935 x = 0;
936 else if(x < 0)
937 x = WIDTH-1;
938
939 if(y == HEIGHT)
940 y = 0;
941 else if(y < 0)
942 y = HEIGHT-1;
943
944 newdir = board[x][y];
945 if(olddir != newdir)
946 draw_snake_bit(newdir, olddir, x, y);
947 }
948}
949
861/* 950/*
862** Death 'sequence' and end game stuff. 951** Death 'sequence' and end game stuff.
863*/ 952*/
@@ -1004,13 +1093,13 @@ void move( void )
1004 else if(heady < 0) 1093 else if(heady < 0)
1005 heady = HEIGHT-1; 1094 heady = HEIGHT-1;
1006 1095
1007 rb->lcd_fillrect(CENTER_X+headx*MULTIPLIER,CENTER_Y+heady*MULTIPLIER,MODIFIER_1,MODIFIER_1); 1096 draw_head_bit(headx, heady);
1008 1097
1009 /*clear tail*/ 1098 /*clear tail*/
1010 if(applecountdown <= 0) 1099 if(applecountdown <= 0)
1011 { 1100 {
1012 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); 1101 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1013 rb->lcd_fillrect(CENTER_X+tailx*MULTIPLIER,CENTER_Y+taily*MULTIPLIER,MODIFIER_1,MODIFIER_1); 1102 draw_head_bit(tailx, taily);
1014 rb->lcd_set_drawmode(DRMODE_SOLID); 1103 rb->lcd_set_drawmode(DRMODE_SOLID);
1015 1104
1016 taildir = board[tailx][taily]; 1105 taildir = board[tailx][taily];
@@ -1123,6 +1212,8 @@ void game_pause (void)
1123 { 1212 {
1124 case SNAKE2_PLAYPAUSE: 1213 case SNAKE2_PLAYPAUSE:
1125 redraw(); 1214 redraw();
1215 redraw_snake();
1216 draw_head_bit(headx, heady);
1126 rb->lcd_update(); 1217 rb->lcd_update();
1127 rb->sleep(HZ/2); 1218 rb->sleep(HZ/2);
1128 return; 1219 return;
@@ -1217,7 +1308,7 @@ void game (void)
1217 case SNAKE2_RC_QUIT: 1308 case SNAKE2_RC_QUIT:
1218#endif 1309#endif
1219 case SNAKE2_QUIT: 1310 case SNAKE2_QUIT:
1220 dead=1; 1311 quit = 1;
1221 return; 1312 return;
1222 1313
1223 case SNAKE2_PLAYPAUSE: 1314 case SNAKE2_PLAYPAUSE:
@@ -1247,11 +1338,7 @@ void select_maze(void)
1247 while (1) 1338 while (1)
1248 { 1339 {
1249#if LCD_WIDTH >= 160 && LCD_HEIGHT >= 128 1340#if LCD_WIDTH >= 160 && LCD_HEIGHT >= 128
1250 1341 draw_frame_bitmap(1);
1251 rb->lcd_bitmap(snake2_header1,0,0,BMPWIDTH_snake2_header, BMPHEIGHT_snake2_header);
1252 rb->lcd_bitmap(snake2_left,0,BMPHEIGHT_snake2_header,BMPWIDTH_snake2_left, BMPHEIGHT_snake2_left);
1253 rb->lcd_bitmap(snake2_right,LCD_WIDTH-BMPWIDTH_snake2_right,BMPHEIGHT_snake2_header,BMPWIDTH_snake2_right, BMPHEIGHT_snake2_right);
1254 rb->lcd_bitmap(snake2_bottom,0,BMPHEIGHT_snake2_header+BMPHEIGHT_snake2_left,BMPWIDTH_snake2_bottom, BMPHEIGHT_snake2_bottom);
1255 1342
1256 rb->snprintf(strbuf, sizeof(strbuf), "%d", level); 1343 rb->snprintf(strbuf, sizeof(strbuf), "%d", level);
1257 rb->lcd_getstringsize(strbuf, &strwdt, &strhgt); 1344 rb->lcd_getstringsize(strbuf, &strwdt, &strhgt);