00001 #include "Command.h" 00002 #include "Level.h" 00003 #include "List.h" 00004 00005 using namespace std; 00006 00007 const std::string PlaySoundCommand::_id = "playSound"; 00008 00009 PlaySoundCommand::PlaySoundCommand( std::string filename ) 00010 : _filename( filename ) 00011 { 00012 Level::instance()->loadSound( _filename ); 00013 } 00014 00015 PlaySoundCommand::PlaySoundCommand(List *command) 00016 { 00017 command = command->rest(); 00018 _filename = command->firstString(); 00019 00020 Level::instance()->loadSound( _filename ); 00021 } 00022 void PlaySoundCommand::execute() 00023 { 00024 // Play sound on next available channel 00025 Mix_PlayChannel(-1, Level::instance()->getSound( _filename ), 0 ); 00026 } 00027 00028 std::string PlaySoundCommand::getString() 00029 { 00030 List *command = new List(); 00031 command->snoc(new Atom(_id)); 00032 command->snoc( new Atom( _filename ) ); 00033 string commandString = command->getString(); 00034 delete command; 00035 00036 return commandString; 00037 }