ftp://ftp.linux.ncsu.edu/mirror/ftp.redhat.com/pub/redhat/linux/enterprise/4/en/os...
[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 #define LEVHEIGHT       32U
31 #define LEVWIDTH        40U
32
33 #define GETNB(n) ((1 << (n)) - 1)
34 #define TESTNB(v, n) (((1 << (n)) & v) != 0x00)
35 #define SNB(v, n) ((v) |= (1 << (n)))
36 #define UNSNB(v, n) ((v) &= ~(1 << (n)))
37 #define GHOSTS 4U
38 #define MAXMOUTH 11
39 #define MAXGPOS 2
40 #define MAXGDIR 4
41 #define MAXGWAG 2
42 #define MINGRIDSIZE 4
43 #define MINSIZE 3
44 #define NOWHERE 16383
45 #define START ((LRAND() & 1) ? 1 : 3)
46 #define MINDOTPERC 10
47
48 #define YELLOW (MI_NPIXELS(mi) / 6)
49 #define GREEN (23 * MI_NPIXELS(mi) / 64)
50 #define BLUE (45 * MI_NPIXELS(mi) / 64)
51 #define WHITE (MI_NPIXELS(mi))
52
53 #define LINEWIDTH       4
54 #define HLINEWIDTH      1
55 #define JAILHEIGHT      7
56 #define JAILWIDTH       8
57
58 #define GETFACTOR(x, y) ((x) > (y) ? 1 : ((x) < (y) ? -1 : 0))
59 #define SIGN(x) GETFACTOR((x), 0)
60 #define TRACEVECS 40
61
62 typedef struct { int vx, vy; } tracevec_struct;
63
64 typedef enum { inbox = 0, goingout, randdir, chasing, hiding } GhostState;
65 typedef enum { ps_eating = 0, ps_chasing, ps_hiding, ps_random } PacmanState;
66 typedef enum { GHOST_DANGER, GHOST_EATEN } GameState;
67
68 typedef struct {
69         unsigned int    col, row;
70         unsigned int    lastbox, nextcol, nextrow;
71         int             dead;
72         int             cfactor, rfactor;
73         int             cf, rf;
74         int             oldcf, oldrf;
75         int             timeleft;
76         GhostState      aistate;
77         /*int         color; */
78         int             speed;
79         XPoint          delta;
80         XPoint          err;
81 } ghoststruct;
82
83 typedef struct {
84         unsigned int    col, row;
85         unsigned int    lastbox, nextcol, nextrow;
86         int             mouthstage, mouthdirection;
87         int             cfactor, rfactor;
88         int             cf, rf;
89         int             oldcf, oldrf;
90         int             oldlx, oldly;
91         int             justate;
92         PacmanState     aistate;
93         tracevec_struct trace[TRACEVECS];
94         int             cur_trace;
95         int             state_change;
96         int             roundscore;
97         int             speed;
98         int             lastturn;
99         XPoint          delta;
100         XPoint          err;
101 } pacmanstruct;
102
103 typedef struct {
104         unsigned short  width, height;
105         unsigned short  nrows, ncols;
106         short           xs, ys, xb, yb;
107         short           incx, incy;
108         GC              stippledGC;
109         int             graphics_format;
110         pacmanstruct    pacman;
111         ghoststruct     *ghosts;
112         unsigned int    nghosts;
113         Pixmap          pacmanPixmap[4][MAXMOUTH];
114 /*      Pixmap          ghostPixmap[4][MAXGPOS];*/
115 /*      Pixmap          ghostPixmap; */
116         Pixmap          ghostPixmap[4][MAXGDIR][MAXGWAG];
117 /*          Pixmap          ghostMask[4][MAXGDIR][MAXGWAG]; */
118         Pixmap          ghostMask;
119         char            level[LEVHEIGHT * LEVWIDTH];
120         unsigned int    wallwidth;
121         unsigned int    dotsleft;
122         int             spritexs, spriteys, spritedx, spritedy;
123
124         GameState       gamestate;
125         unsigned int    timeleft;
126 } pacmangamestruct;
127
128 #define DIRVECS 4
129
130 extern pacmangamestruct *pacmangames;
131 extern Bool trackmouse;
132
133 typedef char lev_t[LEVHEIGHT][LEVWIDTH + 1];
134
135 #endif /* __PACMAN_H__ */