X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fpacman.h;h=bd6fbe4ae3b232e0a97f32f608780e56d3eddbc3;hb=aa75c7476aeaa84cf3abc192b376a8b03c325213;hp=8c914f79b9a6b2155f1f9667ae0557bc6c15e901;hpb=e4fa2ac140f7bc56571373a7b7eb585fa4500e38;p=xscreensaver diff --git a/hacks/pacman.h b/hacks/pacman.h index 8c914f79..bd6fbe4a 100644 --- a/hacks/pacman.h +++ b/hacks/pacman.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /*- * Copyright (c) 2002 by Edwin de Jong . * @@ -21,16 +22,44 @@ * */ +#ifndef __PACMAN_H__ +#define __PACMAN_H__ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "xlockmoreI.h" + +#if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM) || defined(HAVE_JWXYZ) +# define USE_PIXMAP +#include "xpm-pixmap.h" +# else +# if defined(USE_PIXMAP) +# undef USE_PIXMAP +# endif +#endif + #define LEVHEIGHT 32U #define LEVWIDTH 40U +#define TILEWIDTH 5U +#define TILEHEIGHT 5U + #define GETNB(n) ((1 << (n)) - 1) #define TESTNB(v, n) (((1 << (n)) & v) != 0x00) #define SNB(v, n) ((v) |= (1 << (n))) #define UNSNB(v, n) ((v) &= ~(1 << (n))) #define GHOSTS 4U +#if defined(USE_PIXMAP) +#define MAXMOUTH 3 +#else #define MAXMOUTH 11 +#endif #define MAXGPOS 2 +#define MAXGDIR 4 +#define MAXGWAG 2 +#define MAXGFLASH 2 #define MINGRIDSIZE 4 #define MINSIZE 3 #define NOWHERE 16383 @@ -50,140 +79,153 @@ #define GETFACTOR(x, y) ((x) > (y) ? 1 : ((x) < (y) ? -1 : 0)) #define SIGN(x) GETFACTOR((x), 0) #define TRACEVECS 40 +#define PAC_DEATH_FRAMES 8 + +#define GHOST_TRACE ( LEVWIDTH * LEVHEIGHT ) + +#define DIRVECS 4 +#define NUM_BONUS_DOTS 4 + +typedef struct +{ + int vx, vy; +} tracevec_struct; + +typedef enum + { inbox = 0, goingout, randdir, chasing, hiding, goingin } GhostState; +typedef enum + { ps_eating = 0, ps_chasing, ps_hiding, ps_random, ps_dieing } PacmanState; +typedef enum +{ GHOST_DANGER, GHOST_EATEN } GameState; + +typedef struct +{ + volatile unsigned int col, row; + unsigned int lastbox, nextcol, nextrow; + int dead; + int cfactor, rfactor; + int cf, rf; + int oldcf, oldrf; + volatile int timeleft; + GhostState aistate; + int speed; + XPoint delta; + XPoint err; + int flash_scared; + int trace_idx; + tracevec_struct trace[GHOST_TRACE]; + int home_idx; + volatile int home_count; + tracevec_struct way_home[GHOST_TRACE]; + volatile int wait_pos; /* a cycle before calculating the position */ +#if 0 /* Used for debugging */ + int ndirs; + int oldndirs; +#endif + +#if 0 /* Used for debugging */ + char last_stat[1024]; +#endif -#define DEF_TRACKMOUSE "False" -static Bool trackmouse; - -typedef struct { int vx, vy; } tracevec_struct; - -typedef enum { inbox = 0, goingout, randdir, chasing, hiding } GhostState; -typedef enum { ps_eating = 0, ps_chasing, ps_hiding, ps_random } PacmanState; -typedef enum { GHOST_DANGER, GHOST_EATEN } GameState; - -typedef struct { - unsigned int col, row; - unsigned int lastbox, nextcol, nextrow; - int dead; - int cfactor, rfactor; - int cf, rf; - int oldcf, oldrf; - int timeleft; - GhostState aistate; - /*int color; */ - int speed; - XPoint delta; - XPoint err; } ghoststruct; -typedef struct { - unsigned int col, row; - unsigned int lastbox, nextcol, nextrow; - int mouthstage, mouthdirection; - int cfactor, rfactor; - int cf, rf; - int oldcf, oldrf; - int oldlx, oldly; - int justate; - PacmanState aistate; - tracevec_struct trace[TRACEVECS]; - int cur_trace; - int state_change; - int roundscore; - int speed; - int lastturn; - XPoint delta; - XPoint err; +typedef struct +{ + unsigned int col, row; + unsigned int lastbox, nextcol, nextrow; + int mouthstage, mouthdirection; + int cfactor, rfactor; + int cf, rf; + int oldcf, oldrf; + int oldlx, oldly; + int justate; + PacmanState aistate; + tracevec_struct trace[TRACEVECS]; + int cur_trace; + int state_change; + int roundscore; + int speed; + int lastturn; + XPoint delta; + XPoint err; + int deaths; + int init_row; } pacmanstruct; -typedef struct { - unsigned short width, height; - unsigned short nrows, ncols; - short xs, ys, xb, yb; - short incx, incy; - GC stippledGC; - int graphics_format; - pacmanstruct pacman; - ghoststruct *ghosts; - unsigned int nghosts; - Pixmap pacmanPixmap[4][MAXMOUTH]; -/* Pixmap ghostPixmap[4][MAXGPOS];*/ - Pixmap ghostPixmap; - char level[LEVHEIGHT * LEVWIDTH]; - unsigned int wallwidth; - unsigned int dotsleft; - int spritexs, spriteys, spritedx, spritedy; - - GameState gamestate; - unsigned int timeleft; -} pacmangamestruct; -#define DIRVECS 4 -static const struct { int dx, dy; } dirvecs[DIRVECS] = - { {-1, 0}, {0, 1}, {1, 0}, {0, -1}}; +typedef struct +{ + unsigned int x, y; + int eaten; +} bonus_dot; + + +/* This are tiles which can be placed to create a level. */ +struct tiles { + char block[TILEWIDTH * TILEHEIGHT + 1]; + unsigned dirvec[4]; + unsigned ndirs; + unsigned simular_to; +}; + +typedef struct +{ + unsigned short width, height; + unsigned short nrows, ncols; + short xs, ys, xb, yb; + short incx, incy; + GC stippledGC; + int graphics_format; + pacmanstruct pacman; + ghoststruct *ghosts; + unsigned int nghosts; + Pixmap pacmanPixmap[4][MAXMOUTH]; + Pixmap pacmanMask[4][MAXMOUTH]; + Pixmap pacman_ds[PAC_DEATH_FRAMES]; /* pacman death sequence */ + Pixmap pacman_ds_mask[PAC_DEATH_FRAMES]; + Pixmap ghostPixmap[4][MAXGDIR][MAXGWAG]; + Pixmap ghostMask; + Pixmap s_ghostPixmap[MAXGFLASH][MAXGWAG]; /* Scared ghost Pixmaps */ + Pixmap ghostEyes[MAXGDIR]; + char level[LEVHEIGHT * LEVWIDTH]; + unsigned int wallwidth; + unsigned int dotsleft; + int spritexs, spriteys, spritedx, spritedy; + + GameState gamestate; + unsigned int timeleft; + + char last_pac_stat[1024]; + + /* draw_pacman_sprite */ + int pm_mouth; + int pm_mouth_delay; + int pm_open_mouth; + int pm_death_frame; + int pm_death_delay; + + /* draw_ghost_sprite */ + int gh_wag; + int gh_wag_count; + + /* flash_bonus_dots */ + int bd_flash_count; + int bd_on; + + /* pacman_tick */ + int ghost_scared_timer; + int flash_timer; + PacmanState old_pac_state; + + /* pacman_level.c */ + bonus_dot bonus_dots[NUM_BONUS_DOTS]; + struct tiles *tiles; + +} pacmangamestruct; -static pacmangamestruct *pacmangames = (pacmangamestruct *) NULL; +extern pacmangamestruct *pacman_games; +extern Bool pacman_trackmouse; typedef char lev_t[LEVHEIGHT][LEVWIDTH + 1]; -/* function type definitions */ - - /* level generation */ -static int creatlevelblock(lev_t *level, const unsigned x, - const unsigned y); -static void setblockto(lev_t *level, const unsigned x, const unsigned y, - const char c); -static int checkset(lev_t *level, const unsigned x, const unsigned y); -static int checksetout(lev_t *level, const unsigned x, const unsigned y); -static int checkunsetdef(lev_t *level, const unsigned x, const unsigned y); -static void clearlevel(lev_t *level); -static void copylevel(char *dest, lev_t *level); -static void createjail(lev_t *level, const unsigned width, - const unsigned height); -static void finishjail(lev_t *level, const unsigned width, - const unsigned height); -static int tryset(lev_t *level, const unsigned xpos, const unsigned ypos, - const char *block); -static int creatlevelblock(lev_t *level, const unsigned x, - const unsigned y); -static void filllevel(lev_t *level); -static void frmtlevel(lev_t *level); -static unsigned countdots(ModeInfo * mi); -static int createnewlevel(ModeInfo * mi); -static int check_pos(pacmangamestruct *pp, int y, int x, int ghostpass); -static int check_dot(pacmangamestruct *pp, unsigned int x, unsigned int y); - - /* graphics rendering */ -static void drawlevel(ModeInfo * mi); - - /* AI */ -static int ghost_get_posdirs(pacmangamestruct *pp, int *posdirs, - ghoststruct *g); -static void ghost_random(pacmangamestruct *pp, ghoststruct *g); -static void ghost_chasing(pacmangamestruct *pp, ghoststruct *g); -static void ghost_hiding(pacmangamestruct *pp, ghoststruct *g); -static void ghost_update(pacmangamestruct *pp, ghoststruct *g); - -static void pac_dot_vec(pacmangamestruct *pp, pacmanstruct *p, - long *vx, long *vy); -static int pac_ghost_prox_and_vector(pacmangamestruct *pp, - pacmanstruct *p, int *vx, int *vy); -static int pac_get_posdirs(pacmangamestruct *pp, pacmanstruct *p, - int *posdirs); -static void pac_clear_trace(pacmanstruct *p); -static void pac_save_trace(pacmanstruct *p, const int vx, const int vy); -static int pac_check_trace(const pacmanstruct *p, const int vx, - const int vy); -static void pac_eating(pacmangamestruct *pp, pacmanstruct *p); -#if 0 -static void pac_chasing(pacmangamestruct *pp, pacmanstruct *p); -#endif -static void pac_random(pacmangamestruct *pp, pacmanstruct *p); -static int pac_get_vector_screen(pacmangamestruct *pp, pacmanstruct *p, - const int x, const int y, int *vx, int *vy); -static int pac_trackmouse(ModeInfo * mi, pacmangamestruct *pp, - pacmanstruct *p); -static void pac_update(ModeInfo * mi, pacmangamestruct *pp, - pacmanstruct *p); - - /* generic functions */ -static void repopulate(ModeInfo * mi); +#endif /* __PACMAN_H__ */