File: xonix.h

package info (click to toggle)
xonix 1.4-13
  • links: PTS
  • area: main
  • in suites: potato
  • size: 304 kB
  • ctags: 502
  • sloc: ansic: 3,676; makefile: 38; sh: 22
file content (298 lines) | stat: -rw-r--r-- 10,904 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/* Hey emacs, make this use -*- Mode: C++; tab-width: 4 -*- */
#ifndef XONIX_H
#define XONIX_H

/*
 * xonix global definitions
 *
 * xonix.h,v 1.39 1995/09/08 09:51:30 j Exp
 */

/*
 * Copyright (c) 1995
 *   Torsten Schoenitz <torsten_schoenitz@bonnie.heep.sax.de>
 *   Joerg Wunsch <joerg_wunsch@uriah.heep.sax.de>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef USE_X11
#include <X11/Xos.h>		/* Boolean et al. */
#include <X11/Intrinsic.h>
#endif

#ifdef USE_MAC
#include <Types.h>          /* Basistypendeklarationen.                     */
#include <Memory.h>							     
#include <QuickDraw.h>      /* Interface-Datei zu den QuickDraw-Datenstruk- */
                            /* turen und Routinen.                          */
#include <QDOffscreen.h>    /* Wegen der hintergruendigen GWorld-Geschichten*/
#include <Fonts.h>          /* Interface-Datei des Font-Managers (wird vom  */
                            /* Window-Manager benoetigt).                   */
#include <Windows.h>        /* Interface-Datei des Window-Managers (hier 	*/
                            /* wird u.a. GetNewWindow deklariert).          */
#include <Events.h>         /* Interface-Datei zu den Routinen und Daten-   */
                            /* strukturen des Event-Managers.               */
#include <ToolUtils.h>      /* ToolBox-Utilities (z.B. HiWord, LoWord).     */
#include <Menus.h>          /* Interface-Datei des Menu-Managers.           */
#include <Desk.h>           /* Desk-Manager (Kompatibilitaet zu System 6.x +*/
                            /* Finder in bezug auf Schreibtischprogramme).  */
#include <TextEdit.h>       /* Interface-Datei des TextEdit-Managers (wird  */
                            /* vom Dialog-Manager verwendet).               */
#include <Dialogs.h>        /* Interface-Datei des Dialog-Managers.         */
#include <StandardFile.h>   /* Einsprungadressen bzw. Datenstrukturen von   */
                            /* SFGetFile und SFPutFile.                     */
#endif /* USE_MAC */

/* Typedefs.*/

struct point {
  short h, v;
};

typedef struct point myPoint;

struct rectangle {
	short top, left, bottom, right;
};

typedef struct rectangle myRect;

#ifdef USE_MAC
struct keyboardPrefs {
	char	leftKey, rightKey, upKey, downKey, pauseKey;
};

typedef struct keyboardPrefs kbPrefs, *kbPrefsPtr, **kbPrefsHandle;

struct highScoreEntry {
	Str255	name;
	int		score;
	int		level;
};

typedef struct highScoreEntry hgScoreEntry, *hgScoreEntryPtr, 
							**hgScoreEntryHandle;
#endif /* USE_MAC */
							
struct Player   {
  int       x, y;                           /* Koordinaten der Figur        */
  int       sx, sy;                         /* Groesse der Figur            */
  int       dx, dy;                         /* Schrittweite der Figur       */
  myRect	rr;								/* Redraw-Rechteck				*/
};

typedef struct Player Player;

struct Segment	{
	int		y;
	int		xl;
	int		xr;
	int		dy;
};

typedef struct Segment mySegment;

enum attribute  {
            EMPTY       = 0x00,             /* Ungefuellt                   */
            WAY         = 0x01,             /* Spur des Runners             */
            TESTFILLED  = 0x02,             /* Probefuellung                */
            FILLED      = 0x04,             /* Endgueltig gefuellt          */
            BORDER      = 0x08,             /* Rahmen                       */
            RUNNER      = 0x80,             /* Spielfigur                   */
            FLYER       = 0x40,             /* Flieger                      */
            EATER       = 0x20              /* Fresser                      */
            };


/* Andere Konstanten. */

/* Die Spieldimensionen werden durch die "Fresser"-Groesse bestimmt.        */
/* H_STEPS und V_STEPS sollten multipliziert mit EATER_SIZE jeweils         */
/* etwa 600 bzw. 400 ergeben                                                */
									     
#define EATER_SIZE          4               /* Groesse der "Fresser"        */
#define RATIO               2               /* Faktor von Eater zu Runner   */
#define H_STEPS             150             /* Horizontal moegl. Positionen	*/
#define V_STEPS             100             /* Vertikal moegl. Positionen 	*/

#define PERCENT_THRESHOLD	75				/* Fuellstand - Schwelle		*/
#define LEVEL_BONUS_FACTOR	100.0        /* Bonus fuer geschafftes Level */
#define LOOP_FACTOR			10.0			/* Faktor fuer Punktberechnung	*/

#define EATER_STEP          1                  /* Schrittweite der "Fresser"*/
#define FLYER_SIZE          RATIO*EATER_SIZE   /* Groesse der "Flieger"     */
#define FLYER_STEP          RATIO              /* Schrittweite der "Flieger"*/
#define RUNNER_SIZE         RATIO*EATER_SIZE   /* Groesse der Spielfigur    */
#define RUNNER_STEP         RATIO              /* Schrittweite der Spielfig.*/
#define FIELD_WIDTH         H_STEPS*EATER_SIZE /* Breite des Spielfeldes    */
#define FIELD_HEIGHT        V_STEPS*EATER_SIZE /* Hoehe des Spielfeldes     */

