1 /*
2
3 Dodgin' Diamond 2, a shot'em up arcade
4 Copyright (C) 2003,2004 Juan J. Martinez <jjm@usebox.net>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 */
21 #include"SDL_plus.h"
22 #include<string.h>
23
24 SDL_Surface *
loadBMP(char * file)25 loadBMP(char *file)
26 {
27 SDL_Surface *a,*b;
28
29 a=SDL_LoadBMP(file);
30 if(!a)
31 return NULL;
32 b=SDL_DisplayFormat(a);
33 if(!b)
34 return NULL;
35
36 SDL_FreeSurface(a);
37 return b;
38 }
39
40 void
writeNumber(SDL_Surface * src,SDL_Surface * dst,int x,int y,int number,int padd)41 writeNumber(SDL_Surface *src, SDL_Surface *dst, int x, int y, int number, int padd)
42 {
43 SDL_Rect a,b;
44 char buffer[32],fmt[16];
45 int i;
46
47 sprintf(fmt,"%%.%ii",padd);
48 sprintf(buffer,fmt,number);
49
50 a.y=y;
51 a.w=8;
52 a.h=12;
53 b.y=73;
54 b.w=8;
55 b.h=12;
56 for(i=0;i<strlen(buffer);i++) {
57 a.x=x+i*8;
58 b.x=101+(buffer[i]-'0')*9;
59 SDL_BlitSurface(src, &b, dst, &a);
60 }
61 }
62
63 void
drawPanel(SDL_Surface * src,SDL_Surface * dst,pDesc * player)64 drawPanel(SDL_Surface *src, SDL_Surface *dst, pDesc *player)
65 {
66 SDL_Rect a,b;
67 int i;
68
69 a.x=0;
70 a.y=0;
71
72 b.x=2;
73 b.y=83;
74 b.h=34;
75 b.w=95;
76 SDL_BlitSurface(src, &b, dst, &a);
77
78 a.x=SCREENW-b.w;
79 b.x=2;
80 b.y=47;
81 SDL_BlitSurface(src, &b, dst, &a);
82
83 /* GAME OVER */
84 if(!player[0].shield && !player[1].shield) {
85 a.x=(SCREENW/2)-70;
86 a.y=(SCREENH/2)-10;
87 b.x=100;
88 b.y=89;
89 b.h=19;
90 b.w=140;
91 SDL_BlitSurface(src, &b, dst, &a);
92 return;
93 }
94
95 for(i=0;i<2;i++) {
96
97 if(!player[i].shield)
98 continue;
99
100 switch(player[i].weapon) {
101 case 0:
102 b.x=47;
103 break;
104 case 1:
105 b.x=53;
106 break;
107 case 2:
108 b.x=59;
109 break;
110 }
111 a.x=30;
112 a.y=6;
113 b.w=5;
114 b.h=10;
115 b.y=24;
116
117 if(i) {
118 a.x=SCREENW-35;
119 writeNumber(src,dst,a.x-10,a.y-1,player[i].level+1,1);
120 writeNumber(src,dst,a.x-15,a.y+14,player[i].score,6);
121 } else {
122 writeNumber(src,dst,a.x+b.w+2,a.y-1,player[i].level+1,1);
123 writeNumber(src,dst,2,a.y+14,player[i].score,6);
124 }
125
126 SDL_BlitSurface(src, &b, dst, &a);
127
128 b.y=62;
129 b.w=(player[i].shield*38)/10;
130 b.h=9;
131 a.y=4;
132 if(i) {
133 b.x=139;
134 a.x=SCREENW-(54+38)+(38-b.w);
135 } else {
136 b.x=100;
137 a.x=54;
138 }
139 SDL_BlitSurface(src, &b, dst, &a);
140 }
141 }
142
143
144 /* x,y, w,h for each leter */
145 static const struct font_descr_struct {
146
147 char key;
148 SDL_Rect font_rect;
149
150 } font_descr[]= {
151 { 'a', { 288,0,12,17 } }, /* a */
152 { 'b', { 302,0,11,17 } }, /* b */
153 { 'c', { 314,0,11,17 } }, /* c */
154 { 'd', { 327,0,11,17 } }, /* d */
155 { 'e', { 340,0,11,17 } }, /* e */
156 { 'f', { 354,0,7,17 } }, /* f */
157 { 'g', { 362,0,11,17 } }, /* g */
158 { 'h', { 376,0,10,17 } }, /* h */
159 { 'i', { 389,0,6,17 } }, /* i */
160 { 'j', { 396,0,9,17 } }, /* j */
161 { 'k', { 408,0,11,17 } }, /* k */
162 { 'l', { 421,0,6,17 } }, /* l */
163 { 'm', { 430,0,14,17 } }, /* m */
164 { 'n', { 446,0,10,17 } }, /* n */
165 { 'o', { 458,0,11,17 } }, /* o */
166 { 'p', { 472,0,11,17 } }, /* p */
167 { 'q', { 484,0,11,17 } }, /* q */
168 { 'r', { 498,0,7,17 } }, /* r */
169 { 's', { 506,0,9,17 } }, /* s */
170 { 't', { 517,0,7,17 } }, /* t */
171 { 'u', { 527,0,10,17 } }, /* u */
172 { 'v', { 539,0,10,17 } }, /* v */
173 { 'w', { 550,0,14,17 } }, /* w */
174 { 'x', { 566,0,10,17 } }, /* x */
175 { 'y', { 579,0,10,17 } }, /* y */
176 { 'z', { 591,0,11,17 } }, /* z */
177 { '0', { 604,0,13,17 } }, /* 0 */
178 { '1', { 620,0,6,17 } }, /* 1 */
179 { '2', { 628,0,9,17 } }, /* 2 */
180 { '3', { 640,0,8,17 } }, /* 3 */
181 { '4', { 651,0,10,17 } }, /* 4 */
182 { '5', { 663,0,8,17 } }, /* 5 */
183 { '6', { 674,0,10,17 } }, /* 6 */
184 { '7', { 686,0,9,17 } }, /* 7 */
185 { '8', { 698,0,9,17 } }, /* 8 */
186 { '9', { 709,0,11,17 } }, /* 9 */
187 { '+', { 722,0,9,17 } }, /* HUD */
188 { '.', { 437,39,9,17 } }, /* . */
189 { 0, { 0,0,0,0 } }
190
191 };
192
193 /* ONLY supports lowcase letters */
194 void
writeCString(SDL_Surface * src,SDL_Surface * dst,int x,int y,char * str,int color)195 writeCString(SDL_Surface *src, SDL_Surface *dst, int x, int y, char *str, int color)
196 {
197 int i,j;
198 SDL_Rect a,b;
199
200 /* that's damn slow, but portable to different character sets */
201 for(i=0,a.x=x,a.y=y;i<strlen(str);i++) {
202 for(j=0; font_descr[j].key && j!=-1; j++) {
203 if(font_descr[j].key==str[i]) {
204 b=font_descr[j].font_rect;
205 if(color)
206 b.y+=19;
207 SDL_BlitSurface(src, &b, dst, &a);
208 a.x+=b.w;
209 j=-2;
210 }
211 }
212 if(j>0)
213 a.x+=12;
214
215 }
216
217 return;
218 }
219
220 /* ugly!!!! needs review */
221 char
SDLK2ascii(int sym)222 SDLK2ascii(int sym)
223 {
224 switch(sym) {
225 default:
226 break;
227 case SDLK_a:
228 return 'a';
229 case SDLK_b:
230 return 'b';
231 case SDLK_c:
232 return 'c';
233 case SDLK_d:
234 return 'd';
235 case SDLK_e:
236 return 'e';
237 case SDLK_f:
238 return 'f';
239 case SDLK_g:
240 return 'g';
241 case SDLK_h:
242 return 'h';
243 case SDLK_i:
244 return 'i';
245 case SDLK_j:
246 return 'j';
247 case SDLK_k:
248 return 'k';
249 case SDLK_l:
250 return 'l';
251 case SDLK_m:
252 return 'm';
253 case SDLK_n:
254 return 'n';
255 case SDLK_o:
256 return 'o';
257 case SDLK_p:
258 return 'p';
259 case SDLK_q:
260 return 'q';
261 case SDLK_r:
262 return 'r';
263 case SDLK_s:
264 return 's';
265 case SDLK_t:
266 return 't';
267 case SDLK_u:
268 return 'u';
269 case SDLK_v:
270 return 'v';
271 case SDLK_w:
272 return 'w';
273 case SDLK_x:
274 return 'x';
275 case SDLK_y:
276 return 'y';
277 case SDLK_z:
278 return 'z';
279 case SDLK_0:
280 return '0';
281 case SDLK_1:
282 return '1';
283 case SDLK_2:
284 return '2';
285 case SDLK_3:
286 return '3';
287 case SDLK_4:
288 return '4';
289 case SDLK_5:
290 return '5';
291 case SDLK_6:
292 return '6';
293 case SDLK_7:
294 return '7';
295 case SDLK_8:
296 return '8';
297 case SDLK_9:
298 return '9';
299 }
300
301 return ' ';
302 }
303
304