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
[] = {
44 void init_graphics( const char *data_dir
) {
48 char temp
[MAXPATHLEN
];
50 images
= (Image
*)calloc( GR_COUNT
, sizeof( Image
));
52 for( i
=0; i
<GR_COUNT
; i
++) {
53 strcpy( temp
, data_dir
);
54 strcat( temp
, filenames
[i
]);
55 tmp
= IMG_Load( temp
);
57 fprintf( stderr
, "Error: %s\n", SDL_GetError());
61 SDL_SetColorKey( tmp
, SDL_SRCCOLORKEY
, SDL_MapRGB( tmp
->format
, 0, 0, 0));
62 data
= SDL_DisplayFormatAlpha( tmp
);
63 SDL_FreeSurface( tmp
);
66 fprintf( stderr
, "Error: %s\n", SDL_GetError());
69 images
[i
].data
= data
;
73 void uninit_graphics() {
76 for( i
=0; i
<GR_COUNT
; i
++) {
77 SDL_FreeSurface( images
[i
].data
);
83 void show_sprite( unsigned int id
, int pos
, int items
, int x_offset
, int y_offset
, int opacity
) {
87 bitmap
= images
[id
].data
;
91 SDL_SetAlpha( bitmap
, SDL_SRCALPHA
| SDL_RLEACCEL
, opacity
);
93 dst
.w
= src
.w
= bitmap
->w
/items
;
94 dst
.h
= src
.h
= bitmap
->h
;
100 SDL_BlitSurface( bitmap
, &src
, screen
, &dst
);
103 void line_horiz( int y
, Uint8 r
, Uint8 g
, Uint8 b
) {
104 Uint32 color
= SDL_MapRGB( screen
->format
, r
, g
, b
);
112 SDL_FillRect( screen
, &rect
, color
);
115 void line_vert( int x
, Uint8 r
, Uint8 g
, Uint8 b
) {
116 Uint32 color
= SDL_MapRGB( screen
->format
, r
, g
, b
);
124 SDL_FillRect( screen
, &rect
, color
);
127 void rectangle( int x
, int y
, int w
, int h
, Uint8 r
, Uint8 g
, Uint8 b
) {
128 Uint32 color
= SDL_MapRGB( screen
->format
, r
, g
, b
);
136 SDL_FillRect( screen
, &rect
, color
);
139 void show_image( unsigned int id
, int x_offset
, int y_offset
, int opacity
) {
140 show_sprite( id
, 0, 1, x_offset
, y_offset
, opacity
);
143 void show_digit( int zahl
, int x_offset
, int y_offset
, int opacity
) {
144 show_sprite( GR_SCORE
, zahl
, 11, x_offset
, y_offset
, opacity
);
147 void introimage( unsigned int id
) {
150 for( i
=0; i
<256; i
+=10) {
152 show_image( id
, 0, 0, i
);
160 for( i
=255; i
>=0; i
-=10) {
162 show_image( id
, 0, 0, i
);
178 SDL_FillRect( screen
, &rect
, SDL_MapRGB( screen
->format
, 0, 0, 0));
182 SDL_UpdateRect( screen
, 0, 0, 0, 0);