1 /*
2 * SDLRoids - An Astroids clone.
3 *
4 * Copyright (c) 2000 David Hedbor <david@hedbor.org>
5 * based on xhyperoid by Russel Marks.
6 * xhyperoid is based on a Win16 game, Hyperoid by Edward Hutchins
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 *
17 */
18
19 /*
20 * roidsupp.c - SDLRoids support functions
21 */
22
23 #include "config.h"
24 RCSID("$Id: roidsupp.c,v 1.5 2001/03/23 23:54:23 neotron Exp $");
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #ifdef HAVE_LIMITS_H
30 #include <limits.h>
31 #endif
32 #include "misc.h"
33 #include "hyperoid.h"
34
35 #include "roidsupp.h"
36
37 #ifndef PATH_MAX
38 #define PATH_MAX 1024
39 #endif
40
41 static char datafile[PATH_MAX+1];
42
43 /* these parts map to "abcdefghijklm" */
44 POINT LetterPart[] =
45 {
46 {83, 572}, {64, 512}, {45, 572}, {96, 362}, {32, 362},
47 {128, 256}, {0, 0}, {0, 256},
48 {160, 362}, {224, 362}, {173, 572}, {192, 512}, {211, 572}
49 };
50
51 /* here's the vector font */
52 char *NumberDesc[] =
53 {
54 "cakmck", /* 0 */
55 "dbl", /* 1 */
56 "abekm", /* 2 */
57 "abegjlk", /* 3 */
58 "mcfh", /* 4 */
59 "cbfgjlk", /* 5 */
60 "bdiljgi", /* 6 */
61 "acgl", /* 7 */
62 "bdjlieb", /* 8 */
63 "ljebdge" /* 9 */
64 };
65
66 char *LetterDesc[] =
67 {
68 "kdbemhf", /* A */
69 "kabegjlk", /* B */
70 "cbflm", /* C */
71 "kabejlk", /* D */
72 "cafgfkm", /* E */
73 "cafgfk", /* F */
74 "bdiljhg", /* G */
75 "kafhcm", /* H */
76 "bl", /* I */
77 "cjli", /* J */
78 "akcgm", /* K */
79 "akm", /* L */
80 "kagcm", /* M */
81 "kamc", /* N */
82 "bdiljeb", /* O */
83 "kabegf", /* P */
84 "mlidbejl", /* Q */
85 "kabegfgm", /* R */
86 "ebdjli", /* S */
87 "lbac", /* T */
88 "ailjc", /* U */
89 "alc", /* V */
90 "akgmc", /* W */
91 "amgkc", /* X */
92 "aglgc", /* Y */
93 "ackm" /* Z */
94 };
95
96
97
98 /* PrintLetters - create letter objects from a string */
99
PrintLetters(char * npszText,POINT Pos,POINT Vel,BYTE byColor,int nSize)100 void PrintLetters( char *npszText, POINT Pos, POINT Vel,
101 BYTE byColor, int nSize )
102 {
103 int nLen = strlen( npszText );
104 int nCnt = nLen;
105 int nSpace = nSize + nSize / 2;
106 int nBase = (nLen - 1) * nSpace;
107 int nBaseStart = Pos.x + nBase / 2;
108
109 while (nCnt--)
110 {
111 OBJ *npLtr = CreateLetter( npszText[nCnt], nSize / 2 );
112 if (npLtr)
113 {
114 npLtr->Pos.x = nBaseStart;
115 npLtr->Pos.y = Pos.y;
116 npLtr->Vel = Vel;
117 npLtr->byColor = byColor;
118 }
119 nBaseStart -= nSpace;
120 }
121 }
122
123
124 /* SpinLetters - spin letter objects away from center for effect */
125
SpinLetters(char * npszText,POINT Pos,POINT Vel,BYTE byColor,int nSize)126 void SpinLetters( char *npszText, POINT Pos, POINT Vel,
127 BYTE byColor, int nSize )
128 {
129 int nLen = strlen( npszText );
130 int nCnt = nLen;
131 int nSpace = nSize + nSize / 2;
132 int nBase = (nLen - 1) * nSpace;
133 int nBaseStart = Pos.x + nBase / 2;
134
135 while (nCnt--)
136 {
137 OBJ *npLtr = CreateLetter( npszText[nCnt], nSize / 2 );
138 if (npLtr)
139 {
140 int nSpin = (nCnt - nLen / 2) * 2;
141 npLtr->Pos.x = nBaseStart;
142 npLtr->Pos.y = Pos.y;
143 npLtr->Vel = Vel;
144 npLtr->Vel.x += nSpin * 16;
145 npLtr->nSpin = -nSpin;
146 npLtr->byColor = byColor;
147 }
148 nBaseStart -= nSpace;
149 }
150 }
151
152
153 /* Build the file names */
datafilename(char * prefix,char * name)154 char *datafilename(char *prefix, char *name)
155 {
156 #ifdef HAVE_GETENV
157 static char *env = NULL;
158 #endif
159 if(prefix == NULL) {
160 #ifdef HAVE_GETENV
161 if(env == NULL)
162 env = getenv("SRDATADIR");
163 if(env == NULL) return name;
164 prefix = env;
165 #else
166 return name;
167 #endif
168 }
169 if((strlen(prefix) + strlen(name)) > PATH_MAX) return name;
170 strcpy(datafile, prefix);
171 strcat(datafile, name);
172 return datafile;
173 }
174