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 #include "ximage-loader.h"
42 #define GETNB(n) ((1 << (n)) - 1)
43 #define TESTNB(v, n) (((1 << (n)) & v) != 0x00)
44 #define SNB(v, n) ((v) |= (1 << (n)))
45 #define UNSNB(v, n) ((v) &= ~(1 << (n)))
55 #define START ((LRAND() & 1) ? 1 : 3)
58 #define YELLOW (MI_NPIXELS(mi) / 6)
59 #define GREEN (23 * MI_NPIXELS(mi) / 64)
60 #define BLUE (45 * MI_NPIXELS(mi) / 64)
61 #define WHITE (MI_NPIXELS(mi))
68 #define GETFACTOR(x, y) ((x) > (y) ? 1 : ((x) < (y) ? -1 : 0))
69 #define SIGN(x) GETFACTOR((x), 0)
71 #define PAC_DEATH_FRAMES 8
73 #define GHOST_TRACE ( LEVWIDTH * LEVHEIGHT )
76 #define NUM_BONUS_DOTS 4
84 { inbox = 0, goingout, randdir, chasing, hiding, goingin } GhostState;
86 { ps_eating = 0, ps_chasing, ps_hiding, ps_random, ps_dieing } PacmanState;
88 { GHOST_DANGER, GHOST_EATEN } GameState;
92 volatile unsigned int col, row;
93 unsigned int lastbox, nextcol, nextrow;
98 volatile int timeleft;
105 tracevec_struct trace[GHOST_TRACE];
107 volatile int home_count;
108 tracevec_struct way_home[GHOST_TRACE];
109 volatile int wait_pos; /* a cycle before calculating the position */
110 #if 0 /* Used for debugging */
115 #if 0 /* Used for debugging */
116 char last_stat[1024];
123 unsigned int col, row;
124 unsigned int lastbox, nextcol, nextrow;
125 int mouthstage, mouthdirection;
126 int cfactor, rfactor;
132 tracevec_struct trace[TRACEVECS];
152 /* This are tiles which can be placed to create a level. */
154 char block[TILEWIDTH * TILEHEIGHT + 1];
162 unsigned short width, height;
163 unsigned short nrows, ncols;
164 short xs, ys, xb, yb;
170 unsigned int nghosts;
171 Pixmap pacmanPixmap[4][MAXMOUTH];
172 Pixmap pacmanMask[4][MAXMOUTH];
173 Pixmap pacman_ds[PAC_DEATH_FRAMES]; /* pacman death sequence */
174 Pixmap pacman_ds_mask[PAC_DEATH_FRAMES];
175 Pixmap ghostPixmap[4][MAXGDIR][MAXGWAG];
177 Pixmap s_ghostPixmap[MAXGFLASH][MAXGWAG]; /* Scared ghost Pixmaps */
178 Pixmap ghostEyes[MAXGDIR];
179 char level[LEVHEIGHT * LEVWIDTH];
180 unsigned int wallwidth;
181 unsigned int dotsleft;
182 int spritexs, spriteys, spritedx, spritedy;
185 unsigned int timeleft;
187 char last_pac_stat[1024];
189 /* draw_pacman_sprite */
196 /* draw_ghost_sprite */
200 /* flash_bonus_dots */
205 int ghost_scared_timer;
207 PacmanState old_pac_state;
210 bonus_dot bonus_dots[NUM_BONUS_DOTS];
215 extern pacmangamestruct *pacman_games;
216 extern Bool pacman_trackmouse;
218 typedef char lev_t[LEVHEIGHT][LEVWIDTH + 1];
220 #endif /* __PACMAN_H__ */