removed images
[tennix.git] / graphics.c
blobea5ebf8a7860e274f20841470770b785b4a4c952
1 #include <stdio.h>
3 #include "tennix.h"
4 #include "graphics.h"
5 #include "input.h"
7 static Image* images;
9 static const char* filenames[] = {
10 "court.bmp",
11 "shadow.png",
12 "player-racket.bmp",
13 "ground.png",
14 "ball.png",
15 "score.png",
16 "menu.bmp",
17 "animation.bmp"
20 void init_graphics( const char *data_dir) {
21 int i;
22 SDL_Surface* data;
23 SDL_Surface* tmp;
24 char temp[MAXPATHLEN];
26 images = (Image*)calloc( GR_COUNT, sizeof( Image));
28 for( i=0; i<GR_COUNT; i++) {
29 strcpy( temp, data_dir);
30 strcat( temp, filenames[i]);
31 tmp = IMG_Load( temp);
32 if( !tmp) {
33 fprintf( stderr, "Error: %s\n", SDL_GetError());
34 continue;
37 SDL_SetColorKey( tmp, SDL_SRCCOLORKEY, SDL_MapRGB( tmp->format, 0, 0, 0));
38 data = SDL_DisplayFormatAlpha( tmp);
39 SDL_FreeSurface( tmp);
41 if( !data) {
42 fprintf( stderr, "Error: %s\n", SDL_GetError());
43 continue;
45 images[i].data = data;
49 void uninit_graphics() {
50 int i;
52 for( i=0; i<GR_COUNT; i++) {
53 SDL_FreeSurface( images[i].data);
56 free( images);
59 void show_sprite( unsigned int id, int pos, int items, int x_offset, int y_offset, int opacity) {
60 SDL_Surface *bitmap;
61 SDL_Rect src, dst;
63 bitmap = images[id].data;
65 if( !bitmap) return;
67 SDL_SetAlpha( bitmap, SDL_SRCALPHA | SDL_RLEACCEL, opacity);
69 dst.w = src.w = bitmap->w/items;
70 dst.h = src.h = bitmap->h;
71 src.x = src.w*pos;
72 src.y = 0;
73 dst.x = x_offset;
74 dst.y = y_offset;
76 SDL_BlitSurface( bitmap, &src, screen, &dst);
79 void show_image( unsigned int id, int x_offset, int y_offset, int opacity) {
80 show_sprite( id, 0, 1, x_offset, y_offset, opacity);
83 void show_digit( int zahl, int x_offset, int y_offset, int opacity) {
84 show_sprite( GR_SCORE, zahl, 11, x_offset, y_offset, opacity);
87 void introimage( unsigned int id) {
88 int i;
90 for( i=0; i<256; i+=10) {
91 clearscr();
92 show_image( id, 0, 0, i);
93 updatescr();
94 SDL_Delay( 30);
97 //SDL_Delay( 500);
98 wait_keypress();
100 for( i=255; i>=0; i-=10) {
101 clearscr();
102 show_image( id, 0, 0, i);
103 updatescr();
104 SDL_Delay( 30);
107 clearscr();
110 void clearscr() {
111 SDL_Rect rect;
113 rect.x = 0;
114 rect.y = 0;
115 rect.w = WIDTH;
116 rect.h = HEIGHT;
118 SDL_FillRect( screen, &rect, SDL_MapRGB( screen->format, 0, 0, 0));
121 void updatescr() {
122 SDL_UpdateRect( screen, 0, 0, 0, 0);
123 SDL_Flip( screen);