Skip to content

Commit

Permalink
Load music filenames from maps.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit-n committed Dec 22, 2015
1 parent a6668ff commit 9185d76
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 15 deletions.
1 change: 1 addition & 0 deletions data/map0.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<map version="1.0" orientation="orthogonal" width="192" height="64" tilewidth="16" tileheight="16">
<properties>
<property name="backgroundyoff" value="61"/>
<property name="music" value="groove_grove.ogg"/>
<property name="startingupgrades" value="0"/>
</properties>
<tileset firstgid="1" name="set01" tilewidth="16" tileheight="16">
Expand Down
1 change: 1 addition & 0 deletions data/map1.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<properties>
<property name="backgroundyoff" value="61"/>
<property name="startingupgrades" value="8"/>
<property name="music" value="groove_grove.ogg"/>
</properties>
<tileset firstgid="1" name="set01" tilewidth="16" tileheight="16">
<image source="tilesets/tile1.png" trans="ff00ff" width="512" height="512"/>
Expand Down
1 change: 1 addition & 0 deletions data/map2.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<property name="startingammo" value="2"/>
<property name="startingupgrades" value="12"/>
<property name="timetosniper" value="15"/>
<property name="music" value="brittle_rille.ogg"/>
</properties>
<tileset firstgid="1" name="set1" tilewidth="16" tileheight="16">
<image source="tilesets/tile1.png" width="512" height="512"/>
Expand Down
1 change: 1 addition & 0 deletions data/map3.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<property name="startingammo" value="3"/>
<property name="startingupgrades" value="16"/>
<property name="timetosniper" value="15"/>
<property name="music" value="ultralounge.ogg"/>
</properties>
<tileset firstgid="1" name="set1" tilewidth="16" tileheight="16">
<image source="tilesets/tile1.png" width="512" height="512"/>
Expand Down
6 changes: 4 additions & 2 deletions loadingmapstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ along with Clonepoint. If not, see <http://www.gnu.org/licenses/>.
LoadingMapState::LoadingMapState(StateManager* sm) : BaseState(sm)
{
_mapFilename = "";
_mapMusicFilename = "";
_timer = 0;
_loaded = false;
}
Expand All @@ -38,7 +39,7 @@ void LoadingMapState::update(unsigned int dT)
{
_manager->initSceneAndMap(_mapFilename.c_str());
_manager->makeStartSave();
Locator::getAudio()->playMusic("groove_grove.ogg");
Locator::getAudio()->playMusic(_mapMusicFilename);
_loaded = true;
}

Expand All @@ -55,9 +56,10 @@ void LoadingMapState::handleKeyUp(SDL_Keycode){}
void LoadingMapState::handleMouseDown(SDL_MouseButtonEvent event){}
void LoadingMapState::handleMouseUp(SDL_MouseButtonEvent event){}

void LoadingMapState::setMap(std::string mapFilename)
void LoadingMapState::setMap(std::string mapFilename, std::string musicFilename)
{
_mapFilename = mapFilename;
_mapMusicFilename = musicFilename;
_timer = 0;
_loaded = false;
}
3 changes: 2 additions & 1 deletion loadingmapstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class LoadingMapState : public BaseState
void handleKeyUp(SDL_Keycode);
void handleMouseDown(SDL_MouseButtonEvent event);
void handleMouseUp(SDL_MouseButtonEvent event);
void setMap(std::string mapFilename);
void setMap(std::string mapFilename, std::string musicFilename);
private:
std::string _mapFilename;
std::string _mapMusicFilename;
unsigned int _timer;
bool _loaded;
};
Expand Down
22 changes: 11 additions & 11 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,33 @@ Credits:
- https://www.freesound.org/people/fastson/sounds/50618/
- CC BY 3.0 http://creativecommons.org/licenses/by/3.0/
- Beginning and end of wav file cut with Audacity

2. menu_click.wav
- By dklon
- http://opengameart.org/content/quick-zap
- CC BY 3.0 http://creativecommons.org/licenses/by/3.0/

3. switch.wav
- By ecfike
- http://freesound.org/people/ecfike/sounds/128919/
- CC0 http://creativecommons.org/publicdomain/zero/1.0/

4. enter_crosslink.wav, exit_crosslink.wav, jump.wav, circuitbox.wav
- By Circlerun
- http://opengameart.org/content/hi-tech-button-sound-pack-i-non-themed
- CC0 http://creativecommons.org/publicdomain/zero/1.0/

5. punch1.wav, punch2.wav
- By scarbelly25
- https://www.freesound.org/people/scarbelly25/sounds/35409/
- CC0 http://creativecommons.org/publicdomain/zero/1.0/

