add sounds

This commit is contained in:
2025-11-09 00:56:26 -05:00
parent a88f527dd4
commit 767ef44175
4 changed files with 45 additions and 3 deletions
+29
View File
@@ -1,5 +1,6 @@
#include <SFML/Graphics/RenderWindow.hpp>
#include <iostream>
#include <SFML/Audio.hpp>
#include "Game.h"
#include "MazeMap.h"
@@ -19,6 +20,31 @@ void Game::run() {
// Pellet data: 0=none, 1=pellet, 2=power
resources.loadMap("pelletMap", "assets/game/pellets.txt");
resources.loadSound("credit", "assets/sounds/credit.wav");
resources.loadSound("death_0", "assets/sounds/death_0.wav");
resources.loadSound("death_1", "assets/sounds/death_1.wav");
resources.loadSound("eat_dot_0", "assets/sounds/eat_dot_0.wav");
resources.loadSound("eat_dot_1", "assets/sounds/eat_dot_1.wav");
resources.loadSound("eat_fruit", "assets/sounds/eat_fruit.wav");
resources.loadSound("eat_ghost", "assets/sounds/eat_ghost.wav");
resources.loadSound("extend", "assets/sounds/extend.wav");
resources.loadSound("eyes", "assets/sounds/eyes.wav");
resources.loadSound("eyes_firstloop", "assets/sounds/eyes_firstloop.wav");
resources.loadSound("fright", "assets/sounds/fright.wav");
resources.loadSound("fright_firstloop", "assets/sounds/fright_firstloop.wav");
resources.loadSound("intermission.wav", "assets/sounds/intermission.wav");
resources.loadSound("siren0", "assets/sounds/siren0.wav");
resources.loadSound("siren0_firstloop", "assets/sounds/siren0_firstloop.wav");
resources.loadSound("siren1", "assets/sounds/siren1.wav");
resources.loadSound("siren1_firstloop", "assets/sounds/siren1_firstloop.wav");
resources.loadSound("siren2", "assets/sounds/siren2.wav");
resources.loadSound("siren2_firstloop", "assets/sounds/siren2_firstloop.wav");
resources.loadSound("siren3", "assets/sounds/siren3.wav");
resources.loadSound("siren3_firstloop", "assets/sounds/siren3_firstloop.wav");
resources.loadSound("siren4", "assets/sounds/siren4.wav");
resources.loadSound("siren4_firstloop", "assets/sounds/siren4_firstloop.wav");
resources.loadSound("start", "assets/sounds/start.wav");
// Texture layout: [Pellet Maze Image] + gap (16px) + [Base Maze Image]
// Original: 224px (28*8) + 4px gap at 8px tiles
// Scaled 4x: 896px (28*32) + 16px gap at 32px tiles
@@ -71,6 +97,9 @@ void Game::run() {
auto window = sf::RenderWindow(sf::VideoMode(windowRes), windowName);
window.setFramerateLimit(maxFPS);
sf::Sound sound(*resources.getSound("start"));
sound.play();
while (window.isOpen())
{
while (const std::optional event = window.pollEvent())
+8
View File
@@ -1,5 +1,6 @@
#include "ResourceManager.h"
#include "MazeMap.h"
#include <SFML/Audio/SoundBuffer.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/RenderTexture.hpp>
#include <SFML/Graphics/Sprite.hpp>
@@ -44,6 +45,13 @@ bool ResourceManager::loadMap(const std::string& mapName, const std::filesystem:
return !mapData.empty();
};
bool ResourceManager::loadSound(const std::string& soundName, const std::filesystem::path& soundPath) {
sounds[soundName] = sf::SoundBuffer(soundPath);
return true;
};
void ResourceManager::resizeTexture(const std::string& textureName, unsigned int newTextureTileSize) {
auto it = textures.find(textureName);
if (it == textures.end()) return;
+7 -2
View File
@@ -1,6 +1,7 @@
#ifndef RESOURCEMANAGER_H
#define RESOURCEMANAGER_H
#include <SFML/Audio/SoundBuffer.hpp>
#include <SFML/Graphics/Font.hpp>
#include <map>
#include <vector>
@@ -22,7 +23,7 @@ public:
bool loadMap(const std::string& mapName, const std::filesystem::path& mapPath);
//bool loadSound(const std::filesystem::path& soundPath);
bool loadSound(const std::string& soundName, const std::filesystem::path& soundPath);
sf::Texture& getTexture(const std::string& textureName) {
return *textures[textureName];
@@ -38,6 +39,10 @@ public:
return pelletMap;
}
sf::SoundBuffer* getSound(const std::string& soundName) {
return &sounds[soundName];
};
//load gameplay info
private:
@@ -49,7 +54,7 @@ private:
std::map<std::string, sf::Font> fonts;
//sounds
//std::map<std::string, sf::SoundBuffer> sounds;
std::map<std::string, sf::SoundBuffer> sounds;
//map
std::vector<int> mazeMap;