~ubuntu-branches/ubuntu/edgy/dd2/edgy

« back to all changes in this revision

Viewing changes to src/SDL_plus.c

  • Committer: Bazaar Package Importer
  • Author(s): Gürkan Sengün
  • Date: 2006-04-23 14:52:00 UTC
  • Revision ID: james.westby@ubuntu.com-20060423145200-wr4obk2gvkcishho
Tags: upstream-0.2.1
Import upstream version 0.2.1

Show diffs side-by-side

added added

removed removed

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