Removed powershot sound
[tennix.git] / tennix.c
blobaa6416adb287925ec259e91ee0e345b424755bd9
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];
44 int highlight_y = 0;
46 Point elektrons[ELEKTRONS];
47 int el;
49 fprintf( stderr, "Tennix %s\n%s\n%s\n\n", VERSION, COPYRIGHT, URL);
51 srand( (unsigned)time( NULL));
53 for( el=0; el<ELEKTRONS; el++) {
54 elektrons[el].x = elektrons[el].y = 0;
55 elektrons[el].w = 20+(rand()%80);
56 elektrons[el].h = 10+(rand()%10);
57 elektrons[el].phase = 4*2*PI*((rand()%1000)/1000.0);
60 if( SDL_Init( SDL_INIT_VIDEO) == -1) {
61 fprintf( stderr, "Can't init SDL: %s\n", SDL_GetError());
62 exit( 1);
65 atexit( SDL_Quit);
67 vi = (SDL_VideoInfo*)SDL_GetVideoInfo();
69 if( (screen = SDL_SetVideoMode( WIDTH, HEIGHT, vi->vfmt->BitsPerPixel, sdl_flags)) == NULL) {
70 fprintf( stderr, "Can't set video mode: %s\n", SDL_GetError());
71 exit( 1);
74 SDL_WM_SetCaption( "Tennix! SDL", "Tennix");
75 SDL_ShowCursor( SDL_DISABLE);
76 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, 1);
78 strcpy( datadir, argv[0]);
79 strcpy( (char*)(datadir+strlen( dirname( datadir))), DATADIR);
81 init_sound( datadir);
82 init_graphics( datadir);
84 while( 1) {
85 SDL_PollEvent( &e);
86 keys = SDL_GetKeyState( NULL);
87 mb = SDL_GetMouseState( &mx, &my);
89 if( keys[SDLK_ESCAPE] || keys['q']) {
90 break;
93 if( keys['f']) {
94 SDL_WM_ToggleFullScreen( screen);
97 clearscr();
99 if( highlight_y) {
100 for( el=0; el<ELEKTRONS; el++) {
101 elektrons[el].phase += 0.02+(rand()%20/100.0);
102 elektrons[el].x = HIGHLIGHT_X + 85 + elektrons[el].w*cosf(elektrons[el].phase/4);
103 elektrons[el].y = highlight_y + elektrons[el].h*sinf(elektrons[el].phase);
107 highlight_y = 0;
108 if( M_POS_START_GAME(mx,my)) {
109 highlight_y = HIGHLIGHT_START_GAME;
110 } else if( M_POS_START_MULTI(mx,my)) {
111 highlight_y = HIGHLIGHT_START_MULTI;
112 } else if( M_POS_CREDITS(mx,my)) {
113 highlight_y = HIGHLIGHT_CREDITS;
114 } else if( M_POS_QUIT(mx,my)) {
115 highlight_y = HIGHLIGHT_QUIT;
118 if( highlight_y) {
119 show_image( GR_MENU_HIGHLIGHT, HIGHLIGHT_X, highlight_y, 255);
120 for( el=0; el<ELEKTRONS; el++) {
121 rectangle( elektrons[el].x, elektrons[el].y, 2, 2, 255, 255, 0);
125 show_image( GR_MENU, 180*2, 0, 255);
126 if( i%(12*4) == 0) {
127 sound_racket( 0);
129 show_sprite( GR_ANIMATION, (i++/12%4), 4, 20*2, 30*2, 255);
130 show_sprite( GR_RACKET, (mb&SDL_BUTTON( SDL_BUTTON_LEFT)) > 0, 4, mx, my, 255);
131 updatescr();
133 if( mb & SDL_BUTTON( SDL_BUTTON_LEFT)) {
134 if( M_POS_START_GAME(mx,my)) {
135 game( true);
136 SDL_Delay( 50);
137 while( SDL_PollEvent( &e));
139 if( M_POS_START_MULTI(mx,my)) {
140 game( false);
141 SDL_Delay( 50);
142 while( SDL_PollEvent( &e));
144 if( M_POS_CREDITS(mx,my)) {
145 //introimage( "data/credits.bmp");
147 if( M_POS_QUIT(mx,my)) {
148 break;
151 SDL_Delay( 10);
154 uninit_graphics();
156 SDL_Quit();
157 return 0;