Меню сайта
Форма входа

Категории раздела
Уроки по созданию игр [38]
Программирование игр разной сложности
Игровые алгоритмы [24]
Алгоритмы, которые уже реализованы для разных жанров игр
Графика [5]
Учимся работать с графикой в Делфи
Мультимедиа [3]
Работа с мультимедийными возможностями Делфи
Другие статьи [18]
Статьи не вошедшие не в один из разделов
Ошибки [4]
Всевозможные ошибки и пути их решения
Четверг, 16.05.2024, 16:00
Приветствую Вас Гость

Статьи по программированию

Главная » Статьи » Мультимедиа

Работа со звуком с помощью Bass.dll

В данных процедурах я показал как можно реализовать работу с библиотекой Bass.dll. Эта библиотека позволяет работать с аудио форматом mp3, запускать одновременно много звуковых дорожек (что необходимо при создании игр). Например одновременно может играть фоновая музыка, шаги главного героя и звуки ударов монстров. В папке с игрой обязательно должны находиться файлы Bass.dcu, bass.dll и SongStream.dcu.

Вот созданные мною процедуры, в которых есть также проверка на окончание звука, чтобы заново перезапускать звук (непрерывная игра)

var
path:string; //put k papke s igroy
Ground:integer; //nomer zemli
PlayerStar,PlayerStarGo:Boolean; //proverka na izmeneniya
Songs:array[1..6]of TSongStream; //massiv s podderzhkoy 6 odnovremennih zvukov
procedure PlayMusicAll;
procedure PlayMusicMenu;
procedure PlayMusicTorg;
procedure ProverkaMusic;

 

Чтобы работать с переменными типа TSongstream нужно нашим переменнім віделить память под музыку:

 

Songs[1]:=TSongStream.Create;

 

А уже далее мы создаем наши процедуры и т.д.


