initial import of tennix SDL port
[tennix.git] / graphics.c
blob280f6c75b7b5bb9b8ac9f1d86ad64f81467265c5
1 #include <stdio.h>
3 #include <SDL/SDL.h>
5 #include "tennix.h"
6 #include "graphics.h"
7 #include "input.h"
9 void show_sprite( const char* name, int pos, int items, int x_offset, int y_offset, int opacity) {
10 SDL_Surface *bitmap;
11 SDL_Rect src, dst;
13 bitmap = SDL_LoadBMP( name);
14 if( bitmap == NULL) {
15 fprintf( stderr, "Error: %s\n", SDL_GetError());
16 return;
19 SDL_SetAlpha( bitmap, SDL_SRCALPHA | SDL_RLEACCEL, opacity);
20 SDL_SetColorKey( bitmap, SDL_SRCCOLORKEY, SDL_MapRGB( bitmap->format, 0, 0, 0));
22 dst.w = src.w = bitmap->w/items;
23 dst.h = src.h = bitmap->h;
24 src.x = src.w*pos;
25 src.y = 0;
26 dst.x = x_offset;
27 dst.y = y_offset;
29 SDL_BlitSurface( bitmap, &src, screen, &dst);
30 SDL_FreeSurface( bitmap);
33 void show_bmp( const char *name, int x_offset, int y_offset, int opacity) {
34 show_sprite( name, 0, 1, x_offset, y_offset, opacity);
37 void show_digit( int zahl, int x_offset, int y_offset, int opacity) {
38 show_sprite( "data/score.bmp", zahl, 11, x_offset, y_offset, opacity);
41 void introimage( char *name) {
42 int i;
44 for( i=0; i<256; i+=10) {
45 clearscr();
46 show_bmp( name, 0, 0, i);
47 updatescr();
48 SDL_Delay( 30);
51 //SDL_Delay( 500);
52 wait_keypress();
54 for( i=255; i>=0; i-=10) {
55 clearscr();
56 show_bmp( name, 0, 0, i);
57 updatescr();
58 SDL_Delay( 30);
61 clearscr();
64 void clearscr() {
65 SDL_Rect rect;
67 rect.x = 0;
68 rect.y = 0;
69 rect.w = WIDTH;
70 rect.h = HEIGHT;
72 SDL_FillRect( screen, &rect, SDL_MapRGB( screen->format, 0, 0, 0));
75 void updatescr() {
76 SDL_UpdateRect( screen, 0, 0, 0, 0);