6. glass_break.wav
- By cmusounddesign
- http://freesound.org/people/cmusounddesign/sounds/84536/
- CC BY 3.0 http://creativecommons.org/licenses/by/3.0/
- Beginning and end of wav file cut and used Noise Removal tool with Audacity

7. pistol_ready.wav
- By Fr3yr
- https://www.freesound.org/people/Fr3yr/sounds/100804/
Expand All @@ -76,12 +76,12 @@ Credits:
- https://www.freesound.org/people/pempi/sounds/33873/
- CC BY 3.0 http://creativecommons.org/licenses/by/3.0/
- Both sounds cut out and faded with Audacity

10. alarm.wav
- By hypocore
- http://freesound.org/people/hypocore/sounds/164090/
- CC0 http://creativecommons.org/publicdomain/zero/1.0/

11. link.wav
- By NoiseCollector
- https://www.freesound.org/people/NoiseCollector/sounds/41610/
Expand All @@ -100,12 +100,12 @@ Credits:
- http://opengameart.org/content/netslash-tiles
- CC BY 3.0 http://creativecommons.org/licenses/by/3.0/
- Taken from tileset_office.png and darkened

2. Collision Tiles
- By Eris
- http://opengameart.org/content/sci-fi-platform-tiles
- CC0 http://creativecommons.org/publicdomain/zero/1.0/

3. Wall Tiles 1
- By RodlenJack
- http://opengameart.org/content/crimelike-spritetile-set
Expand All @@ -126,7 +126,7 @@ Credits:
- CC0 http://creativecommons.org/publicdomain/zero/1.0/

Music
1. groove_grove.ogg
1. groove_grove.ogg, brittle_rille.ogg, ultralounge.ogg
- By Kevin MacLeod
- incompetech.com
- CC BY 3.0 http://creativecommons.org/licenses/by/3.0/
Expand Down
41 changes: 40 additions & 1 deletion statemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ StateManager::StateManager()
_winY = 600;
_settingsChanged = false;
_activeMapFilename = "";
_mapMusicFilename = "";
}

StateManager::~StateManager()
Expand Down Expand Up @@ -108,7 +109,8 @@ void StateManager::switchToState(eState state)
_activeState = _pauseState;
break;
case LOADINGMAP_SCREEN:
lms->setMap(_activeMapFilename);
getMusicFilename(_activeMapFilename);
lms->setMap(_activeMapFilename, _mapMusicFilename);
_activeState = _loadingMapState;
break;
case LOADMAP_SCREEN:
Expand Down Expand Up @@ -172,6 +174,7 @@ void StateManager::update(unsigned int dT)
void StateManager::setActiveMapFilename(std::string filename)
{
_activeMapFilename = filename;
_mapMusicFilename = "";
}

void StateManager::getMapVariables(std::string filename, int* money, int* upgrades, unsigned int* bullets, int* timeToSniper, unsigned int* energy)
Expand Down Expand Up @@ -236,6 +239,42 @@ void StateManager::getMapVariables(std::string filename, int* money, int* upgrad
}
}

void StateManager::getMusicFilename(std::string mapFilename)
{
TiXmlDocument doc(mapFilename.c_str());

if (!doc.LoadFile())
{
LOGF((stderr, "Failed to load map file %s.\n", mapFilename.c_str()));
return;
}

TiXmlHandle hDoc(&doc);
TiXmlElement *root, *lvl1, *lvl2;
root = doc.FirstChildElement("map");

if(!root)
{
LOGF((stderr, "Failed to parse map file %s.\n", mapFilename.c_str()));
return;
}

lvl1 = root->FirstChildElement("properties");
while(lvl1)
{
lvl2 = lvl1->FirstChildElement("property");
while (lvl2)
{
if (!strcmp(lvl2->Attribute("name"), "music"))
{
_mapMusicFilename = std::string(lvl2->Attribute("value"));
}
lvl2 = lvl2->NextSiblingElement("property");
}
lvl1 = lvl1->NextSiblingElement("properties");
}
}

int StateManager::getWindowWidth()
{
return _winX;
Expand Down
2 changes: 2 additions & 0 deletions statemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class StateManager
void setWindowDims(int w, int h);
void setActiveMapFilename(std::string filename);
void getMapVariables(std::string filename, int* money, int* upgrades, unsigned int* bullets, int* timeToSniper, unsigned int* energy);
void getMusicFilename(std::string mapFilename);
int getWindowWidth();
int getWindowHeight();
void makeStartSave();
Expand All @@ -72,6 +73,7 @@ class StateManager
BaseState* _upgradesState;
bool _settingsChanged;
std::string _activeMapFilename;
std::string _mapMusicFilename;
int _winX;
int _winY;
};
Expand Down

0 comments on commit 9185d76

Please sign in to comment.