summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2022-03-11 15:33:28 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2022-03-11 15:33:28 -0500
commit6cfc54f019ea793c75c012af9c8249eac936cfac (patch)
treef19eed64e9b284136f3b802d4dee71ee24978646 /src
parent456122f5f0086ed0dbe1b784266b96e9624aa8e1 (diff)
downloadether-6cfc54f019ea793c75c012af9c8249eac936cfac.tar.gz
ether-6cfc54f019ea793c75c012af9c8249eac936cfac.tar.bz2
ether-6cfc54f019ea793c75c012af9c8249eac936cfac.zip
Added music and lamp popping sound
Diffstat (limited to 'src')
-rw-r--r--src/game.h2
-rw-r--r--src/main.cpp19
-rw-r--r--src/muxer.cpp70
-rw-r--r--src/muxer.h35
4 files changed, 126 insertions, 0 deletions
diff --git a/src/game.h b/src/game.h index 200b691..f0385ee 100644 --- a/src/game.h +++ b/src/game.h
@@ -6,6 +6,7 @@
6#include <random> 6#include <random>
7#include <list> 7#include <list>
8#include "map.h" 8#include "map.h"
9#include "muxer.h"
9 10
10const int GAME_WIDTH = 640*2; 11const int GAME_WIDTH = 640*2;
11const int GAME_HEIGHT = 480*2; 12const int GAME_HEIGHT = 480*2;
@@ -80,6 +81,7 @@ public:
80 } 81 }
81 82
82 std::mt19937& rng; 83 std::mt19937& rng;
84 Muxer muxer;
83 85
84 Map<MapData> map; 86 Map<MapData> map;
85 std::list<Kickup> kickups; 87 std::list<Kickup> kickups;
diff --git a/src/main.cpp b/src/main.cpp index 4b13051..25da94f 100644 --- a/src/main.cpp +++ b/src/main.cpp
@@ -13,6 +13,10 @@ void incrementIfSet(Game& game, int& count, int x, int y, Tile val = Tile::Wall)
13 } 13 }
14} 14}
15 15
16int getZoomLevel(const Game& game) {
17 return (game.curZoom - INIT_ZOOM) / 2;
18}
19
16void tick( 20void tick(
17 Game& game, 21 Game& game,
18 int x1, 22 int x1,
@@ -96,11 +100,14 @@ bool movePlayer(Game& game, int x, int y)
96 100
97 game.player_x = x; 101 game.player_x = x;
98 game.player_y = y; 102 game.player_y = y;
103 game.muxer.setPlayerLoc(x, y);
99 104
100 game.dirtyLighting = true; 105 game.dirtyLighting = true;
101 106
102 return true; 107 return true;
103 } else { 108 } else {
109 //game.muxer.playSoundAtPosition("bump", game.player_x, game.player_y);
110
104 return false; 111 return false;
105 } 112 }
106} 113}
@@ -241,6 +248,8 @@ void kickUpDust(Game& game, int x, int y, size_t chain)
241 248
242void popLamp(Game& game, int x, int y, size_t chain) 249void popLamp(Game& game, int x, int y, size_t chain)
243{ 250{
251 game.muxer.playSoundAtPosition("pop", x, y);
252
244 if (game.map.at(x,y).tile == Tile::Lamp) 253 if (game.map.at(x,y).tile == Tile::Lamp)
245 { 254 {
246 game.numLamps--; 255 game.numLamps--;
@@ -400,6 +409,15 @@ void setZoom(Game& game, size_t zoom)
400 { 409 {
401 game.curBoundY = game.map.getBottom() - zoom * ZOOM_Y_FACTOR; 410 game.curBoundY = game.map.getBottom() - zoom * ZOOM_Y_FACTOR;
402 } 411 }
412
413 int zoomLevel = getZoomLevel(game);
414 if (zoomLevel == 0) {
415 game.muxer.setMusicLevel(0);
416 } else if (zoomLevel < 3) {
417 game.muxer.setMusicLevel(1);
418 } else {
419 game.muxer.setMusicLevel(2);
420 }
403} 421}
404 422
405int main(int, char**) 423int main(int, char**)
@@ -731,6 +749,7 @@ int main(int, char**)
731 zoomAcc -= zoomDt; 749 zoomAcc -= zoomDt;
732 } 750 }
733 751
752 game.muxer.update();
734 renderer.render(game, true); 753 renderer.render(game, true);
735 } 754 }
736 } catch (const sdl_error& ex) 755 } catch (const sdl_error& ex)
diff --git a/src/muxer.cpp b/src/muxer.cpp new file mode 100644 index 0000000..5b09ef8 --- /dev/null +++ b/src/muxer.cpp
@@ -0,0 +1,70 @@
1#include "muxer.h"
2#include <iostream>
3#include <fmod_errors.h>
4
5void ERRCHECK_fn(FMOD_RESULT result, const char* file, int line) {
6 if (result != FMOD_OK) {
7 std::cout << file << "(" << line << "): FMOD error " << result << " - " << FMOD_ErrorString(result);
8 abort();
9 }
10}
11
12#define ERRCHECK(_result) ERRCHECK_fn(_result, __FILE__, __LINE__)
13
14Muxer::Muxer() {
15 FMOD::Studio::System* system_holder = nullptr;
16 ERRCHECK(FMOD::Studio::System::create(&system_holder));
17 system_.reset(system_holder);
18
19 FMOD::System* coreSystem = nullptr;
20 ERRCHECK(system_->getCoreSystem(&coreSystem));
21 ERRCHECK(coreSystem->setSoftwareFormat(0, FMOD_SPEAKERMODE_5POINT1, 0));
22 ERRCHECK(system_->initialize(1024, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, nullptr));
23
24 FMOD::Studio::Bank* masterBank = nullptr;
25 ERRCHECK(system_->loadBankFile("../res/fmod/Build/Desktop/Master Bank.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &masterBank));
26
27 FMOD::Studio::Bank* stringsBank = nullptr;
28 ERRCHECK(system_->loadBankFile("../res/fmod/Build/Desktop/Master Bank.strings.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &stringsBank));
29
30 FMOD::Studio::EventDescription* exploration_desc = nullptr;
31 ERRCHECK(system_->getEvent("event:/exploration", &exploration_desc));
32 ERRCHECK(exploration_desc->createInstance(&exploration_event_));
33 ERRCHECK(exploration_event_->start());
34}
35
36void Muxer::setPlayerLoc(int x, int y) {
37 FMOD_3D_ATTRIBUTES attributes = {{0}};
38 attributes.forward.z = 1.0f;
39 attributes.up.y = 1.0f;
40 attributes.position.x = x;
41 attributes.position.y = y;
42 ERRCHECK(system_->setListenerAttributes(0, &attributes));
43}
44
45void Muxer::playSoundAtPosition(std::string name, float x, float y) {
46 std::string eventPath = std::string("event:/") + name;
47
48 FMOD::Studio::EventDescription* eventDescription = nullptr;
49 ERRCHECK(system_->getEvent(eventPath.c_str(), &eventDescription));
50
51 FMOD::Studio::EventInstance* eventInstance = nullptr;
52 ERRCHECK(eventDescription->createInstance(&eventInstance));
53
54 FMOD_3D_ATTRIBUTES attributes = {{0}};
55 attributes.forward.z = 1.0f;
56 attributes.up.y = 1.0f;
57 attributes.position.x = x;
58 attributes.position.y = y;
59 ERRCHECK(eventInstance->set3DAttributes(&attributes));
60 ERRCHECK(eventInstance->start());
61 ERRCHECK(eventInstance->release());
62}
63
64void Muxer::setMusicLevel(int level) {
65 ERRCHECK(exploration_event_->setParameterByName("level", level));
66}
67
68void Muxer::update() {
69 ERRCHECK(system_->update());
70}
diff --git a/src/muxer.h b/src/muxer.h new file mode 100644 index 0000000..f99cce4 --- /dev/null +++ b/src/muxer.h
@@ -0,0 +1,35 @@
1#ifndef MUXER_H_3146C802
2#define MUXER_H_3146C802
3
4#include <memory>
5#include <string>
6#include <fmod_studio_common.h>
7#include <fmod_studio.hpp>
8
9class fmod_system_deleter {
10public:
11 void operator()(FMOD::Studio::System* val) {
12 val->release();
13 }
14};
15
16using fmod_system_ptr = std::unique_ptr<FMOD::Studio::System, fmod_system_deleter>;
17
18class Muxer {
19public:
20 Muxer();
21
22 void setPlayerLoc(int x, int y);
23
24 void playSoundAtPosition(std::string name, float x, float y);
25
26 void setMusicLevel(int level);
27
28 void update();
29
30private:
31 fmod_system_ptr system_;
32 FMOD::Studio::EventInstance* exploration_event_;
33};
34
35#endif /* end of include guard: MUXER_H_3146C802 */