sound system added

load_textures() was changed to load_resources() and will now load all sounds in sfx/. playing via play_sound(char *name) (or the pointer variant). positional audio is not implemented yet.

and some other changes.
This commit is contained in:
laochailan 2011-04-02 12:14:37 +02:00
parent 0268449151
commit 88a77b3fb8
14 changed files with 366 additions and 10 deletions

View file

@ -8,6 +8,8 @@ set(CMAKE_CFLAGS="--std=c99")
set(DATA_DIR "share/taisei")
install(DIRECTORY gfx DESTINATION ${DATA_DIR})
install(DIRECTORY sfx DESTINATION ${DATA_DIR})
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"

78
FindALUT.cmake Normal file
View file

@ -0,0 +1,78 @@
# Locate ALUT
# This module defines XXX_FOUND, XXX_INCLUDE_DIRS and XXX_LIBRARIES standard variables
#
# $ALUTDIR is an environment variable that would
# correspond to the ./configure --prefix=$ALUTDIR
# used in building ALUT.
#
# Created by Sukender (Benoit Neil). Based on FindOpenAL.cmake module. (taken from osgaudio)
IF(ALUT_USE_AL_SUBDIR)
SET(ALUT_HEADER_NAMES "AL/alut.h")
SET(ALUT_HEADER_SUFFIXES include)
ELSE()
SET(ALUT_HEADER_NAMES "alut.h")
SET(ALUT_HEADER_SUFFIXES include/AL include/OpenAL include)
ENDIF()
SET(ALUT_SEARCH_PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
FIND_PATH(ALUT_INCLUDE_DIR NAMES ${ALUT_HEADER_NAMES}
HINTS
$ENV{ALUTDIR}
$ENV{ALUT_PATH}
PATH_SUFFIXES ${ALUT_HEADER_SUFFIXES}
PATHS ${ALUT_SEARCH_PATHS}
)
FIND_LIBRARY(ALUT_LIBRARY
NAMES alut libalut
HINTS
$ENV{ALUTDIR}
$ENV{ALUT_PATH}
PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 Release
PATHS ${ALUT_SEARCH_PATHS}
)
# First search for d-suffixed libs
FIND_LIBRARY(ALUT_LIBRARY_DEBUG
NAMES alutd libalutd
HINTS
$ENV{ALUTDIR}
$ENV{ALUT_PATH}
PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 Debug
PATHS ${ALUT_SEARCH_PATHS}
)
IF(NOT ALUT_LIBRARY_DEBUG)
# Then search for non suffixed libs if necessary, but only in debug dirs
FIND_LIBRARY(ALUT_LIBRARY_DEBUG
NAMES alut libalut
HINTS
$ENV{ALUTDIR}
$ENV{ALUT_PATH}
PATH_SUFFIXES Debug
PATHS ${ALUT_SEARCH_PATHS}
)
ENDIF()
IF(ALUT_LIBRARY)
IF(ALUT_LIBRARY_DEBUG)
SET(ALUT_LIBRARIES optimized "${ALUT_LIBRARY}" debug "${ALUT_LIBRARY_DEBUG}")
ELSE()
SET(ALUT_LIBRARIES "${ALUT_LIBRARY}") # Could add "general" keyword, but it is optional
ENDIF()
ENDIF()
# handle the QUIETLY and REQUIRED arguments and set XXX_FOUND to TRUE if all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALUT DEFAULT_MSG ALUT_LIBRARIES ALUT_INCLUDE_DIR)

147
gfx/marisa.svg Normal file
View file

@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
id="svg2"
version="1.1"
inkscape:version="0.48.1 r9760"
inkscape:export-filename="/tmp/raw.png"
inkscape:export-xdpi="21"
inkscape:export-ydpi="21"
sodipodi:docname="Neues Dokument 1">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.98994949"
inkscape:cx="291.17392"
inkscape:cy="853.05298"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="992"
inkscape:window-height="832"
inkscape:window-x="536"
inkscape:window-y="219"
inkscape:window-maximized="0" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1">
<path
inkscape:connector-curvature="0"
id="path3007"
d="m 247.14285,403.65594 c 0,0 7.22697,90.46993 11.67368,122.59246 5.01874,36.25482 -19.00603,57.34346 -28.81654,1.9555 -6.88633,-38.87866 -20,-134.41314 -20,-134.41314"
style="fill:#ffffff;stroke:#000000;stroke-width:0.92908758px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
sodipodi:nodetypes="cssc" />
<path
style="fill:#ffffff;stroke:#000000;stroke-width:0.92908758px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 142.85714,407.35538 c 0,0 -8.93908,88.78667 -9.65337,120.84852 -1.08357,48.63793 22.31045,33.63198 26.79623,3.69945 3.43634,-22.92985 19.87441,-134.52156 20,-134.41315"
id="path3005"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cssc" />
<path
style="fill:#ffffff;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 101.42857,408.07647 c -2.857141,6.42857 -17.142856,25.71428 -17.142856,25.71428 l 28.588056,-9.62912 19.34886,11.28637 23.48678,-8.34344 20.67796,9.45451 26.45235,-7.69558 23.67923,13.05821 22.00579,-14.00046 31.02883,16.94195 8.71819,-12.34587 23.15681,4.84486 -20.71428,-25.71428 z"
id="path3003"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccccccccccc" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 145,265.93361 -1.42857,20 104.28571,2.85714 -0.71428,-25.71428 z"
id="path3009"
inkscape:connector-curvature="0" />
<path
style="fill:#000000;stroke:#000000;stroke-width:0.93452531000000005px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 142.14286,280.93361 109.99999,0.62381 c 14.19115,45.74214 32.90164,116.05171 56.42858,142.06732 -55.91772,5.54681 -132.98187,-10.70665 -220.714287,-5.09048 35.936577,-44.91451 44.251177,-92.68615 54.285717,-137.60065 z"
id="path2985"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
style="fill:#ffffff;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 139.28571,312.36218 121.42857,0.71428 3.57143,11.42857 -130,-2.14285 z"
id="path3001"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 130.71429,200.21932 C 133.99241,199.85508 93.544423,312.11467 101.42857,318.79075 114.27303,329.66708 152.89471,204.49564 150,205.21932"
id="path3017"
inkscape:connector-curvature="0"
sodipodi:nodetypes="csc" />
<path
style="fill:#ffffff;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 159.28972,149.92315 c -17.61106,-1.06794 -30.8557,0.99309 -35.82535,20.52161 -1.78013,7.54465 1.28129,23.22013 1.28129,23.22013 l -8.30752,8.53168 31.27454,3.12083 z"
id="path3013"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc" />
<path
sodipodi:nodetypes="csc"
inkscape:connector-curvature="0"
id="path3021"
d="m 271.27575,200.21932 c -3.27812,-0.36424 37.16987,111.89535 29.28572,118.57143 -12.84446,10.87633 -55.75185,-121.43797 -52.85714,-120.71429"
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
sodipodi:nodetypes="cccccc"
inkscape:connector-curvature="0"
id="path3015"
d="m 242.15243,147.78029 c 17.61106,-1.06794 30.8557,0.99309 35.82535,20.52161 1.78013,7.54465 -1.28129,23.22013 -1.28129,23.22013 l 8.30752,8.53168 -31.27454,3.12083 z"
style="fill:#ffffff;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
style="fill:#000000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 152.85714,148.79074 17.85715,-0.71428 7.85715,38.57143 c 10.65667,5.96768 29.08895,4.14024 39.99999,-1.42857 l 9.28572,-40 19.28571,-0.71429 c 2.14286,41.42857 15.06607,89.32535 6.42857,124.28571 -35.90628,2.08892 -70.68829,-5.50784 -112.14286,0 -5.32732,-27.20842 7.58797,-79.95649 11.42857,-120 z"
id="path2987"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccccccc" />
<path
style="fill:#ffffff;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 198.57143,313.07646 c 13.86828,-40.58217 70.2044,9.13042 15.71429,8.57143 L 225,353.07645 211.42857,364.50503 202.14286,326.64789 190,365.21931 175.71429,348.79074 189.28572,321.64789 c -68.54312,3.74311 4.74444,-48.12101 9.28571,-8.57143 z"
id="path2995"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccccccc" />
<path
style="fill:#999999;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 200.71428,45.93361 c -59.8437,2.610808 -45.04543,58.35152 -45.41645,113.58302 -0.43308,64.46908 -6.17749,129.60139 -3.86926,139.98841 5.04787,-27.61905 8.5776,-55.23809 17.14286,-82.85714 0.2381,26.76541 0.47619,55.70185 0.71429,84.28571 4.6168,-35.29021 11.813,-65.42161 22.14285,-89.28571 -1.85795,36.38176 0.32054,68.72708 2.14286,101.42857 2.36586,-36.54008 5.97802,-73.7033 12.14286,-112.14286 8.89865,37.46276 9.91473,72.95487 11.42857,108.57143 3.09524,-35 6.19047,-70 9.28571,-105 3.12618,45.08905 8.82553,89.66346 21.42857,132.85714 -4.10068,-37.6449 -7.08853,-79.74109 -9.28571,-125 0,0 25,84.28572 25,103.57143 -2.34162,-19.98383 -5.4796,-94.67549 -13.82577,-161.57244 -7.17729,-57.528135 10.2582,-111.014192 -49.03138,-108.42756 z"
id="path3023"
inkscape:connector-curvature="0"
sodipodi:nodetypes="sscccccccccccss" />
<path
style="fill:#000000;stroke:#000000;stroke-width:0.99173009000000001px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 199.40059,18.788845 C 159.97006,19.015452 89.350336,21.46641 88.566097,76.582052 87.79525,130.75659 158.84796,134.62662 197.60328,135.21284 239.02393,135.83938 311.97931,133.6512 311.43329,75.744469 310.9095,20.195255 239.13689,18.560481 199.40059,18.788845 z"
id="path3025"
inkscape:connector-curvature="0"
sodipodi:nodetypes="sssss" />
<path
style="fill:#000000;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 123.57143,64.505039 c 36.61667,-13.196572 64.69378,-97.779471 75.57386,-95.051469 20.01341,5.018037 41.8384,82.082658 80.14042,94.337183"
id="path3029"
inkscape:connector-curvature="0"
sodipodi:nodetypes="csc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 8.4 KiB

View file

@ -10,17 +10,22 @@ set(SRCs
poweritem.c
list.c
font.c
audio.c
stages/stage0.c)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
find_package(SDL REQUIRED)
find_package(OpenGL REQUIRED)
find_package(OpenAL REQUIRED)
find_package(ALUT REQUIRED)
find_package(SDL_image REQUIRED)
find_package(SDL_ttf REQUIRED)
add_definitions(-DPREFIX="${CMAKE_INSTALL_PREFIX}")
include_directories(${SDL_INCLUDE_DIRS})
include_directories(${SDL_INCLUDE_DIRS} ${ALUT_INCLUDE_DIRS})
add_executable(taisei ${SRCs})
target_link_libraries(taisei ${SDL_LIBRARY} ${OPENGL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLTTF_LIBRARY})
target_link_libraries(taisei ${SDL_LIBRARY} ${OPENGL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLTTF_LIBRARY} ${OPENAL_LIBRARY} ${ALUT_LIBRARY})
install(TARGETS taisei RUNTIME DESTINATION bin)

71
src/audio.c Normal file
View file

@ -0,0 +1,71 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
*/
#include "audio.h"
#include "global.h"
Sound *load_sound(char *filename) {
ALuint sound;
if(!(sound = alutCreateBufferFromFile(filename)))
errx(-1,"load_sound():\n!- cannot load '%s': %s", filename, alutGetErrorString(alutGetError()));
Sound *snd = create_element((void **)&global.sounds, sizeof(Sound));
snd->alsnd = sound;
char *beg = strstr(filename, "sfx/") + 4;
char *end = strrchr(filename, '.');
snd->name = malloc(end - beg + 1);
memset(snd->name, 0, end-beg + 1);
strncpy(snd->name, beg, end-beg);
printf("-- loaded '%s' as '%s'\n", filename, snd->name);
return snd;
}
Sound *get_snd(char *name) {
Sound *s, *res = NULL;
for(s = global.sounds; s; s = s->next) {
if(strcmp(s->name, name) == 0)
res = s;
}
if(res == NULL)
errx(-1,"get_snd():\n!- cannot load sound '%s'", name);
return res;
}
void play_sound(char *name) {
play_sound_p(get_snd(name));
}
void play_sound_p(Sound *snd) {
ALuint i,res = -1;
ALint play;
for(i = 0; i < SNDSRC_COUNT; i++) {
alGetSourcei(global.sndsrc[i],AL_SOURCE_STATE,&play);
if(play != AL_PLAYING) {
res = i;
break;
}
}
if(res != -1) {
alSourcei(global.sndsrc[res],AL_BUFFER, snd->alsnd);
alSourcePlay(global.sndsrc[res]);
} else {
fprintf(stderr,"play_sound_p():\n!- not enough sources");
}
}
void delete_sounds() {
delete_all_elements((void **)&global.sounds);
}

30
src/audio.h Normal file
View file

@ -0,0 +1,30 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
*/
#ifndef AUDIO_H
#define AUDIO_H
#include <AL/alut.h>
struct Sound;
typedef struct Sound {
struct Sound *next;
struct Sound *prev;
ALuint alsnd;
char *name;
} Sound;
Sound *load_sound(char *filename);
void play_sound(char *name);
void play_sound_p(Sound *snd);
Sound *get_snd(char *name);
void delete_sounds();
#endif

View file

@ -27,7 +27,9 @@ void init_global() {
global.lasttime = 0;
load_textures();
alGenSources(SNDSRC_COUNT, global.sndsrc);
load_resources();
init_fonts();
}

View file

@ -13,6 +13,7 @@
#include "projectile.h"
#include "fairy.h"
#include "poweritem.h"
#include "audio.h"
enum {
RESX = 800,
@ -28,6 +29,8 @@ enum {
POINT_OF_COLLECT = VIEWPORT_H/4,
SNDSRC_COUNT = 30,
FPS = 60
};
@ -43,6 +46,9 @@ typedef struct {
Texture *textures;
Animation *animations;
Sound *sounds;
ALuint sndsrc[SNDSRC_COUNT];
int game_over;

View file

@ -43,6 +43,7 @@ void shutdown() {
delete_textures();
delete_animations();
alutExit();
SDL_FreeSurface(display);
SDL_Quit();
}
@ -57,9 +58,11 @@ int main(int argc, char** argv) {
errx(-1, "Error opening screen: %s", SDL_GetError());
init_gl();
if(!alutInit(&argc, argv))
errx(-1, "Error initializing audio: %s", alutGetErrorString(alutGetError()));
init_global();
stage0_loop();
atexit(shutdown);
shutdown();
}

View file

@ -86,8 +86,6 @@ void player_logic(Player* plr) {
create_projectile("youmu", plr->pos - 10 - I*20, ((Color){1,1,1}), linear, I*-20*cexp(I*a))->type = PlrProj;
}
}
// if(global.frames - abs(plr->recovery) >= 0)
if(plr->focus < 0 || (plr->focus > 0 && plr->focus < 30))
plr->focus++;
@ -99,6 +97,9 @@ void plr_bomb(Player *plr) {
for(f = global.fairies; f; f = f->next)
f->hp = 0;
free_projectiles();
play_sound("laser1");
plr->bombs--;
plr->recovery = global.frames + 200;
}

View file

@ -58,6 +58,7 @@ void process_poweritems() {
v = collision(poweritem);
if(v == 1) {
global.plr.power += 0.1;
play_sound("item_generic");
}
if(v == 1 || creal(poweritem->pos) < -9 || creal(poweritem->pos) > VIEWPORT_W + 9
|| cimag(poweritem->pos) > VIEWPORT_H + 8 ) {

View file

@ -62,6 +62,7 @@ int test_collision(Projectile *p) {
while(f != NULL) {
if(cabs(f->pos - p->pos) < 15) {
f->hp--;
play_sound("hit");
return 2;
}
f = f->next;

View file

@ -101,6 +101,7 @@ void stage0_events() {
// create_fairy(VIEWPORT_W-1, 10, -1, 180, 3, simpleFairy);
// create_fairy(VIEWPORT_W-1, 200, -1, 180, 3, simpleFairy);
create_projectile("ball", VIEWPORT_W/2, ((Color) {0,0,1}), linear, 2*I);
play_sound("shot_special1");
}
}

View file

@ -10,7 +10,7 @@
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "audio.h"
void recurse_dir(char *path) {
DIR *dir = opendir(path);
@ -33,16 +33,24 @@ void recurse_dir(char *path) {
init_animation(buf);
else
load_texture(buf);
} else if(strcmp(dp->d_name + strlen(dp->d_name)-4, ".wav") == 0) {
load_sound(buf);
}
}
}
void load_textures() {
printf("load_textures():\n");
void load_resources() {
printf("load_resources():\n");
char *path = malloc(sizeof(FILE_PREFIX)+4);
printf("- textures:\n");
strcpy(path, FILE_PREFIX);
strncat(path, "gfx", sizeof(FILE_PREFIX)+4);
recurse_dir(path);
printf("- sounds:\n");
strcpy(path, FILE_PREFIX);
strncat(path, "sfx", sizeof(FILE_PREFIX)+4);
recurse_dir(path);
}