zengine/test/ZSoundTest.cpp

111 lines
3.8 KiB
C++
Raw Normal View History

2002-11-21 05:40:49 +00:00
/*******************************************************************************
2002-12-29 06:50:19 +00:00
This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk
2002-11-21 05:40:49 +00:00
2003-07-10 20:45:39 +00:00
ZEngine is Licensed under a BSD-style license.
This example file is in the public domain, it may be used with no restrictions.
2002-11-21 05:40:49 +00:00
2002-12-29 06:50:19 +00:00
The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net
2002-11-21 05:40:49 +00:00
*******************************************************************************/
2003-10-05 19:20:52 +00:00
/*$Id: ZSoundTest.cpp,v 1.18 2003/10/05 19:20:52 cozman Exp $*/
2003-01-04 05:17:56 +00:00
2002-11-21 05:40:49 +00:00
#include <ZEngine.h>
#include <string>
using namespace std;
using namespace ZE;
bool Initialize()
2002-11-21 05:40:49 +00:00
{
ZEngine *engine = ZEngine::GetInstance();
ZConfigFile cfg("tests.zcf");
2003-01-04 05:16:01 +00:00
int w,h,bpp,rate;
2002-11-21 05:40:49 +00:00
bool fs;
2003-06-11 05:51:15 +00:00
std::string title;
2002-11-21 05:40:49 +00:00
w = cfg.GetInt("ZSoundTest","width",800);
h = cfg.GetInt("ZSoundTest","height",600);
bpp = cfg.GetInt("ZSoundTest","bpp",32);
fs = cfg.GetBool("ZSoundTest","fullscreen",false);
title = cfg.GetString("ZSoundTest","title","ZSound Test");
2003-01-04 05:16:01 +00:00
rate = cfg.GetInt("ZSoundTest","framerate",60);
2002-11-21 05:40:49 +00:00
engine->SetupDisplay(w,h,bpp,fs);
2003-01-04 05:16:01 +00:00
engine->SetDesiredFramerate(rate);
return engine->CreateDisplay(title);
2002-11-21 05:40:49 +00:00
}
void Test()
{
ZEngine *engine = ZEngine::GetInstance();
2003-06-11 05:51:15 +00:00
std::string name[5] = { "monkey", "rooster", "kick", "carcrash", "whip" };
2002-11-21 05:40:49 +00:00
ZSound sample[5];
ZFont font("data/almontew.ttf",48);
ZImage text[6];
int sampleNum = 0;
for(int i=0; i < 4; i++)
sample[i].OpenFromZip("data/data.zip",FormatStr("%s.wav",name[i].c_str()));
2003-10-05 19:20:52 +00:00
sample[4].Open("data/whip.wav");
2002-11-21 05:40:49 +00:00
font.DrawText("(P)ause\t(U)npause",text[0]);
font.DrawText("(F)ade Out\t(H)alt\t",text[1]);
font.DrawText("Space - Play\t Up/Down - Control Volume",text[2]);
2003-07-10 23:30:05 +00:00
font.DrawText("1-5 Change Sample Being Controlled",text[3]);
2002-11-21 05:40:49 +00:00
do
{
//In the active loop, check events first//
engine->CheckEvents();
if(engine->IsActive())
{
if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit();
if(engine->KeyIsPressed(SDLK_1))
sampleNum = 0;
if(engine->KeyIsPressed(SDLK_2))
sampleNum = 1;
if(engine->KeyIsPressed(SDLK_3))
sampleNum = 2;
if(engine->KeyIsPressed(SDLK_4))
sampleNum = 3;
if(engine->KeyIsPressed(SDLK_5))
sampleNum = 4;
if(engine->KeyIsPressed(SDLK_p))
sample[sampleNum].Pause();
if(engine->KeyIsPressed(SDLK_u))
sample[sampleNum].Unpause();
if(engine->KeyIsPressed(SDLK_f))
sample[sampleNum].Stop(5000);
if(engine->KeyIsPressed(SDLK_h))
sample[sampleNum].Stop();
if(engine->KeyIsPressed(SDLK_SPACE))
sample[sampleNum].Play();
if(engine->KeyIsPressed(SDLK_UP))
sample[sampleNum].SetVolume(sample[sampleNum].Volume()+1);
if(engine->KeyIsPressed(SDLK_DOWN))
sample[sampleNum].SetVolume(sample[sampleNum].Volume()-1);
font.DrawText(FormatStr("Volume: %d",sample[sampleNum].Volume()),text[4]);
font.DrawText(FormatStr("Sample: %s",name[sampleNum].c_str()),text[5]);
engine->Clear(); //clear screen
for(int i=0; i < 6; i++)
text[i].Draw(0,i*50);
engine->Update(); //update the screen
}
2002-11-21 05:40:49 +00:00
} while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
}
int main(int argc, char *argv[])
2002-11-21 05:40:49 +00:00
{
if(Initialize())
Test();
ZEngine::ReleaseInstance();
2002-11-21 05:40:49 +00:00
return 0;
}