From owner-freebsd-hackers Wed May 21 13:16:40 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id NAA03244 for hackers-outgoing; Wed, 21 May 1997 13:16:40 -0700 (PDT) Received: from angst.it.hq.nasa.gov (Angst.it.hq.nasa.gov [131.182.119.89]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id NAA03228 for ; Wed, 21 May 1997 13:16:30 -0700 (PDT) Received: (from root@localhost) by angst.it.hq.nasa.gov (8.8.5/8.7.3) id QAA00293; Wed, 21 May 1997 16:18:23 -0400 (EDT) Date: Wed, 21 May 1997 16:18:23 -0400 (EDT) Message-Id: <199705212018.QAA00293@angst.it.hq.nasa.gov> From: Chris Shenton To: hackers@freebsd.org Subject: Dancing daemon saver -- flips left and right PATCH Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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. + */ + + 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) {