Last change
on this file since 3590 was
3102,
checked in by chris, 20 years ago
|
orxonox/branches/chris: quick doodle with simons sound test
|
File size:
1.9 KB
|
Line | |
---|
1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Simon Hofmann |
---|
13 | co-programmer: |
---|
14 | */ |
---|
15 | |
---|
16 | #include "sound_test.h" |
---|
17 | |
---|
18 | static Mix_Music* music = NULL; |
---|
19 | |
---|
20 | using namespace std; |
---|
21 | |
---|
22 | void handleKey(SDL_KeyboardEvent key); |
---|
23 | |
---|
24 | SoundControl* sound = NULL; |
---|
25 | int sfx_channel1 = -1; |
---|
26 | int sfx_channel2 = -1; |
---|
27 | int finished = 0; |
---|
28 | |
---|
29 | SoundTest::SoundTest() { |
---|
30 | sound = SoundControl::getInstance(); |
---|
31 | } |
---|
32 | |
---|
33 | SoundTest::~SoundTest() { |
---|
34 | sound->deleteInstance(); |
---|
35 | } |
---|
36 | |
---|
37 | int main( int argc, char* argv[] ) { |
---|
38 | SoundTest(); |
---|
39 | SDL_Surface *screen; |
---|
40 | SDL_Event event; |
---|
41 | SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO); |
---|
42 | screen = SDL_SetVideoMode(320, 240, 0, 0); |
---|
43 | while(!finished) { |
---|
44 | while(SDL_PollEvent(&event)) { |
---|
45 | switch(event.type) { |
---|
46 | case SDL_QUIT: |
---|
47 | finished = 1; |
---|
48 | break; |
---|
49 | case SDL_KEYDOWN: |
---|
50 | case SDL_KEYUP: |
---|
51 | handleKey(event.key); |
---|
52 | break; |
---|
53 | } |
---|
54 | } |
---|
55 | SDL_Delay(50); |
---|
56 | } |
---|
57 | SDL_Quit(); |
---|
58 | } |
---|
59 | |
---|
60 | void handleKey(SDL_KeyboardEvent key) { |
---|
61 | switch(key.keysym.sym) { |
---|
62 | case SDLK_a: |
---|
63 | if(key.type == SDL_KEYDOWN) { |
---|
64 | if(sfx_channel1 < 0) { |
---|
65 | sfx_channel1 = sound->playWav("sound1.wav"); |
---|
66 | } |
---|
67 | } else { |
---|
68 | Mix_HaltChannel(sfx_channel1); |
---|
69 | sfx_channel1 = -1; |
---|
70 | } |
---|
71 | break; |
---|
72 | case SDLK_s: |
---|
73 | if(key.type == SDL_KEYDOWN) { |
---|
74 | if(sfx_channel2 < 0) { |
---|
75 | sfx_channel2 = sound->playWav("sound2.wav"); |
---|
76 | } |
---|
77 | } else { |
---|
78 | Mix_HaltChannel(sfx_channel2); |
---|
79 | sfx_channel2 = -1; |
---|
80 | } |
---|
81 | break; |
---|
82 | case SDLK_m: |
---|
83 | if(key.state == SDL_PRESSED) { |
---|
84 | if(music == NULL) { |
---|
85 | sound->playOgg("music.ogg"); |
---|
86 | } else { |
---|
87 | Mix_HaltMusic(); |
---|
88 | Mix_FreeMusic(music); |
---|
89 | music = NULL; |
---|
90 | } |
---|
91 | } |
---|
92 | break; |
---|
93 | case SDLK_q: |
---|
94 | finished = 1; |
---|
95 | break; |
---|
96 | } |
---|
97 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.