Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

109 Neutral

About Pacman18

  • Rank
  1. Pacman18

    SDL_Mixer can't open wav

    sorry, it said "couldn't open test.wav"
  2. Pacman18

    SDL_Mixer can't open wav

    it kept saying the printf error - ( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() );   I tried an mp3 instead (which required I also put smpeg2.dll in the directory) and it worked, which as I say is better for me anyway
  3. Pacman18

    SDL_Mixer can't open wav

    Nevermind, it works with mp3 which I prefer anyway
  4. hi guys,   I've been following a tutorial on playing music in C++ with sdl_mixer, the program builds fine but when run I always get the error that the music couldn't load. I have copied test.wav into the project directory, is there something I am missing? Any help is appreciated #include <iostream> #include <SDL.h> #include <SDL_mixer.h> #include <stdio.h> #include <string> Mix_Music *gMusic = NULL; Mix_Chunk *gScratch = NULL; Mix_Chunk *gHigh = NULL; Mix_Chunk *gMedium = NULL; Mix_Chunk *gLow = NULL; bool loadMedia(); int main( int argc, char *argv[] ) { loadMedia(); Mix_PlayMusic( gMusic, -1 ); int a; std::cin >> a; return 0; } bool loadMedia() { bool success = true; if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 ) { printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() ); success = false; } gMusic = Mix_LoadMUS( "test.wav" ); if( gMusic == NULL ) { printf( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() ); success = false; } }
  5. Pacman18

    C++ design advice

    wow thanks guys, I knew I must of been going about it the wrong way. I'm going to create another class to handle where the player is and review the gamestate idea.   thanks a lot, no doubt i'll be back with another question later as I re-do the code!
  6. Pacman18

    C++ design advice

    thanks a lot, no rush. I'll be grateful for any examples you may provide!
  7. Pacman18

    C++ design advice

    hi guys,   I've been learning to program for about 2 months now, with C++11 from Bjarne Stroustrup's "The C++ language" book.   I've read the section covering basic facilities, variables, containers etc. I'm now reading about the abstraction mechanisms and classes and I think I understand them, however I have trouble figuring out how best to use them to write good code. Since I'm an absolute basic beginner I have just been using console apps to practice, for classes practice I decided to try and write a text based rpg like game with a few rooms just to test. I'm realising that learning the syntax is easy but the hard part of programming is design.   I was wondering if I could get some advice on the best way to use classes to make such a game, or any game/program really so that it is easily extendable without modifying the classes too much. In my program so far I've made some classes and functions to handle a waiting prompt, the setup of a new area etc, but when I come to write the room in the main cpp file, it just seems wrong and a weird way to go about it. Any advice is appreciated, below is my code example ;   header file ; #include <iostream> #include <string> #include <vector> #include <windows.h> #define TITLE "\tTest RPG\n\t---------\n\n\n" #define PROMPT "\n> " void wait(); void setupareas(); void bunker(); void cafe(); void wait() { print("\n\n\n1. Back\n\n\n> "); char c; std::cin >> c; } class area { public: short m_seen = 0; std::string m_name; std::string m_description; std::vector<std::string> m_menu1; std::vector<std::string> m_menu2; void setname(std::string name); void setdescription(std::string description); void presetmenu(std::vector<std::string> menu); void postsetmenu(std::vector<std::string> menu); void printmenu1(); void printmenu2(); void printdescription(); } ; void area::setname(std::string name) { m_name = name; } void area::setdescription(std::string description) { m_description = description; } void area::presetmenu(std::vector<std::string> menu) { for (auto i : menu) { m_menu1.push_back(i); } } void area::postsetmenu(std::vector<std::string> menu) { for (auto i : menu) { m_menu2.push_back(i); } } void area::printmenu1() { std::cout << TITLE; print(m_name); std::cout << std::endl << std::endl; for (auto i : m_menu1) { print(i); std::cout << std::endl << std::endl; } } void area::printmenu2() { std::cout << TITLE; print(m_name); std::cout << std::endl << std::endl; for (auto i : m_menu2) { print(i); std::cout << std::endl << std::endl; } } void area::printdescription() { m_seen = 1; char wait; system("cls"); print(m_description); print("\n\n\n1. Back\n\n"); print(PROMPT); std::cin >> wait; } Then the main.cpp file where I 'setup' the rooms and run the game #include "head.h" area bunker; area cafe; using namespace std; int main(void) { setupareas(); bunker(); return 0; } void setupareas() { bunker.setname("Bunker\n_________"); bunker.setdescription("You are in the bunker"); vector<string> temp {"1.Look Around", "2. Go North", "3. Go South"}; bunker.presetmenu(temp); temp = {"1.Look Around", "2. Go North", "3. Go South", "4. Examine poster"}; bunker.postsetmenu(temp); cafe.setname("Cafe\n_________"); cafe.setdescription("You are in the cafe"); temp = {"1.Look Around", "2. Go South"}; cafe.presetmenu(temp); temp = {"1.Look Around", "2. Go South", "3. Speak with coffee lady", "4. Speak with worker"}; cafe.postsetmenu(temp); } void bunker() { bool here = true; while (here) { system("cls"); if (bunker.m_seen == 0) { bunker.printmenu1(); } else { bunker.printmenu2(); } print(PROMPT); char choice; cin >> choice; switch(choice) { case '1': bunker.printdescription(); break; case '2': cafe(); break; case '3': break; case '4': system("cls"); print("Poster"); wait(); break; } } } void cafe() { bool here = true; while (here) { system("cls"); if (cafe.m_seen == 0) { cafe.printmenu1(); } else { cafe.printmenu2(); } print(PROMPT); char choice; cin >> choice; switch(choice) { case '1': cafe.printdescription(); break; case '2': bunker(); break; case '3': system("cls"); print("lady"); wait(); break; case '4': system("cls"); print("worker"); wait(); break; } } }
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!