Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: Re: snake patch
From: lithermon (rockbox_at_durbrain.dialstart.net)
Date: 2002-09-11


thanks for the snake game itai,
i done a patch so snake can be controlled by 'steering' it
this is choosable on the screen befor the game.
i hope the code is alright it is my first go at c code
/lither
heh better attach it tho


--- apps/recorder/snake.c Tue Sep 10 16:55:37 2002
+++ snake.c Wed Sep 11 08:20:35 2002
@@ -24,7 +24,7 @@
 
 int board[28][16],snakelength;
 unsigned int score,hiscore=0;
-short dir,frames,apple,level=1,dead=0;
+short dir,frames,apple,level=5,dead=0,steer=0;
 
 int rand_num (int range) {
     return current_tick % range;
@@ -183,16 +183,28 @@
 
         switch (button_get(false)) {
              case BUTTON_UP:
- if (dir!=2) dir=0;
+ if (dir!=2 && steer!=1) dir=0;
                  break;
              case BUTTON_RIGHT:
- if (dir!=3) dir=1;
+ if (steer!=1) {
+ if (dir!=3) dir=1;
+ }
+ else {
+ dir++;
+ if (dir==4) dir=0;
+ }
                  break;
              case BUTTON_DOWN:
- if (dir!=0) dir=2;
+ if (dir!=0 && steer!=1) dir=2;
                  break;
              case BUTTON_LEFT:
- if (dir!=1) dir=3;
+ if (steer!=1) {
+ if (dir!=1) dir=3;
+ }
+ else {
+ if (dir==0) dir=4;
+ dir--;
+ }
                  break;
              case BUTTON_OFF:
                  dead=1;
@@ -228,16 +240,29 @@
     lcd_putsxy(3,22, "[off] to quit",0);
     lcd_putsxy(3,32, "[play] to start/pause",0);
     lcd_putsxy(3,42, phscore,0);
+ if (steer!=1) {
+ lcd_putsxy(3,52, "Control - <direct>",0);
+ }
+ else {
+ lcd_putsxy(3,52, "Control - <steeer>",0);
+ }
     lcd_update();
 
     while (1) {
         switch (button_get(true)) {
             case BUTTON_RIGHT:
+ case BUTTON_LEFT:
+ if (steer!=1) {
+ steer=1;
+ }
+ else {
+ steer=0;
+ }
+ break;
             case BUTTON_UP:
                 if (level<9)
                     level++;
                 break;
- case BUTTON_LEFT:
             case BUTTON_DOWN:
                 if (level>1)
                     level--;
@@ -252,6 +277,12 @@
         }
         snprintf(plevel,sizeof(plevel),"Level - %d",level);
         lcd_putsxy(3,2, plevel,0);
+ if (steer!=1) {
+ lcd_putsxy(3,52, "Control - <direct>",0);
+ }
+ else {
+ lcd_putsxy(3,52, "Control - <steeer>",0);
+ }
         lcd_update();
     }
      



Page was last modified "Jan 10 2012" The Rockbox Crew
aaa