http://se.aminet.net/pub/Linux/distributions/slackware/slackware-10.1/source/xap...
[xscreensaver] / hacks / pacman.h
1 /*-
2  * Copyright (c) 2002 by Edwin de Jong <mauddib@gmx.net>.
3  *
4  * Permission to use, copy, modify, and distribute this software and its
5  * documentation for any purpose and without fee is hereby granted,
6  * provided that the above copyright notice appear in all copies and that
7  * both that copyright notice and this permission notice appear in
8  * supporting documentation.
9  *
10  * This file is provided AS IS with no warranties of any kind.  The author
11  * shall have no liability with respect to the infringement of copyrights,
12  * trade secrets or any patents by this file or any part thereof.  In no
13  * event will the author be liable for any lost revenue or profits or
14  * other special, indirect and consequential damages.
15  *
16  * Revision History:
17  *  3-May-2002: Added AI to pacman and ghosts, slowed down ghosts.
18  * 26-Nov-2001: Random level generator added
19  * 01-Nov-2000: Allocation checks
20  * 04-Jun-1997: Compatible with xscreensaver
21  *
22  */
23
24 #ifndef __PACMAN_H__
25 #define __PACMAN_H__
26
27 #include "config.h"
28 #include "xlockmoreI.h"
29
30 #if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM)
31 #define USE_PIXMAP
32 #include "xpm-pixmap.h"
33 #else
34 #if defined(USE_PIXMAP)
35 #undef USE_PIXMAP
36 #endif
37 #endif
38
39 #define LEVHEIGHT       32U
40 #define LEVWIDTH        40U
41
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)))
46 #define GHOSTS 4U
47 #if defined(USE_PIXMAP)
48 #define MAXMOUTH 3
49 #else
50 #define MAXMOUTH 11
51 #endif
52 #define MAXGPOS 2
53 #define MAXGDIR 4
54 #define MAXGWAG 2
55 #define MINGRIDSIZE 4
56 #define MINSIZE 3
57 #define NOWHERE 16383
58 #define START ((LRAND() & 1) ? 1 : 3)
59 #define MINDOTPERC 10
60
61 #define YELLOW (MI_NPIXELS(mi) / 6)
62 #define GREEN (23 * MI_NPIXELS(mi) / 64)
63 #define BLUE (45 * MI_NPIXELS(mi) / 64)
64 #define WHITE (MI_NPIXELS(mi))
65
66 #define LINEWIDTH       4
67 #define HLINEWIDTH      1
68 #define JAILHEIGHT      7
69 #define JAILWIDTH       8
70
71 #define GETFACTOR(x, y) ((x) > (y) ? 1 : ((x) < (y) ? -1 : 0))
72 #define SIGN(x) GETFACTOR((x), 0)
73 #define TRACEVECS 40
74
75 typedef struct { int vx, vy; } tracevec_struct;
76
77 typedef enum { inbox = 0, goingout, randdir, chasing, hiding } GhostState;
78 typedef enum { ps_eating = 0, ps_chasing, ps_hiding, ps_random } PacmanState;
79 typedef enum { GHOST_DANGER, GHOST_EATEN } GameState;
80
81 typedef struct {
82         unsigned int    col, row;
83         unsigned int    lastbox, nextcol, nextrow;
84         int             dead;
85         int             cfactor, rfactor;
86         int             cf, rf;
87         int             oldcf, oldrf;
88         int             timeleft;
89         GhostState      aistate;
90         /*int         color; */
91         int             speed;
92         XPoint          delta;
93         XPoint          err;
94 } ghoststruct;
95
96 typedef struct {
97         unsigned int    col, row;
98         unsigned int    lastbox, nextcol, nextrow;
99         int             mouthstage, mouthdirection;
100         int             cfactor, rfactor;
101         int             cf, rf;
102         int             oldcf, oldrf;
103         int             oldlx, oldly;
104         int             justate;
105         PacmanState     aistate;
106         tracevec_struct trace[TRACEVECS];
107         int             cur_trace;
108         int             state_change;
109         int             roundscore;
110         int             speed;
111         int             lastturn;
112         XPoint          delta;
113         XPoint          err;
114 } pacmanstruct;
115
116 typedef struct {
117         unsigned short  width, height;
118         unsigned short  nrows, ncols;
119         short           xs, ys, xb, yb;
120         short           incx, incy;
121         GC              stippledGC;
122         int             graphics_format;
123         pacmanstruct    pacman;
124         ghoststruct     *ghosts;
125         unsigned int    nghosts;
126         Pixmap          pacmanPixmap[4][MAXMOUTH];
127         Pixmap          pacmanMask[4][MAXMOUTH];
128         Pixmap          ghostPixmap[4][MAXGDIR][MAXGWAG];
129         Pixmap          ghostMask;
130         char            level[LEVHEIGHT * LEVWIDTH];
131         unsigned int    wallwidth;
132         unsigned int    dotsleft;
133         int             spritexs, spriteys, spritedx, spritedy;
134
135         GameState       gamestate;
136         unsigned int    timeleft;
137 } pacmangamestruct;
138
139 #define DIRVECS 4
140
141 extern pacmangamestruct *pacmangames;
142 extern Bool trackmouse;
143
144 typedef char lev_t[LEVHEIGHT][LEVWIDTH + 1];
145
146 #endif /* __PACMAN_H__ */