use pngs instead of bmps
[tennix.git] / tennix.c
blobb5e371e09232ae8bdc4601d9bc37a8da7e2c3c10
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>
25 #include <time.h>
26 #include <libgen.h>
28 #include "tennix.h"
29 #include "game.h"
30 #include "graphics.h"
31 #include "sound.h"
33 SDL_Surface *screen;
35 int main( int argc, char** argv) {
36 int i = 0;
37 int mx, my;
38 Uint8 *keys;
39 Uint8 mb;
40 SDL_Event e;
41 SDL_VideoInfo* vi;
42 int sdl_flags = SDL_SWSURFACE | SDL_DOUBLEBUF;
43 char datadir[MAXPATHLEN];
45 fprintf( stderr, "Tennix %s\n%s\n%s\n\n", VERSION, COPYRIGHT, URL);
47 srand( (unsigned)time( NULL));
49 if( SDL_Init( SDL_INIT_VIDEO) == -1) {
50 fprintf( stderr, "Can't init SDL: %s\n", SDL_GetError());
51 exit( 1);
54 atexit( SDL_Quit);
56 vi = (SDL_VideoInfo*)SDL_GetVideoInfo();
58 if( (screen = SDL_SetVideoMode( WIDTH, HEIGHT, vi->vfmt->BitsPerPixel, sdl_flags)) == NULL) {
59 fprintf( stderr, "Can't set video mode: %s\n", SDL_GetError());
60 exit( 1);
63 SDL_WM_SetCaption( "Tennix! SDL", "Tennix");
64 SDL_ShowCursor( SDL_DISABLE);
65 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, 1);
67 strcpy( datadir, argv[0]);
68 strcpy( (char*)(datadir+strlen( dirname( datadir))), DATADIR);
70 init_sound( datadir);
71 init_graphics( datadir);
73 while( 1) {
74 SDL_PollEvent( &e);
75 keys = SDL_GetKeyState( NULL);
76 mb = SDL_GetMouseState( &mx, &my);
78 if( keys[SDLK_ESCAPE] || keys['q']) {
79 break;
82 if( keys['f']) {
83 SDL_WM_ToggleFullScreen( screen);
86 clearscr();
87 show_image( GR_MENU, 180*2, 0, 255);
88 if( i%(12*4) == 0) {
89 sound_racket( 0);
91 show_sprite( GR_ANIMATION, (i++/12%4), 4, 20*2, 30*2, 255);
92 show_sprite( GR_RACKET, (mb&SDL_BUTTON( SDL_BUTTON_LEFT)) > 0, 4, mx, my, 255);
93 updatescr();
95 if( mb & SDL_BUTTON( SDL_BUTTON_LEFT)) {
96 if( M_POS_START_GAME(mx,my)) {
97 game();
98 SDL_Delay( 50);
99 while( SDL_PollEvent( &e));
101 if( M_POS_HIGH_SCORES(mx,my)) {
102 //introimage( "data/hiscores.bmp");
104 if( M_POS_CREDITS(mx,my)) {
105 //introimage( "data/credits.bmp");
107 if( M_POS_QUIT(mx,my)) {
108 break;
111 SDL_Delay( 10);
114 uninit_graphics();
116 SDL_Quit();
117 return 0;