1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * Copyright (c) 2002 by Edwin de Jong <mauddib@gmx.net>.
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation for any purpose and without fee is hereby granted,
7 * provided that the above copyright notice appear in all copies and that
8 * both that copyright notice and this permission notice appear in
9 * supporting documentation.
11 * This file is provided AS IS with no warranties of any kind. The author
12 * shall have no liability with respect to the infringement of copyrights,
13 * trade secrets or any patents by this file or any part thereof. In no
14 * event will the author be liable for any lost revenue or profits or
15 * other special, indirect and consequential damages.
18 * 3-May-2002: Added AI to pacman and ghosts, slowed down ghosts.
19 * 26-Nov-2001: Random level generator added
20 * 01-Nov-2000: Allocation checks
21 * 04-Jun-1997: Compatible with xscreensaver
32 #include "xlockmoreI.h"
34 #if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM) || defined(HAVE_COCOA)
36 #include "xpm-pixmap.h"
38 # if defined(USE_PIXMAP)
49 #define GETNB(n) ((1 << (n)) - 1)
50 #define TESTNB(v, n) (((1 << (n)) & v) != 0x00)
51 #define SNB(v, n) ((v) |= (1 << (n)))
52 #define UNSNB(v, n) ((v) &= ~(1 << (n)))
54 #if defined(USE_PIXMAP)
66 #define START ((LRAND() & 1) ? 1 : 3)
69 #define YELLOW (MI_NPIXELS(mi) / 6)
70 #define GREEN (23 * MI_NPIXELS(mi) / 64)
71 #define BLUE (45 * MI_NPIXELS(mi) / 64)
72 #define WHITE (MI_NPIXELS(mi))
79 #define GETFACTOR(x, y) ((x) > (y) ? 1 : ((x) < (y) ? -1 : 0))
80 #define SIGN(x) GETFACTOR((x), 0)
82 #define PAC_DEATH_FRAMES 8
84 #define GHOST_TRACE ( LEVWIDTH * LEVHEIGHT )
87 #define NUM_BONUS_DOTS 4
95 { inbox = 0, goingout, randdir, chasing, hiding, goingin } GhostState;
97 { ps_eating = 0, ps_chasing, ps_hiding, ps_random, ps_dieing } PacmanState;
99 { GHOST_DANGER, GHOST_EATEN } GameState;
103 volatile unsigned int col, row;
104 unsigned int lastbox, nextcol, nextrow;
106 int cfactor, rfactor;
109 volatile int timeleft;
116 tracevec_struct trace[GHOST_TRACE];
118 volatile int home_count;
119 tracevec_struct way_home[GHOST_TRACE];
120 volatile int wait_pos; /* a cycle before calculating the position */
121 #if 0 /* Used for debugging */
126 #if 0 /* Used for debugging */
127 char last_stat[1024];
134 unsigned int col, row;
135 unsigned int lastbox, nextcol, nextrow;
136 int mouthstage, mouthdirection;
137 int cfactor, rfactor;
143 tracevec_struct trace[TRACEVECS];
163 /* This are tiles which can be placed to create a level. */
165 char block[TILEWIDTH * TILEHEIGHT + 1];
173 unsigned short width, height;
174 unsigned short nrows, ncols;
175 short xs, ys, xb, yb;
181 unsigned int nghosts;
182 Pixmap pacmanPixmap[4][MAXMOUTH];
183 Pixmap pacmanMask[4][MAXMOUTH];
184 Pixmap pacman_ds[PAC_DEATH_FRAMES]; /* pacman death sequence */
185 Pixmap pacman_ds_mask[PAC_DEATH_FRAMES];
186 Pixmap ghostPixmap[4][MAXGDIR][MAXGWAG];
188 Pixmap s_ghostPixmap[MAXGFLASH][MAXGWAG]; /* Scared ghost Pixmaps */
189 Pixmap ghostEyes[MAXGDIR];
190 char level[LEVHEIGHT * LEVWIDTH];
191 unsigned int wallwidth;
192 unsigned int dotsleft;
193 int spritexs, spriteys, spritedx, spritedy;
196 unsigned int timeleft;
198 char last_pac_stat[1024];
200 /* draw_pacman_sprite */
207 /* draw_ghost_sprite */
211 /* flash_bonus_dots */
216 int ghost_scared_timer;
218 PacmanState old_pac_state;
221 bonus_dot bonus_dots[NUM_BONUS_DOTS];
226 extern pacmangamestruct *pacmangames;
227 extern Bool trackmouse;
229 typedef char lev_t[LEVHEIGHT][LEVWIDTH + 1];
231 #endif /* __PACMAN_H__ */