1 /* $Id: title.c,v 1.4 1998/05/11 06:52:59 mrogre Exp $ */
2 /* Copyright (c) 1998 Joe Rumsey (mrogre@mediaone.net) */
3 #include "copyright.h"
4 #include <config.h>
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #ifdef HAVE_FCNTL_H
10 # include <fcntl.h>
11 #endif
12 #include "math.h"
13 #include "Wlib.h"
14 #include "defs.h"
15 #include "images.h"
16 #include "struct.h"
17 #include "data.h"
18 #include "proto.h"
19
20 /* for scrolling credits */
21 const LINESIZE= 70;
22 const VISIBLELINES=7;
23 const SPEEDFACTOR=5;
24 char *gchLBuf;
25 int giCreditLines=0, giActCreditLine=0;
26
27 W_Image *pauseImage, *titleImage;
28 int pausex, pausey, pauseyspeed=1;
29
undo_pause()30 void undo_pause()
31 {
32 W_CacheClearArea(baseWin, pausex-(pauseImage->width/2), pausey-(pauseImage->height/2),
33 pauseImage->width, pauseImage->height);
34 }
35
do_pause()36 void do_pause()
37 {
38 if((pausey < pauseImage->height/2) || ((pausey+(pauseImage->height/2)) >= WINHEIGHT))
39 pauseyspeed = -pauseyspeed;
40 pausey+=pauseyspeed;
41
42 W_DrawImage(baseWin, pausex-(pauseImage->width/2), pausey-(pauseImage->height/2), 0, pauseImage, W_White);
43 }
44
45 void
center_text(char * text,int y,W_Color color)46 center_text(char *text, int y, W_Color color)
47 {
48 /*
49 W_MaskText(baseWin, WINWIDTH/2 - ((strlen(text)*W_Textwidth)/2)-1, y+1, W_Black,
50 text, strlen(text), W_RegularFont);
51 */
52 W_MaskText(baseWin, WINWIDTH/2 - ((strlen(text)*W_Textwidth)/2), y, color,
53 text, strlen(text), W_RegularFont);
54 }
55
56 #if 0 /* ships vary from level to level now */
57 static void show_points()
58 {
59 int i, ty;
60 int a_images[6] = {
61 I_ALIEN1,
62 I_ALIEN2,
63 I_ALIEN3,
64 I_ALIEN4,
65 I_ALIEN5,
66 I_ALIEN6
67 };
68
69 char buf[40];
70
71 for (i=0;i<6;i++) {
72 W_DrawImage(baseWin, WINWIDTH/2 - 30, 220+i*21,
73 0, getImage(a_images[5-i]), W_Red);
74 if(i < 5)
75 sprintf(buf, "- %d", (i+1)*100);
76 else
77 sprintf(buf, "- ???");
78 W_MaskText(baseWin, WINWIDTH/2, 225+i*21,
79 W_Yellow, buf, strlen(buf), W_RegularFont);
80 }
81 ty = 220+i*21;
82 center_text("Ships in convoy are worth 50 points", ty, W_Green); ty += W_Textheight;
83 center_text("Bonus ships at 20,000, 50,000, then every 50,000.", ty, W_Green);
84 }
85 #endif
86
show_help()87 static void show_help()
88 {
89 int top = 270;
90
91 center_text(" Keyboard controls ", top, W_Red);
92 center_text(" left/right arrow move ", top+10, W_Yellow);
93 center_text(" space bar fire ", top+20, W_Yellow);
94 center_text(" p pause ", top+30, W_Cyan);
95 center_text(" q end game ", top+40, W_Cyan);
96 center_text(" Q quick quit ", top+50, W_Cyan);
97 center_text(" k keyboard control", top+60, W_Cyan);
98 center_text(" m mouse control ", top+70, W_Cyan);
99 #ifndef ORIGINAL_XGALAGA
100 center_text(" x toggle shields ", top+80, W_Cyan);
101 #endif
102 #ifdef SOUND
103 center_text(" s toggle sound ", top+90, W_Cyan);
104 #endif
105
106 center_text("Bonus ships at 20,000, 50,000, then every 50,000.", top+120, W_Green);
107 center_text("XGalaga Home page: http://rumsey.org/xgal.html",
108 top+150, W_Cyan);
109 }
110
read_credits()111 int read_credits()
112 {
113 int hsf;
114 int i,j,l,lines;
115 int nSize;
116 char *chFBuf, chLBuf[LINESIZE+1];
117
118 j = 0; lines = 0;
119 chFBuf = (char *) malloc (8000+1);
120 if (chFBuf == 0) return (-1);
121 gchLBuf = (char *) malloc (LINESIZE+1);
122 if (gchLBuf == 0) return (-2);
123 hsf = open (CREDITSFILE, O_RDONLY);
124 if ( hsf > 0 )
125 {
126 l = read (hsf, chFBuf, 8000);
127 chFBuf[l] = 0x00;
128 if ( l > 0 )
129 {
130 for (i=0; i<l; i++)
131 {
132 switch (chFBuf[i])
133 {
134 case 10 : // Linefeed
135 case 0 :
136 chLBuf[j] = 0x00;
137 j = 0;
138 strncpy (gchLBuf+(lines*(LINESIZE+1)), chLBuf, LINESIZE);
139 lines++;
140 nSize = (lines+1) * (LINESIZE+1);
141 gchLBuf = (char *) realloc (gchLBuf, nSize); // get space for next line
142 break;
143 case 1: case 2: case 3: case 4:case 5:
144 case 6: case 7: case 8: case 9:
145 case 11: case 12: case 13: case 14:case 15:
146 case 16: case 17: case 18: case 19:
147 // ignore control characters
148 break;
149 default:
150 chLBuf[j++] = chFBuf[i]; // visible character
151 if (j>LINESIZE)
152 {
153 // line too long -> cut without grace
154 chLBuf[j] = 0x00;
155 j = 0;
156 strncpy (gchLBuf+(lines*(LINESIZE+1)), chLBuf, LINESIZE);
157 lines++;
158 nSize = (lines+1) * (LINESIZE+1);
159 gchLBuf = (char *) realloc (gchLBuf, nSize); // get space for next line
160 }
161 break;
162 } // end switch
163 } // end for
164 }
165 }
166 else
167 {
168 // printf (chLBuf, sizeof(chLBuf)-1, "Sorry! Could not read CREDITSFILE");
169 }
170 close(hsf);
171 free (chFBuf);
172 giCreditLines = lines-1;
173 }
174
175
undo_credits()176 void undo_credits()
177 {
178 int hsf;
179 int i,j,l,lines;
180 int top = 460;
181 char chLBuf[LINESIZE+1];
182
183 if ( gchLBuf > 0 )
184 {
185 j = 0; lines = 0;
186 for ( i=giActCreditLine; i<giCreditLines; i++ )
187 {
188 strncpy (chLBuf, gchLBuf+i*(LINESIZE+1), LINESIZE);
189 center_text (chLBuf, top+lines*W_Textheight + ((pagetimer-1) % (W_Textheight*SPEEDFACTOR))/SPEEDFACTOR, W_Black);
190 lines++;
191 if ( lines > VISIBLELINES ) break;
192 } // end for
193 }
194 else
195 {
196 snprintf (chLBuf, sizeof(chLBuf)-1, "Sorry no CREDITS data");
197 center_text (chLBuf, top+10, W_Black);
198 }
199 }
200
201
show_credits()202 void show_credits()
203 {
204 int hsf;
205 int i,j,l,lines;
206 int top = 460;
207 char chLBuf[LINESIZE+1];
208
209 if ( gchLBuf > 0 )
210 {
211 j = 0; lines = 0;
212 for ( i=giActCreditLine; i<giCreditLines; i++ )
213 {
214 strncpy (chLBuf, gchLBuf+i*(LINESIZE+1), LINESIZE);
215 j = top + lines*W_Textheight + ((pagetimer-1) % (W_Textheight*SPEEDFACTOR))/SPEEDFACTOR ;
216 center_text (chLBuf,j, W_Green);
217 lines++;
218 if ( lines > VISIBLELINES ) break;
219 } // end for
220 W_ClearArea(baseWin,
221 0, top,
222 WINWIDTH, W_Textheight);
223 W_ClearArea(baseWin,
224 0, top+(VISIBLELINES+1)*W_Textheight,
225 WINWIDTH, W_Textheight);
226 }
227 else
228 {
229 snprintf (chLBuf, sizeof(chLBuf)-1, "Sorry no CREDITS data");
230 center_text (chLBuf, top+10, W_Green);
231 }
232 }
233
234
do_title()235 void do_title()
236 {
237 int ty;
238 char vbuf[10];
239
240 W_DrawImage (baseWin, WINWIDTH/2 - titleImage->width/2, 50, 0, titleImage, W_Red);
241 sprintf (vbuf, "v%s", VERSION);
242 center_text (vbuf, 40+titleImage->height, W_Yellow);
243
244 ty = 60 + titleImage->height;
245 if (getting_name)
246 title_page = 0;
247
248 switch (title_page)
249 {
250 case 0:
251 center_text("Copyright (c) 1995-1998 Joe Rumsey", ty, W_Green); ty+= W_Textheight;
252 center_text("Maintenance 2008 by Hermann Riedel", ty, W_Green); ty+= 2*W_Textheight;
253 #ifndef ORIGINAL_XGALAGA
254 center_text("XGalaga: Hyperspace 0.9", ty, W_Green); ty+= W_Textheight;
255 #endif
256 show_help();
257 // show_credits();
258 break;
259 case 1:
260 default:
261 show_scores();
262 // show_credits();
263 break;
264 }
265
266 #ifdef __linux__
267 if (js_device)
268 center_text("Press k for keyboard or joystick control, m for mouse", WINHEIGHT - 2*W_Textheight, W_Yellow);
269 else /* no joystick, so use message below */
270 #endif
271 center_text("Press k for keyboard control, m for mouse", WINHEIGHT - 2*W_Textheight, W_Yellow);
272 center_text("Or q to quit", WINHEIGHT - W_Textheight, W_Yellow);
273
274 undo_credits(); // erase with painting black
275 pagetimer--;
276 // if (!(pagetimer % 50))
277 if (!(pagetimer % (W_Textheight*SPEEDFACTOR)))
278 {
279 //printf("%d %d %25s\n", pagetimer, (pagetimer % (W_Textheight*SPEEDFACTOR)), gchLBuf+giActCreditLine*(LINESIZE+1));
280 giActCreditLine++;
281 if (giActCreditLine > giCreditLines)
282 giActCreditLine = 0;
283 }
284 if (!pagetimer)
285 {
286 W_ClearWindow(baseWin);
287 title_page++;
288 if (title_page > 1)
289 title_page = 0;
290 pagetimer = 299;
291 }
292 show_credits(); // write text
293 }
294
init_titles()295 void init_titles()
296 {
297 titleImage = getImage(I_TITLE);
298 pauseImage = getImage(I_PAUSE);
299 pausex = WINWIDTH/2;
300 pausey = WINHEIGHT/2;
301 pauseyspeed = 3;
302 read_credits();
303 }
304
305