Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 May 1997 16:18:23 -0400 (EDT)
From:      Chris Shenton <cshenton@angst.it.hq.nasa.gov>
To:        hackers@freebsd.org
Subject:   Dancing daemon saver -- flips left and right PATCH
Message-ID:  <199705212018.QAA00293@angst.it.hq.nasa.gov>

next in thread | raw e-mail | index | archive | help
I didn't like how static the dancing daemon was, nor that it "walked"
backward. :-)

The following patch causes the daemon to flip direction when it hits
the wall: it points left when walking left, and right when moving
right. It's a hack but it works OK.

--Chris


*** daemon_saver.c	1997/05/19 16:05:51	1.1
--- daemon_saver.c	1997/05/21 20:11:35
***************
*** 95,103 ****
  	NULL
  };
  
  
  static void
! draw_daemon(int xpos, int ypos)
  {
  	int x, y;
  	int attr;
--- 95,122 ----
  	NULL
  };
  
+ /* Reverse a graphics character, or return unaltered if no mirror;
+  * should do alphanumerics too, but I'm too lazy. <cshenton@it.hq.nasa.gov>
+  */
+ 
+ static char
+ xflip_symbol(char symbol)
+ {
+   static char lchars[] = "`'(){}[]\\/<>";
+   static char rchars[] = "'`)(}{][/\\><";
+   int pos;			/* position in lchars */
+ 
+   for (pos = 0; lchars[pos] != NULL; pos++) {
+     if (lchars[pos] == symbol) {
+       return rchars[pos];
+     }
+   }
+   return symbol;
+ }
+ 
  
  static void
! draw_daemon(int xpos, int ypos, int dxdir)
  {
  	int x, y;
  	int attr;
***************
*** 111,121 ****
  		case 'W': attr = (FG_LIGHTGREY|BG_BLACK)<<8; break;
  		case 'C': attr = (FG_CYAN|BG_BLACK)<<8; break;
  		}
! 		*((u_short*)(Crtat + (ypos+y)*cur_console->xsize + xpos + x)) =
! 			scr_map[daemon_pic[y][x]]|attr;
  	}
  }
  
  static void
  draw_string(int xpos, int ypos, char *s, int len)
  {
--- 130,149 ----
  		case 'W': attr = (FG_LIGHTGREY|BG_BLACK)<<8; break;
  		case 'C': attr = (FG_CYAN|BG_BLACK)<<8; break;
  		}
! 		if (dxdir < 0) {	/* Moving left */
! 		  *((u_short*)(Crtat + (ypos+y)*cur_console->xsize
! 			       + xpos + x)) =
! 		    scr_map[daemon_pic[y][x]]|attr;
! 		}
! 		else {
! 		  *((u_short*)(Crtat + (ypos+y)*cur_console->xsize
! 			       + xpos + (DAEMON_MAX_WIDTH - x) )) =
! 		    scr_map[ xflip_symbol(daemon_pic[y][x]) ] |attr;
! 		}
  	}
  }
  
+ 
  static void
  draw_string(int xpos, int ypos, char *s, int len)
  {
***************
*** 176,182 ****
  		}
  		txpos += txdir; typos += tydir;
  
! 		draw_daemon(dxpos, dypos);
  		draw_string(txpos, typos, (char *)message, sizeof(message)-1);
  	} else {
  		if (scrn_blanked) {
--- 204,210 ----
  		}
  		txpos += txdir; typos += tydir;
  
! 		draw_daemon(dxpos, dypos, dxdir);
  		draw_string(txpos, typos, (char *)message, sizeof(message)-1);
  	} else {
  		if (scrn_blanked) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199705212018.QAA00293>