5 * Copyright (C) 2003, 2007 Thomas Perl <thp@perli.net>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
32 static const char* filenames
[] = {
43 void init_graphics( const char *data_dir
) {
47 char temp
[MAXPATHLEN
];
49 images
= (Image
*)calloc( GR_COUNT
, sizeof( Image
));
51 for( i
=0; i
<GR_COUNT
; i
++) {
52 strcpy( temp
, data_dir
);
53 strcat( temp
, filenames
[i
]);
54 tmp
= IMG_Load( temp
);
56 fprintf( stderr
, "Error: %s\n", SDL_GetError());
60 SDL_SetColorKey( tmp
, SDL_SRCCOLORKEY
, SDL_MapRGB( tmp
->format
, 0, 0, 0));
61 data
= SDL_DisplayFormatAlpha( tmp
);
62 SDL_FreeSurface( tmp
);
65 fprintf( stderr
, "Error: %s\n", SDL_GetError());
68 images
[i
].data
= data
;
72 void uninit_graphics() {
75 for( i
=0; i
<GR_COUNT
; i
++) {
76 SDL_FreeSurface( images
[i
].data
);
82 void show_sprite( unsigned int id
, int pos
, int items
, int x_offset
, int y_offset
, int opacity
) {
86 bitmap
= images
[id
].data
;
90 SDL_SetAlpha( bitmap
, SDL_SRCALPHA
| SDL_RLEACCEL
, opacity
);
92 dst
.w
= src
.w
= bitmap
->w
/items
;
93 dst
.h
= src
.h
= bitmap
->h
;
99 SDL_BlitSurface( bitmap
, &src
, screen
, &dst
);
102 void line_horiz( int y
, Uint8 r
, Uint8 g
, Uint8 b
) {
103 Uint32 color
= SDL_MapRGB( screen
->format
, r
, g
, b
);
111 SDL_FillRect( screen
, &rect
, color
);
114 void line_vert( int x
, Uint8 r
, Uint8 g
, Uint8 b
) {
115 Uint32 color
= SDL_MapRGB( screen
->format
, r
, g
, b
);
123 SDL_FillRect( screen
, &rect
, color
);
126 void show_image( unsigned int id
, int x_offset
, int y_offset
, int opacity
) {
127 show_sprite( id
, 0, 1, x_offset
, y_offset
, opacity
);
130 void show_digit( int zahl
, int x_offset
, int y_offset
, int opacity
) {
131 show_sprite( GR_SCORE
, zahl
, 11, x_offset
, y_offset
, opacity
);
134 void introimage( unsigned int id
) {
137 for( i
=0; i
<256; i
+=10) {
139 show_image( id
, 0, 0, i
);
147 for( i
=255; i
>=0; i
-=10) {
149 show_image( id
, 0, 0, i
);
165 SDL_FillRect( screen
, &rect
, SDL_MapRGB( screen
->format
, 0, 0, 0));
169 SDL_UpdateRect( screen
, 0, 0, 0, 0);