Removed powershot sound
[tennix.git] / graphics.c
blob03aef9e938b80681e27ef15a99d9f9a9c8c458cc
2 /**
4 * Tennix! SDL Port
5 * Copyright (C) 2003, 2007 Thomas Perl <thp@perli.net>
6 *
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,
20 * MA 02110-1301, USA.
22 **/
24 #include <stdio.h>
26 #include "tennix.h"
27 #include "graphics.h"
28 #include "input.h"
30 static Image* images;
32 static const char* filenames[] = {
33 "court.png",
34 "shadow.png",
35 "player-racket.png",
36 "ground.png",
37 "ball.png",
38 "score.png",
39 "menu.png",
40 "animation.png",
41 "menu-highlight.png"
44 void init_graphics( const char *data_dir) {
45 int i;
46 SDL_Surface* data;
47 SDL_Surface* tmp;
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);
56 if( !tmp) {
57 fprintf( stderr, "Error: %s\n", SDL_GetError());
58 continue;
61 SDL_SetColorKey( tmp, SDL_SRCCOLORKEY, SDL_MapRGB( tmp->format, 0, 0, 0));
62 data = SDL_DisplayFormatAlpha( tmp);
63 SDL_FreeSurface( tmp);
65 if( !data) {
66 fprintf( stderr, "Error: %s\n", SDL_GetError());
67 continue;
69 images[i].data = data;
73 void uninit_graphics() {
74 int i;
76 for( i=0; i<GR_COUNT; i++) {
77 SDL_FreeSurface( images[i].data);
80 free( images);
83 void show_sprite( unsigned int id, int pos, int items, int x_offset, int y_offset, int opacity) {
84 SDL_Surface *bitmap;
85 SDL_Rect src, dst;
87 bitmap = images[id].data;
89 if( !bitmap) return;
91 SDL_SetAlpha( bitmap, SDL_SRCALPHA | SDL_RLEACCEL, opacity);
93 dst.w = src.w = bitmap->w/items;
94 dst.h = src.h = bitmap->h;
95 src.x = src.w*pos;
96 src.y = 0;
97 dst.x = x_offset;
98 dst.y = y_offset;
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);
105 SDL_Rect rect;
107 rect.x = 0;
108 rect.w = screen->w;
109 rect.y = y;
110 rect.h = 1;
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);
117 SDL_Rect rect;
119 rect.x = x;
120 rect.w = 1;
121 rect.y = 0;
122 rect.h = screen->h;
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);
129 SDL_Rect rect;
131 rect.x = x;
132 rect.y = y;
133 rect.w = w;
134 rect.h = h;
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) {
148 int i;
150 for( i=0; i<256; i+=10) {
151 clearscr();
152 show_image( id, 0, 0, i);
153 updatescr();
154 SDL_Delay( 30);
157 //SDL_Delay( 500);
158 wait_keypress();
160 for( i=255; i>=0; i-=10) {
161 clearscr();
162 show_image( id, 0, 0, i);
163 updatescr();
164 SDL_Delay( 30);
167 clearscr();
170 void clearscr() {
171 SDL_Rect rect;
173 rect.x = 0;
174 rect.y = 0;
175 rect.w = WIDTH;
176 rect.h = HEIGHT;
178 SDL_FillRect( screen, &rect, SDL_MapRGB( screen->format, 0, 0, 0));
181 void updatescr() {
182 SDL_UpdateRect( screen, 0, 0, 0, 0);
183 SDL_Flip( screen);