ftp://ftp.krokus.ru/pub/OpenBSD/distfiles/xscreensaver-4.21.tar.gz
[xscreensaver] / hacks / pacman.h
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*-
3  * Copyright (c) 2002 by Edwin de Jong <mauddib@gmx.net>.
4  *
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.
10  *
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.
16  *
17  * Revision History:
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
22  *
23  */
24
25 #ifndef __PACMAN_H__
26 #define __PACMAN_H__
27
28 #include "config.h"
29 #include "xlockmoreI.h"
30
31 #if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM)
32 #define USE_PIXMAP
33 #include "xpm-pixmap.h"
34 #else
35 #if defined(USE_PIXMAP)
36 #undef USE_PIXMAP
37 #endif
38 #endif
39
40 #define LEVHEIGHT       32U
41 #define LEVWIDTH        40U
42
43 #define GETNB(n) ((1 << (n)) - 1)
44 #define TESTNB(v, n) (((1 << (n)) & v) != 0x00)
45 #define SNB(v, n) ((v) |= (1 << (n)))
46 #define UNSNB(v, n) ((v) &= ~(1 << (n)))
47 #define GHOSTS 4U
48 #if defined(USE_PIXMAP)
49 #define MAXMOUTH 3
50 #else
51 #define MAXMOUTH 11
52 #endif
53 #define MAXGPOS 2
54 #define MAXGDIR 4
55 #define MAXGWAG 2
56 #define MAXGFLASH 2
57 #define MINGRIDSIZE 4
58 #define MINSIZE 3
59 #define NOWHERE 16383
60 #define START ((LRAND() & 1) ? 1 : 3)
61 #define MINDOTPERC 10
62
63 #define YELLOW (MI_NPIXELS(mi) / 6)
64 #define GREEN (23 * MI_NPIXELS(mi) / 64)
65 #define BLUE (45 * MI_NPIXELS(mi) / 64)
66 #define WHITE (MI_NPIXELS(mi))
67
68 #define LINEWIDTH       4
69 #define HLINEWIDTH      1
70 #define JAILHEIGHT      7
71 #define JAILWIDTH       8
72
73 #define GETFACTOR(x, y) ((x) > (y) ? 1 : ((x) < (y) ? -1 : 0))
74 #define SIGN(x) GETFACTOR((x), 0)
75 #define TRACEVECS 40
76 #define PAC_DEATH_FRAMES 8
77
78 #define GHOST_TRACE ( LEVWIDTH * LEVHEIGHT )
79
80 typedef struct
81 {
82     int vx, vy;
83 } tracevec_struct;
84
85 typedef enum
86     { inbox = 0, goingout, randdir, chasing, hiding, goingin } GhostState;
87 typedef enum
88     { ps_eating = 0, ps_chasing, ps_hiding, ps_random, ps_dieing } PacmanState;
89 typedef enum
90 { GHOST_DANGER, GHOST_EATEN } GameState;
91
92 typedef struct
93 {
94     volatile unsigned int col, row;
95     unsigned int lastbox, nextcol, nextrow;
96     int dead;
97     int cfactor, rfactor;
98     int cf, rf;
99     int oldcf, oldrf;
100     volatile int timeleft;
101     GhostState aistate;
102     int speed;
103     XPoint delta;
104     XPoint err;
105     int flash_scared;
106     int trace_idx;
107     tracevec_struct trace[GHOST_TRACE];
108     int home_idx;
109     volatile int home_count;
110     tracevec_struct way_home[GHOST_TRACE];
111     volatile int wait_pos; /* a cycle before calculating the position */
112 #if 0  /* Used for debugging */
113     int ndirs;
114     int oldndirs;
115 #endif
116
117 #if 0 /* Used for debugging */
118     char last_stat[1024];
119 #endif
120
121 } ghoststruct;
122
123 typedef struct
124 {
125     unsigned int col, row;
126     unsigned int lastbox, nextcol, nextrow;
127     int mouthstage, mouthdirection;
128     int cfactor, rfactor;
129     int cf, rf;
130     int oldcf, oldrf;
131     int oldlx, oldly;
132     int justate;
133     PacmanState aistate;
134     tracevec_struct trace[TRACEVECS];
135     int cur_trace;
136     int state_change;
137     int roundscore;
138     int speed;
139     int lastturn;
140     XPoint delta;
141     XPoint err;
142     int deaths;
143     int init_row;
144 } pacmanstruct;
145
146 typedef struct
147 {
148     unsigned short width, height;
149     unsigned short nrows, ncols;
150     short xs, ys, xb, yb;
151     short incx, incy;
152     GC stippledGC;
153     int graphics_format;
154     pacmanstruct pacman;
155     ghoststruct *ghosts;
156     unsigned int nghosts;
157     Pixmap pacmanPixmap[4][MAXMOUTH];
158     Pixmap pacmanMask[4][MAXMOUTH];
159     Pixmap pacman_ds[PAC_DEATH_FRAMES]; /* pacman death sequence */
160     Pixmap pacman_ds_mask[PAC_DEATH_FRAMES];
161     Pixmap ghostPixmap[4][MAXGDIR][MAXGWAG];
162     Pixmap ghostMask;
163     Pixmap s_ghostPixmap[MAXGFLASH][MAXGWAG];   /* Scared ghost Pixmaps */
164     Pixmap ghostEyes[MAXGDIR];
165     char level[LEVHEIGHT * LEVWIDTH];
166     unsigned int wallwidth;
167     unsigned int dotsleft;
168     int spritexs, spriteys, spritedx, spritedy;
169
170     GameState gamestate;
171     unsigned int timeleft;
172 } pacmangamestruct;
173
174 #define DIRVECS 4
175
176 extern pacmangamestruct *pacmangames;
177 extern Bool trackmouse;
178
179 typedef char lev_t[LEVHEIGHT][LEVWIDTH + 1];
180
181 #define NUM_BONUS_DOTS 4
182
183 #endif /* __PACMAN_H__ */