X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fpacman.c;h=58b2bed6114562d8d2b0f0e427646a5a748c09f8;hb=aa75c7476aeaa84cf3abc192b376a8b03c325213;hp=cf708f4af68c63ea700f2aeac442d929d4578886;hpb=c1b9b55ad8d59dc05ef55e316aebf5863e7dfa56;p=xscreensaver diff --git a/hacks/pacman.c b/hacks/pacman.c index cf708f4a..58b2bed6 100644 --- a/hacks/pacman.c +++ b/hacks/pacman.c @@ -1,9 +1,8 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* pacman --- Mr. Pacman and his ghost friends */ -#if !defined( lint ) && !defined( SABER ) +#if 0 static const char sccsid[] = "@(#)pacman.c 5.00 2000/11/01 xlockmore"; - #endif /*- @@ -56,7 +55,6 @@ static const char sccsid[] = "@(#)pacman.c 5.00 2000/11/01 xlockmore"; # define UNIFORM_COLORS # define BRIGHT_COLORS -# define reshape_pacman 0 # define pacman_handle_event 0 # include "xlockmore.h" /* in xscreensaver distribution */ # include @@ -108,6 +106,7 @@ static const char sccsid[] = "@(#)pacman.c 5.00 2000/11/01 xlockmore"; # include "images/pacman/pacman-ds8.xpm" #endif +#if 0 static const struct { int dx, dy; @@ -115,6 +114,7 @@ static const struct { 0, 1}, { 1, 0}, { 0, -1}}; +#endif #ifdef DISABLE_INTERACTIVE ENTRYPOINT ModeSpecOpt pacman_opts = { @@ -131,7 +131,7 @@ static XrmOptionDescRec opts[] = { }; static argtype vars[] = { - {&trackmouse, "trackmouse", "TrackMouse", DEF_TRACKMOUSE, t_Bool} + {&pacman_trackmouse, "trackmouse", "TrackMouse", DEF_TRACKMOUSE, t_Bool} }; static OptionStruct desc[] = { @@ -158,8 +158,8 @@ ModStruct pacman_description = { #endif -Bool trackmouse; -pacmangamestruct *pacmangames = (pacmangamestruct *) NULL; +Bool pacman_trackmouse; +pacmangamestruct *pacman_games = (pacmangamestruct *) NULL; static void repopulate (ModeInfo * mi); static void drawlevel (ModeInfo * mi); @@ -201,7 +201,7 @@ free_pacman (Display * display, pacmangamestruct * pp) static void reset_level (ModeInfo * mi, int n, int pac_init) { - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; unsigned int ghost; MI_CLEARWINDOW (mi); @@ -251,9 +251,9 @@ reset_level (ModeInfo * mi, int n, int pac_init) pp->ghosts[ghost].delta.y = 0; pp->ghosts[ghost].flash_scared = False; pp->ghosts[ghost].wait_pos = False; - ghost_update (pp, &(pp->ghosts[ghost])); + pacman_ghost_update (pp, &(pp->ghosts[ghost])); } - pac_update (mi, pp, &(pp->pacman)); + pacman_update (mi, pp, &(pp->pacman)); } static int @@ -276,11 +276,9 @@ check_death (ModeInfo * mi, pacmangamestruct * pp) Display *display = MI_DISPLAY (mi); Window window = MI_WINDOW (mi); unsigned int ghost; - int alldead; if (pp->pacman.aistate == ps_dieing) return; - alldead = 1; for (ghost = 0; ghost < pp->nghosts; ghost++) { /* The ghost have to be scared before you can kill them */ @@ -306,20 +304,16 @@ check_death (ModeInfo * mi, pacmangamestruct * pp) } continue; } - - alldead = 0; } - - } /* Resets state of ghosts + pacman. Creates a new level, draws that level. */ static void repopulate (ModeInfo * mi) { - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; pp->pacman.deaths = 0; - reset_level (mi, createnewlevel (pp), True); + reset_level (mi, pacman_createnewlevel (pp), True); check_death (mi, pp); } @@ -328,7 +322,7 @@ static void setwallcolor (ModeInfo * mi) { Display *display = MI_DISPLAY (mi); - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; if (MI_NPIXELS (mi) > 2) XSetForeground (display, pp->stippledGC, MI_PIXEL (mi, BLUE)); @@ -341,7 +335,7 @@ static void setdotcolor (ModeInfo * mi) { Display *display = MI_DISPLAY (mi); - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; XSetForeground (display, pp->stippledGC, MI_WHITE_PIXEL (mi)); } @@ -350,7 +344,7 @@ static void cleardotcolor (ModeInfo * mi) { Display *display = MI_DISPLAY (mi); - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; XSetForeground (display, pp->stippledGC, MI_BLACK_PIXEL (mi)); } @@ -361,7 +355,7 @@ draw_position (ModeInfo * mi, int x, int y, int color) { Display *display = MI_DISPLAY (mi); Window window = MI_WINDOW (mi); - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; XFontStruct *font = NULL; char *f_name = "-*-utopia-*-r-*-*-*-600-*-*-p-*-*-*"; char *s = NULL; @@ -384,7 +378,7 @@ draw_number (ModeInfo * mi, int x, int y, int num, int color) { Display *display = MI_DISPLAY (mi); Window window = MI_WINDOW (mi); - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; XFontStruct *font = NULL; char *f_name = "-*-utopia-*-r-*-*-*-600-*-*-p-*-*-*"; char *s = NULL; @@ -412,7 +406,7 @@ draw_grid (ModeInfo * mi) { Display *display = MI_DISPLAY (mi); Window window = MI_WINDOW (mi); - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; int h = MI_HEIGHT (mi); int w = MI_WIDTH (mi); int y = 0; @@ -436,7 +430,7 @@ draw_string (ModeInfo * mi, int x, int y, char *s, int color) { Display *display = MI_DISPLAY (mi); Window window = MI_WINDOW (mi); - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; XFontStruct *font = NULL; char *f_name = "-*-utopia-*-r-*-*-*-600-*-*-p-*-*-*"; @@ -488,7 +482,7 @@ print_ghost_stats (ModeInfo *mi, ghoststruct *g , int ghost_num) static void print_pac_stats ( ModeInfo *mi, pacmanstruct *pac ) { - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; char s[1024]; sprintf (s, "Pacman, Deaths: %d", pac->deaths ); switch ( pac->aistate ){ @@ -522,7 +516,7 @@ print_pac_stats ( ModeInfo *mi, pacmanstruct *pac ) static void dot_rc_to_pixel (ModeInfo * mi, int *x, int *y) { - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; *x = (pp->xs * *x) + (pp->xs / 2) - (pp->xs > 32 ? (pp->xs / 16) : 1) + pp->xb; *y = (pp->ys * *y) + @@ -535,7 +529,7 @@ dot_rc_to_pixel (ModeInfo * mi, int *x, int *y) static void dot_width_height (ModeInfo *mi, int *w, int *h) { - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; if (pp->xs > 32){ *w = *h = (pp->xs / 32 ); }else { @@ -609,9 +603,9 @@ drawlevelblock (ModeInfo * mi, pacmangamestruct * pp, if (pp->ys % 2 == 1) dy = -1; -#ifndef HAVE_COCOA +#ifndef HAVE_JWXYZ XSetFillStyle (display, pp->stippledGC, FillSolid); -#endif /* !HAVE_COCOA */ +#endif /* !HAVE_JWXYZ */ XSetLineAttributes (display, pp->stippledGC, pp->wallwidth, LineSolid, CapRound, JoinMiter); @@ -719,7 +713,7 @@ drawlevelblock (ModeInfo * mi, pacmangamestruct * pp, static void drawlevel (ModeInfo * mi) { - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; unsigned int x, y; for (y = 0; y < LEVHEIGHT; y++) @@ -751,7 +745,7 @@ draw_pacman_sprite (ModeInfo * mi) { Display *display = MI_DISPLAY (mi); Window window = MI_WINDOW (mi); - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; unsigned int dir = 0; int old_mask_dir = 0; int old_mask_mouth = 0; @@ -831,8 +825,6 @@ draw_pacman_sprite (ModeInfo * mi) pp->pacman.oldcf = pp->pacman.cf; pp->pacman.oldrf = pp->pacman.rf; } - old_mask_dir = dir; - old_mask_mouth = pp->pm_mouth; } #if 0 @@ -859,7 +851,7 @@ draw_ghost_sprite (ModeInfo * mi, const unsigned ghost) { Display *display = MI_DISPLAY (mi); Window window = MI_WINDOW (mi); - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; #define MAX_WAG_COUNT 50 unsigned int dir = 0; unsigned int fs = 0; /*flash scared*/ @@ -962,17 +954,13 @@ draw_pacman_sprite (ModeInfo * mi) { Display *display = MI_DISPLAY (mi); Window window = MI_WINDOW (mi); - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; - unsigned int dir; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; pp->pacman.cf = pp->pacman.col * pp->xs + pp->pacman.delta.x * pp->pacman.cfactor + pp->xb + pp->spritedx; pp->pacman.rf = pp->pacman.row * pp->ys + pp->pacman.delta.y * pp->pacman.rfactor + pp->yb + pp->spritedy; - dir = (ABS (pp->pacman.cfactor) * (2 - pp->pacman.cfactor) + - ABS (pp->pacman.rfactor) * (1 + pp->pacman.rfactor)) % 4; - XSetForeground (display, pp->stippledGC, MI_BLACK_PIXEL (mi)); if (pp->pacman.oldcf != NOWHERE && pp->pacman.oldrf != NOWHERE) { @@ -1011,7 +999,7 @@ draw_ghost_sprite (ModeInfo * mi, const unsigned ghost) { Display *display = MI_DISPLAY (mi); Window window = MI_WINDOW (mi); - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; pp->ghosts[ghost].cf = pp->ghosts[ghost].col * pp->xs + pp->ghosts[ghost].delta.x * @@ -1067,7 +1055,7 @@ ghost_over (ModeInfo * mi, int x, int y) { int ghost = 0; int ret = False; - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; dot_rc_to_pixel (mi, &x, &y); for (ghost = 0; ghost < pp->nghosts; ghost++) { if ((pp->ghosts[ghost].cf <= x @@ -1086,11 +1074,11 @@ static void flash_bonus_dots (ModeInfo * mi) { #define MAX_FLASH_COUNT 25 - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; int i, x, y; for (i = 0; i < NUM_BONUS_DOTS; i++) { - if (!bonus_dot_eaten (pp, i)) { - bonus_dot_pos (pp, i, &x, &y); + if (!pacman_bonus_dot_eaten (pp, i)) { + pacman_bonus_dot_pos (pp, i, &x, &y); if (ghost_over (mi, x, y)) continue; if (pp->bd_on) @@ -1113,10 +1101,10 @@ ate_bonus_dot (ModeInfo * mi) */ unsigned int ret = 0; int idx = 0; - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; - if (is_bonus_dot (pp, pp->pacman.col, pp->pacman.row, &idx)) { - ret = !bonus_dot_eaten (pp, idx); - eat_bonus_dot (pp, idx); + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; + if (pacman_is_bonus_dot (pp, pp->pacman.col, pp->pacman.row, &idx)) { + ret = !pacman_bonus_dot_eaten (pp, idx); + pacman_eat_bonus_dot (pp, idx); } return ret; } @@ -1125,7 +1113,7 @@ static void ghost_scared (ModeInfo * mi) { unsigned int ghost; - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; for (ghost = 0; ghost < pp->nghosts; ghost++) { if (pp->ghosts[ghost].aistate == goingin || pp->ghosts[ghost].aistate == goingout || @@ -1141,7 +1129,7 @@ static void ghost_not_scared (ModeInfo * mi) { unsigned int ghost; - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; for (ghost = 0; ghost < pp->nghosts; ghost++){ if (pp->ghosts[ghost].aistate == goingin || pp->ghosts[ghost].aistate == goingout || @@ -1157,7 +1145,7 @@ static void ghost_flash_scared (ModeInfo * mi) { unsigned int ghost; - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; for (ghost = 0; ghost < pp->nghosts; ghost++) pp->ghosts[ghost].flash_scared = !pp->ghosts[ghost].flash_scared; } @@ -1170,7 +1158,7 @@ pacman_tick (ModeInfo * mi) #define START_FLASH 200 #define FLASH_COUNT 25 - pacmangamestruct *pp = &pacmangames[MI_SCREEN (mi)]; + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; unsigned int ghost; #if 0 draw_grid (mi); @@ -1272,7 +1260,7 @@ scale_pixmap (Display ** dpy, GC gc, Pixmap source, int dwidth, int dheight) end = dheight * yscale; /* Scale height of temp into dest pixmap */ for (i = 0; i <= end; i += yscale) - XCopyArea (*dpy, temp, dest, gc, 0, i, swidth, 1, 0, j++); + XCopyArea (*dpy, temp, dest, gc, 0, i, dwidth, 1, 0, j++); XFreePixmap (*dpy, temp); return (Pixmap) dest; @@ -1488,7 +1476,7 @@ init_pacman (ModeInfo * mi) { Display *display = MI_DISPLAY (mi); Window window = MI_WINDOW (mi); - int size = MI_SIZE (mi); + long size = MI_SIZE (mi); pacmangamestruct *pp; XGCValues gcv; int i, j, k; @@ -1499,13 +1487,13 @@ init_pacman (ModeInfo * mi) int dir, mouth; #endif - if (pacmangames == NULL) { - if ((pacmangames = (pacmangamestruct *) + if (pacman_games == NULL) { + if ((pacman_games = (pacmangamestruct *) calloc ((size_t) MI_NUM_SCREENS (mi), sizeof (pacmangamestruct))) == NULL) return; } - pp = &pacmangames[MI_SCREEN (mi)]; + pp = &pacman_games[MI_SCREEN (mi)]; pp->width = (unsigned short) MI_WIDTH (mi); pp->height = (unsigned short) MI_HEIGHT (mi); @@ -1566,7 +1554,7 @@ init_pacman (ModeInfo * mi) pp->spriteys = MAX (pp->ys + (pp->ys >> 1) - 1, 1); pp->spritedx = (pp->xs - pp->spritexs) >> 1; pp->spritedy = (pp->ys - pp->spriteys) >> 1; - pp->old_pac_state = chasing; + pp->old_pac_state = ps_chasing; if (!pp->stippledGC) { gcv.foreground = MI_BLACK_PIXEL (mi); @@ -1579,7 +1567,7 @@ init_pacman (ModeInfo * mi) } } -#ifdef HAVE_COCOA +#ifdef HAVE_JWXYZ jwxyz_XSetAntiAliasing (display, pp->stippledGC, False); #endif @@ -1718,9 +1706,9 @@ draw_pacman (ModeInfo * mi) unsigned int g; pacmangamestruct *pp; - if (pacmangames == NULL) + if (pacman_games == NULL) return; - pp = &pacmangames[MI_SCREEN (mi)]; + pp = &pacman_games[MI_SCREEN (mi)]; if (pp->ghosts == NULL) return; @@ -1730,7 +1718,7 @@ draw_pacman (ModeInfo * mi) pp->pacman.delta.y += pp->pacman.err.y != 0 ? pp->incy : 0; if (pp->pacman.delta.x >= pp->xs && pp->pacman.delta.y >= pp->ys) { - pac_update (mi, pp, &(pp->pacman)); + pacman_update (mi, pp, &(pp->pacman)); check_death (mi, pp); pp->pacman.delta.x = pp->incx; pp->pacman.delta.y = pp->incy; @@ -1749,7 +1737,7 @@ draw_pacman (ModeInfo * mi) if (pp->ghosts[g].delta.x >= pp->xs && pp->ghosts[g].delta.y >= pp->ys) { - ghost_update (pp, &(pp->ghosts[g])); + pacman_ghost_update (pp, &(pp->ghosts[g])); pp->ghosts[g].delta.x = pp->incx; pp->ghosts[g].delta.y = pp->incy; } @@ -1766,13 +1754,13 @@ draw_pacman (ModeInfo * mi) ENTRYPOINT void release_pacman (ModeInfo * mi) { - if (pacmangames != NULL) { + if (pacman_games != NULL) { int screen; for (screen = 0; screen < MI_NUM_SCREENS (mi); screen++) - free_pacman (MI_DISPLAY (mi), &pacmangames[screen]); - free (pacmangames); - pacmangames = (pacmangamestruct *) NULL; + free_pacman (MI_DISPLAY (mi), &pacman_games[screen]); + free (pacman_games); + pacman_games = (pacmangamestruct *) NULL; } } @@ -1784,6 +1772,19 @@ refresh_pacman (ModeInfo * mi) pacman_tick (mi); } +ENTRYPOINT void +reshape_pacman(ModeInfo * mi, int width, int height) +{ + pacmangamestruct *pp = &pacman_games[MI_SCREEN (mi)]; + pp->width = width; + pp->height = height; + pp->xb = (pp->width - pp->ncols * pp->xs) >> 1; + pp->yb = (pp->height - pp->nrows * pp->ys) >> 1; + MI_CLEARWINDOW (mi); + /* repopulate (mi); */ + drawlevel (mi); +} + #ifndef STANDALONE /* Callback to change level. */ ENTRYPOINT void