procedure PlayMusicAll;
begin
form2.Caption:=inttostr(Karta.map[round(Player.x/60),round(Player.y/60)]);
case Karta.map[round(Player.x/60),round(Player.y/60)] of
2:
begin
Randomize;
Songs[1].Init(path+'\DATA\msc\'+inttostr( random(9)+1 )+'.mp3');
Songs[1].Play(true);
Songs[1].SetVolume(30);
Songs[2].Init(path+'\DATA\msc\priroda.mp3');
Songs[2].Play(true);
end;
5:
begin
Randomize;
Songs[1].Init(path+'\DATA\msc\'+inttostr( random(9)+1 )+'.mp3');
Songs[1].Play(true);
Songs[1].SetVolume(30);
Songs[2].Init(path+'\DATA\msc\priroda.mp3');
Songs[2].Play(true);
end;
7:
begin
Randomize;
Songs[1].Init(path+'\DATA\msc\korol2.mp3');
Songs[1].Play(true);
Songs[1].SetVolume(30);
Songs[2].stop;
end;
end;
//proverka na zdaniye korolevstva
if (Player.x>=5868) and (Player.x<=7098) and (Player.y>=1484) and (Player.y<=3052) then
begin
Randomize;
Songs[1].Init(path+'\DATA\msc\korol2.mp3');
Songs[1].Play(true);
Songs[1].SetVolume(30);
Songs[2].stop;
end;
end;

procedure PlayMusicMenu;
begin
Songs[1].Init(path+'\DATA\msc\menu.mp3');
Songs[1].Play(true);
Songs[1].SetVolume(100);
Songs[2].Stop;
Songs[3].Stop;
Songs[4].Stop;
Songs[5].Stop;
Songs[6].Stop;
end;

procedure PlayMusicTorg;
begin
Songs[1].Init(path+'\DATA\msc\rinok.mp3');
Songs[1].Play(true);
Songs[1].SetVolume(100);

Songs[2].Stop;
Songs[3].Stop;
Songs[4].Stop;
Songs[5].Stop;
Songs[6].Stop;
end;

procedure ProverkaMusic;
var
PlayerNew,PlayerNewGo,MonstersAll:Boolean;
GroundNew:integer;
i,j:Integer;
begin
PlayerNew:=Player.Plavaet;
PlayerNewGo:=Player.Go;
GroundNew:=Karta.map[round(Player.x/60),round(Player.y/60)];
//proverka fonovoy muziki
if Songs[1].PositionCurrent=integer(Songs[1].LongueurTotal) then
PlayMusicAll;
if ((Ground<>GroundNew) and (ground<>2) and (groundNew<>2))
or ((Ground<>GroundNew) and (ground=2) and (groundNew=7))
or ((Ground<>GroundNew) and (ground=7) and (groundNew=2)) then
PlayMusicAll;
//proverka plavaniya
if ( (Player.Plavaet=True) and (Songs[2].PositionCurrent=integer(Songs[2].LongueurTotal)) )
or ( (Player.Plavaet=True) and (PlayerNew<>PlayerStar) ) then
begin
Songs[2].Stop;
Songs[2].Init(path+'\DATA\msc\plavaniye.mp3');
Songs[2].Play(true);
Songs[4].Stop;
end;
//proverka hodbi po zemle
if ( (Player.Plavaet=False) and (Songs[2].PositionCurrent=integer(Songs[2].LongueurTotal)) )
or ( (Player.Plavaet=False) and (PlayerNew<>PlayerStar) ) then
begin
Songs[2].Stop;
Songs[2].Init(path+'\DATA\msc\priroda.mp3');
Songs[2].Play(true);
end;
//proverka na hozhdeniye
if ( (Player.Plavaet=False) and (Songs[4].PositionCurrent=integer(Songs[4].LongueurTotal)) and (Player.Go=true) )
or ( (Player.Plavaet=False) and (Player.Go=true) and (PlayerNew<>PlayerStar) )
or ( (Player.Plavaet=False) and (Player.Go=true) and (PlayerStarGo<>PlayerNewGo) ) then
begin
Songs[4].Stop;
Songs[4].Init(path+'\DATA\msc\hodba.mp3');
Songs[4].Play(true);
end;
//ostanovka hodbi
if Player.Go=False then Songs[4].Stop;
PlayerStar:=Player.plavaet;
PlayerStarGo:=Player.go;
//proverka na udar
if (Player.Fight=True) and (Player.ZaderzhkaUdara=0) then
begin
Songs[4].Stop;
if Player.Tip_oruzhiya='none' then Songs[4].Init(path+'\DATA\msc\udar.mp3');
if (Player.Tip_oruzhiya='nozh') or (Player.Tip_oruzhiya='mech') or (Player.Tip_oruzhiya='topor') then Songs[4].Init(path+'\DATA\msc\nozh.mp3');
if Player.Tip_oruzhiya='knut' then Songs[4].Init(path+'\DATA\msc\knut.mp3');
if (Player.Tip_oruzhiya='dubina') or (Player.Tip_oruzhiya='molot') or (Player.Tip_oruzhiya='bulava') then Songs[4].Init(path+'\DATA\msc\dubina.mp3');
if (Player.Tip_oruzhiya='luk') or (Player.Tip_oruzhiya='rogatka') or (Player.Tip_oruzhiya='arbalet') then Songs[4].Init(path+'\DATA\msc\strela.mp3');
Songs[4].Play(true);
end;
MonstersAll:=False;
//proverka na udar monstrov
for i:=Round(Player.x/60)-1 to Round(Player.x/60)+1 do
for j:=Round(Player.y/60)-1 to Round(Player.y/60)+1 do
Begin
if (Karta.monsters[i,j,1]>0) and (MonstersAll=false) and ( monsters[Karta.monsters[i,j,2]].Fight=true ) then
begin
Songs[5].Stop;
Songs[5].Init(path+'\DATA\msc\tvar'+inttostr(Karta.monsters[i,j,1])+'.mp3');
Songs[5].Play(true);
MonstersAll:=True;
end;
end;
if MonstersAll=False then Songs[5].Stop;
Ground:=GroundNew;
end;

Категория: Мультимедиа | Добавил: Armageddets (08.01.2013)
Просмотров: 2131 | Теги: Работа со звуком с помощью Bass.dll | Рейтинг: 0.0/0
Всего комментариев: 0
Добавлять комментарии могут только зарегистрированные пользователи.
[ Регистрация | Вход ]
Наш опрос
Уроки по созданию каких игр Вам интересны?
Всего ответов: 167
Мини-чат
Друзья сайта
  • Официальный блог
  • Сообщество uCoz
  • FAQ по системе
  • Инструкции для uCoz
  • Статистика

    Онлайн всего: 1
    Гостей: 1
    Пользователей: 0