#define WINDOW_START_X      20
#define WINDOW_START_Y      40
#define MAX_FLYER           10
#define MAX_EATER           4


#ifdef USE_X11
typedef unsigned char * Ptr;
#define NIL_POINTER			NULL
#define STEP_TIME           50		/* Schrittweite in ms */
#define BELL() XBell(dpy, 50)
#endif

#ifdef USE_MAC
#define KEY char
#define BELL() RunnerDieSound()
#endif

/* ------------------------------------------------------------------------ */
/* Deklaration der globalen Variablen.                                      */
/* ------------------------------------------------------------------------ */

extern Boolean      gQuit,                  /* Wenn gQuit auf true gesetzt  */
                                            /* wird, terminiert die Appli-	*/
                                            /* kation.                      */
                    gRun,                   /* Ist gRun auf true gesetzt,	*/
                                            /* laeuft das Spiel, sonst sind */
                                            /* Einstellungen usw. moeglich  */
                    gPause,					/* Spiel unterbrochen           */
					gEndOfGame;				/* Runner sind alle 			*/
extern int          gFlyerCount;            /* Anzahl der Flieger           */
									    
extern Player       gFlyer[MAX_FLYER];      /* Alle Flieger                 */

extern int          gEaterCount;            /* Anzahl der Fresser           */
									    
extern Player       gEater[MAX_EATER];      /* Alle Fresser                 */
									    
extern Player       gMyRunner;              /* Spielfigur                   */
									    
extern Ptr          gMyStatusArea;          /* Status-Area                  */

extern unsigned     gHighScore;	            /* Punktestand                  */
extern int			gLevel;					/* Es geht mit Level 1 los		*/

#ifdef USE_MAC

extern GWorldPtr    gMyGWorld;              /* Offscreen-Area               */

extern WindowPtr    gTheCWindow;            /* Das Window fuer alles        */

extern Rect         gWorldRect;

#endif /* USE_MAC */

#ifdef USE_X11

extern Display *dpy;

#endif /* USE_X11 */


/* ------------------------------------------------------------------------ */
/* Funktionen								     							*/
/* ------------------------------------------------------------------------ */

extern void Animate (void);
extern void Do_Event (void);
extern void DrawRunnerToGWorld (void);
extern void DrawWayToGWorld (void);
extern void DrawEmptyToGWorld (int xPos, int yPos);
extern void DrawFlyerToGWorld (int xPos, int yPos);
extern void DrawEaterToGWorld (int xPos, int yPos);
extern void DrawFilledToGWorld (int xPos, int yPos);
extern void DrawSmallFilledToGWorld (int xPos, int yPos);
extern void DrawCompleteBorder (void);
extern void SetRunner (int x, int y);
extern void ClearWay (void);
extern Boolean FillUp (int x, int y);
extern void ExitXonix (int number);
extern void ScorePercentage (int num);
extern void ScoreLevel (int num);
extern void ScoreRunner (int num);
extern void ShowHighScore (void);

#ifdef USE_MAC

#define NIL_POINTER 0L

#define GWorldEntry() \
  GDHandle    oldGD; \
  GWorldPtr   oldGW; \
  GetGWorld (&oldGW, &oldGD); \
  LockPixels (gMyGWorld -> portPixMap); \
  SetGWorld (gMyGWorld, NIL_POINTER)

#define GWorldExit() \
  SetGWorld (oldGW, oldGD); \
  SetPort (gTheCWindow); \
  CopyBits ((BitMap*)*gMyGWorld -> portPixMap, &gTheCWindow -> portBits, \
	    &gWorldRect, \
	    &gWorldRect, srcCopy, 0L); \
  UnlockPixels (gMyGWorld -> portPixMap)

#define GWorldExitFlyer() \
  SetGWorld (oldGW, oldGD); \
  SetPort (gTheCWindow); \
  for (i = 0; i < gFlyerCount; i ++) \
  	CopyBits ((BitMap*)*gMyGWorld -> portPixMap, &gTheCWindow -> portBits, \
	    &gFlyer[i].rr, \
	    &gFlyer[i].rr, srcCopy, 0L); \
  UnlockPixels (gMyGWorld -> portPixMap)

#define GWorldExitEater() \
  SetGWorld (oldGW, oldGD); \
  SetPort (gTheCWindow); \
  for (i = 0; i < gEaterCount; i ++) \
  	CopyBits ((BitMap*)*gMyGWorld -> portPixMap, &gTheCWindow -> portBits, \
	    &gEater[i].rr, \
	    &gEater[i].rr, srcCopy, 0L); \
  UnlockPixels (gMyGWorld -> portPixMap)

#define GWorldExitRunner() \
  SetGWorld (oldGW, oldGD); \
  SetPort (gTheCWindow); \
  CopyBits ((BitMap*)*gMyGWorld -> portPixMap, &gTheCWindow -> portBits, \
	    &gMyRunner.rr, \
	    &gMyRunner.rr, srcCopy, 0L); \
  UnlockPixels (gMyGWorld -> portPixMap)

#endif /* USE_MAC */

#ifdef USE_X11

#define GWorldEntry()
#define GWorldExit()
#define GWorldExitFlyer()
#define GWorldExitEater()
#define GWorldExitRunner()

#endif /* USE_X11 */

#ifdef __FreeBSD__

#define rand() random()
#define srand(x) srandom(x)

#endif /* __FreeBSD */

#endif /* XONIX_H */