-
Notifications
You must be signed in to change notification settings - Fork 7
/
intro.c
655 lines (554 loc) · 19.6 KB
/
intro.c
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
/*
* IceBreaker
* Copyright (c) 2000-2020 Matthew Miller <mattdm@mattdm.org> and
* Enrico Tassi <gareuselesinge@infinito.it>
*
* <http://www.mattdm.org/icebreaker/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/* special thanks to Enrico for the grid coloring stuff for themes */
/* and for the vastly improved circular scrolling code */
#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include "icebreaker.h"
#include "cursor.h"
#include "penguin.h"
#include "line.h"
#include "grid.h"
#include "sound.h"
#include "laundry.h"
#include "globals.h"
#include "level.h"
#include "status.h"
#include "text.h"
#include "hiscore.h"
#include "themes.h"
#include "event.h"
#include "fullscreen.h"
#include "options.h"
#define LXPOS(x) (BORDERLEFT+(BLOCKWIDTH*(x)))
#define LYPOS(y) (BORDERTOP+(BLOCKHEIGHT*(y)))
static void setupintro(void);
void circularblit(SDL_Surface* scoresurface,SDL_Rect* scrollrect,Uint16 hiscorescroll);
SDL_Surface* createscoresurface();
void setupintro()
{
int x,y;
setcursor(CURSORARROW);
SDL_FillRect(screen,NULL,color.background);
for (x=0;x<WIDTH;x++)
for (y=0;y<HEIGHT;y++)
{
if (x<BORDERLEFT || x>=BORDERRIGHT || y <BORDERTOP || y>=BORDERBOTTOM)
grid[x][y]='X';
else
grid[x][y]='w';
}
/// Here's the fun part where we set up the letters.
// I
markgrid(LXPOS(1),LYPOS(2),BLOCKWIDTH*3,BLOCKHEIGHT ,' ');
markgrid(LXPOS(1),LYPOS(7),BLOCKWIDTH*3,BLOCKHEIGHT ,' ');
markgrid(LXPOS(2),LYPOS(2),BLOCKWIDTH ,BLOCKHEIGHT*6,' ');
//C
markgrid(LXPOS(5),LYPOS(2),BLOCKWIDTH*4,BLOCKHEIGHT ,' ');
markgrid(LXPOS(5),LYPOS(3),BLOCKWIDTH ,BLOCKHEIGHT*5,' ');
markgrid(LXPOS(6),LYPOS(7),BLOCKWIDTH*3,BLOCKHEIGHT, ' ');
//E
markgrid(LXPOS(10),LYPOS(2),BLOCKWIDTH*4,BLOCKHEIGHT ,' ');
markgrid(LXPOS(10),LYPOS(3),BLOCKWIDTH ,BLOCKHEIGHT*5,' ');
markgrid(LXPOS(11),LYPOS(7),BLOCKWIDTH*3,BLOCKHEIGHT, ' ');
markgrid(LXPOS(11),LYPOS(4),BLOCKWIDTH*2,BLOCKHEIGHT ,' ');
drawgridblocks();
updateall();
}
int intro(void)
{
int penguincount=0;
int frozen=true;
int i;
int x,y;
int letterstep=0;
int hiscorescroll=0;
int hiscorestep=0;
int linedone1=false; int linedone2=false;
SDL_Rect labelrect;
SDL_Rect scrollrect;
#ifdef DEVELRELEASE
SDL_Rect develdisclaimerrect;
#endif
int done = false;
Penguin flock[100];
Penguin tux;
SDL_Event event;
SDL_Surface* scoresurface;
setupintro();
#ifdef DEVELRELEASE
develdisclaimerrect.x=BORDERLEFT-3;
develdisclaimerrect.y=MARGINTOP+PLAYHEIGHT+CHARHEIGHT*2;
develdisclaimerrect.h=CHARHEIGHT*3;
develdisclaimerrect.w=WIDTH-develdisclaimerrect.x;
#endif
labelrect.x=BORDERLEFT;
labelrect.y=BORDERTOP-(4*CHARHEIGHT);
labelrect.h=CHARHEIGHT*2;
labelrect.w=CHARWIDTH*21;
scrollrect.x=BORDERLEFT+CHARWIDTH*21;
scrollrect.y=labelrect.y;
scrollrect.w=BORDERRIGHT-(BORDERLEFT+CHARWIDTH*21);
scrollrect.h=labelrect.h;
hiscorescroll=0;
puttext(labelrect.x,labelrect.y,2,color.normaltext,"HIGH SCORES:");
soil(labelrect);
#ifdef DEVELRELEASE
puttext(develdisclaimerrect.x,develdisclaimerrect.y,1,color.copyrighttext,"This is a development (beta) release meant for bug-testing only. Please check");
puttext(develdisclaimerrect.x+3,develdisclaimerrect.y+CHARHEIGHT*1.5,1,color.copyrighttext,"<http://www.mattdm.org/icebreaker/> for the latest stable release. Thanks!");
soil(develdisclaimerrect);
#endif
line1=createline(1);
line2=createline(2);
tux = createpenguin();
// create highscore surface
scoresurface = createscoresurface();
do
{
while (pollevent(&event))
{
if (event.type == SDL_QUIT)
{
return(true);
// fix -- should delete penguins here
}
else if (event.type == SDL_MOUSEBUTTONUP)
{
done=true;
}
else if (event.type == SDL_KEYUP)
{
switch(translatekeyevent(&event))
{
case KEYCANCEL:
if (gameflags.isfullscreen) makewindowed();
break;
case KEYSWITCHLINE: // falls through
case KEYMENU: // yep
case KEYSTARTLINE: // start game
if (letterstep>1) done=true; // kludge to keep from catching enter keystroke which launched app
default:
break;
}
}
}
if (letterstep < 10)
{
switch (letterstep)
{
// I
case 0:
if (!linedone1 && !line1.on) startline(&line1,LEFT,LXPOS(2),LYPOS(2));
if (!linedone2 && !line2.on) startline(&line2,RIGHT,LXPOS(2),LYPOS(2));
break;
case 1:
if (!linedone1 && !line1.on) startline(&line1,LEFT,LXPOS(2),LYPOS(7));
if (!linedone2 && !line2.on) startline(&line2,RIGHT,LXPOS(2),LYPOS(7));
break;
case 2:
if (!linedone1 && !line1.on) startline(&line1,UP,LXPOS(2),LYPOS(5));
if (!linedone2 && !line2.on) startline(&line2,DOWN,LXPOS(2),LYPOS(5));
break;
// C
case 3:
if (!linedone1 && !line1.on) startline(&line1,LEFT,LXPOS(7),LYPOS(2));
if (!linedone2 && !line2.on) startline(&line2,RIGHT,LXPOS(7),LYPOS(2));
break;
case 4:
if (!linedone1 && !line1.on) startline(&line1,UP,LXPOS(5),LYPOS(5));
if (!linedone2 && !line2.on) startline(&line2,DOWN,LXPOS(5),LYPOS(5));
break;
case 5:
if (!linedone1 && !line1.on) startline(&line1,LEFT,LXPOS(7),LYPOS(7));
if (!linedone2 && !line2.on) startline(&line2,RIGHT,LXPOS(7),LYPOS(7));
break;
// E
case 6:
if (!linedone1 && !line1.on) startline(&line1,LEFT,LXPOS(11),LYPOS(2));
if (!linedone2 && !line2.on) startline(&line2,RIGHT,LXPOS(11),LYPOS(2));
break;
case 7:
if (!linedone1 && !line1.on) startline(&line1,UP,LXPOS(10),LYPOS(5));
if (!linedone2 && !line2.on) startline(&line2,DOWN,LXPOS(10),LYPOS(5));
break;
case 8:
if (!linedone1 && !line1.on) startline(&line1,LEFT,LXPOS(13),LYPOS(7));
if (!linedone2 && !line2.on) startline(&line2,RIGHT,LXPOS(13),LYPOS(7));
break;
case 9:
if (!linedone1 && !line1.on) startline(&line1,LEFT,LXPOS(12),LYPOS(4));
if (!linedone2 && !line2.on) startline(&line2,RIGHT,LXPOS(12),LYPOS(4));
break;
}
}
else if (letterstep==10)
{
for (x=0;x<WIDTH;x++)
for (y=0;y<HEIGHT;y++)
if (grid[x][y]=='w')
{
grid[x][y]=' ';
}
// FIX: known bug -- if a line stops partway through a grid cell,
// the space left over is not cleared properly later. this isn't
// an issue in the game, as lines aways stop on cell boundaries, but
// sometimes shows up in the intro. this is a kludge
// which should fix it.
else if (((x-BORDERLEFT) % BLOCKWIDTH)==0 && ((y-BORDERTOP) % BLOCKHEIGHT)==0)
{
if (grid[x+BLOCKWIDTH-1][y+BLOCKHEIGHT-1]==' ')
grid[x][y]=' ';
}
letterstep++;
}
else if (letterstep==11)
{
//B
flock[penguincount]=createpenguinxy(LXPOS(0),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(0),LYPOS(12)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(0),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(0),LYPOS(14)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(0),LYPOS(15)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(0),LYPOS(16)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(1),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(2),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(1),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(2),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(1),LYPOS(16)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(2),LYPOS(16)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(3),LYPOS(12)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(3),LYPOS(14)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(3),LYPOS(15)); penguincount++;
//R
flock[penguincount]=createpenguinxy(LXPOS(5),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(5),LYPOS(12)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(5),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(5),LYPOS(14)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(5),LYPOS(15)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(5),LYPOS(16)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(6),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(7),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(6),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(7),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(8),LYPOS(12)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(8),LYPOS(14)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(8),LYPOS(15)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(8),LYPOS(16)); penguincount++;
//E
flock[penguincount]=createpenguinxy(LXPOS(10),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(10),LYPOS(12)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(10),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(10),LYPOS(14)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(10),LYPOS(15)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(10),LYPOS(16)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(11),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(12),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(11),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(12),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(11),LYPOS(16)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(12),LYPOS(16)); penguincount++;
//A
flock[penguincount]=createpenguinxy(LXPOS(14),LYPOS(12)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(14),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(14),LYPOS(14)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(14),LYPOS(15)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(14),LYPOS(16)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(17),LYPOS(12)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(17),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(17),LYPOS(14)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(17),LYPOS(15)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(17),LYPOS(16)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(15),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(16),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(15),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(16),LYPOS(13)); penguincount++;
//K
flock[penguincount]=createpenguinxy(LXPOS(19),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(19),LYPOS(12)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(19),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(19),LYPOS(14)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(19),LYPOS(15)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(19),LYPOS(16)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(20),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(21),LYPOS(12)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(22),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(21),LYPOS(14)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(22),LYPOS(15)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(22),LYPOS(16)); penguincount++;
//E
flock[penguincount]=createpenguinxy(LXPOS(24),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(24),LYPOS(12)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(24),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(24),LYPOS(14)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(24),LYPOS(15)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(24),LYPOS(16)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(25),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(26),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(25),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(26),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(25),LYPOS(16)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(26),LYPOS(16)); penguincount++;
//R
flock[penguincount]=createpenguinxy(LXPOS(28),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(28),LYPOS(12)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(28),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(28),LYPOS(14)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(28),LYPOS(15)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(28),LYPOS(16)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(29),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(30),LYPOS(11)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(29),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(30),LYPOS(13)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(31),LYPOS(12)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(31),LYPOS(14)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(31),LYPOS(15)); penguincount++;
flock[penguincount]=createpenguinxy(LXPOS(31),LYPOS(16)); penguincount++;
if (penguincount>=MAXPENGUINS) { fprintf(stderr,"Too many penguins!\n"); }
for (i=0;i<penguincount;i++)
{
savebehindpenguin(&flock[i]);
markgrid(flock[i].geom.x,flock[i].geom.y,BLOCKWIDTH,BLOCKHEIGHT,'*');
drawpenguin(&flock[i]);
soil(flock[i].geom);
}
letterstep++;
}
else if (letterstep<300)
{
letterstep++;
}
else if (letterstep==300)
{
frozen=false;
for (i=0;i<penguincount;i++)
{
markgrid(flock[i].geom.x,flock[i].geom.y,BLOCKWIDTH,BLOCKHEIGHT,' ');
erasepenguin(&flock[i]);
soil(flock[i].geom);
}
letterstep++;
setcursor(CURSORCLICK);
}
else if (letterstep<400)
{
letterstep++;
}
else if (letterstep==400)
{
if (penguincount)
{
penguincount--;
markgrid(flock[penguincount].geom.x,flock[penguincount].geom.y,BLOCKWIDTH,BLOCKHEIGHT,' ');
erasepenguin(&flock[penguincount]);
soil(flock[penguincount].geom);
deletepenguin(&flock[penguincount]);
}
else
{
letterstep++;
}
}
else if (letterstep<800)
{
if (!line1.on && !line2.on)
{
x=LXPOS(random() % 32);
y=LYPOS(random() % 20);
if (random()%2)
{
startline(&line1,UP,x,y);
startline(&line2,DOWN,x,y);
}
else
{
startline(&line1,LEFT,x,y);
startline(&line2,RIGHT,x,y);
}
}
}
//else if (letterstep<2000)
//{
// letterstep++;
//}
//else
//{
// done=true;
//}
hiscorestep--;
if (hiscorestep<0)
{
circularblit(scoresurface,&scrollrect,hiscorescroll);
soil(scrollrect);
hiscorescroll++;
hiscorestep=2;
}
if (hiscorescroll >= scoresurface->w)
{
hiscorescroll=0;
}
// move split-lines
if (line1.on)
{
if (moveline(&line1))
{
linedone1=true;
}
if (line1.dead) // need a second check because moveline could change this
{
//no sound in intro?
//playsound(SNDBREAK);
killline(&line1);
linedone1=false;
}
}
if (line2.on)
{
if (moveline(&line2))
{
linedone2=true;
}
if (line2.dead)
{
// no sound in intro?
//playsound(SNDBREAK);
killline(&line2);
linedone2=false;
}
}
if (linedone1 && linedone2) { letterstep++; linedone1=false; linedone2=false; }
// move (and get old background)
if (!frozen)
{
for (i=0;i<penguincount;i+=2)
{
soil(flock[i].geom); // mark the penguin's old position as dirty
movepenguin(&flock[i]);
soil(flock[i].geom); // mark the penguin's new position as dirty too (it will be soon...)
savebehindpenguin(&flock[i]);
}
}
soil(tux.geom); // mark the penguin's old position as dirty
movepenguin(&tux);
soil(tux.geom); // mark the penguin's new position as dirty too (it will be soon...)
savebehindpenguin(&tux);
// actually draw
if (!frozen)
{
for (i=0;i<penguincount;i+=2)
{
drawpenguin(&flock[i]);
}
}
drawpenguin(&tux);
// update screen
clean();
// clear for next update
if (!frozen)
{
for (i=0;i<penguincount;i+=2)
{
erasepenguin(&flock[i]);
}
}
erasepenguin(&tux);
SDL_Delay(10);
} while (!done);
clean();
while (penguincount)
{
penguincount--;
deletepenguin(&flock[penguincount]);
}
deletepenguin(&tux);
// destroy highscore surface
SDL_FreeSurface(scoresurface);
return(false);
}
#define EXTRASCROLLSCORESPACE 30
// FIX -- the max username length is hardcoded at 50 in highscore.c, and as
// 12 in dialog.c. The 12 is so it fits in the dialog box nicely, and should
// be plenty long, but it's good to keep the buffer bigger. Anyway, the value
// in highscore.c should be a define, and this should be that-define + some
// reasonable value for the width of the score.
#define SCOREMAXLEN 550
SDL_Surface* createscoresurface()
{
SDL_Surface* tmpsurface;
char scoretext[SCOREMAXLEN];
int i,len;
//calculate needed len
len=0;
for( i = 0 ; i < HISCORENUM ; i++)
{
snprintf(scoretext,SCOREMAXLEN,"#%d. %s: %ld",i+1,hiscorename[i],hiscoreval[i]);
len += gettextwidth(2,scoretext);
}
len += (HISCORENUM+1) * EXTRASCROLLSCORESPACE;
//alloc surface
tmpsurface = SDL_CreateRGBSurface(SDL_SWSURFACE,len,CHARHEIGHT*2,VIDEODEPTH,0,0,0,0);
// fill surface
SDL_FillRect(tmpsurface,NULL,color.background);
len=0;
for( i = 0 ; i < HISCORENUM ; i++)
{
snprintf(scoretext,SCOREMAXLEN,"#%d. %s: %ld",i+1,hiscorename[i],hiscoreval[i]);
sputtext(tmpsurface,len,0,2,color.normaltext,scoretext);
len += gettextwidth(2,scoretext) + EXTRASCROLLSCORESPACE;
}
return tmpsurface;
}
// this assumes that scoresurface->w > scrollrect->w
void circularblit(SDL_Surface* scoresurface,SDL_Rect* scrollrect,Uint16 hiscorescroll)
{
SDL_Rect from,to;
Sint32 len;
//calculate fiirst part w
if( scoresurface->w - hiscorescroll < scrollrect->w)
len = scoresurface->w - hiscorescroll;
else
len = scrollrect->w;
// draw first part to scoresurface
from.x=hiscorescroll;
from.y=0;
from.w=len;
from.h=scoresurface->h;
to.x=scrollrect->x;
to.y=scrollrect->y;
to.w=from.w;
to.h=from.h;
SDL_BlitSurface(scoresurface,&from,screen,&to);
//if needed, draw second part to scoresurface
if(len < scrollrect->w)
{
from.x=0;
from.y=0;
from.w=scrollrect->w - len;
from.h=scoresurface->h;
to.x=scrollrect->x + len;
to.y=scrollrect->y;
to.w=from.w;
to.h=from.h;
SDL_BlitSurface(scoresurface,&from,screen,&to);
}
}