Sound in 2d game

I am looking to use sound effects in my game which in c++

I am not sure how to do this is it similar to the way you load in images or have I got to do something different.

this is how I am loading my images

sf::Image backGround;
      if(!backGround.LoadFromFile("images/backGrnd2.jpg")) std::cout<<"File not found background.jpg"<<std::endl;
tango2009Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pgnatyukCommented:
Seems like you are talking about Windows.
So:
#include
PlaySound("coolSound.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);

If it will be needed, add these lines after #include:
#define SND_FILENAME 0x20000
#define SND_LOOP 8
#define SND_ASYNC 1

This function in MSDN:
http://msdn.microsoft.com/en-us/library/ms712879

Here is it's all wrapped in classes:
http://www.ucancode.net/Visual_C_MFC_Example/Record-Play-Save-Wave-file-vc-example.htm

Or with DirectSound:
http://www.codeproject.com/KB/audio-video/dxsnd.aspx

0
tango2009Author Commented:
What should I define playsound as it is flagging this as an error as an undeclared identifier
0
pgnatyukCommented:
Show the error.
It's defined in mmsystem.h. So you can include this file.
Or define it:

#define SND_FILENAME 0x20000
#define SND_LOOP 8
#define SND_ASYNC 1
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

tango2009Author Commented:
This is the error

mainscroller.cpp(37) : error C3861: 'PlaySound': identifier not found

This is my code for playsound

PlaySound("sounds/explosion1.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);

and I have added this to my code already

#define SND_FILENAME 0x20000
#define SND_LOOP 8
#define SND_ASYNC 1
0
pgnatyukCommented:
I hope you have
#define WIN32_LEAN_AND_MEAN
#include
in your code.

MSDN:
http://msdn.microsoft.com/en-us/library/ms712879.aspx

Next question maybe about this lib: Winmm.lib
You can add it to your project settings or with pragme
#pragma comment(lib, "Winmm.lib")

About the headers:
http://msdn.microsoft.com/en-us/library/aa383745.aspx
0
pgnatyukCommented:
sndPlaySound exists:
http://msdn.microsoft.com/en-us/library/dd798676(VS.85).aspx

You can test it.

0
pgnatyukCommented:
The attached function should work for you
#include <Windows.h>
#include <Mmsystem.h>
#pragma once(lib, Winmm.lib)

void PlayWav(HINSTANCE hinstance)
{
	PlaySound((LPCSTR)IDR_SELECT, hinstance, SND_ASYNC | SND_RESOURCE);
}

Open in new window

0
pgnatyukCommented:
Sorry. In the previous code should be #pragma comment(lib, "winmm.lib")
0
tango2009Author Commented:
how do you add it to your project settings?

This is what I have defined so far

#include <windows.h>
#define SND_FILENAME 0x20000
#define SND_LOOP 8
#define SND_ASYNC 1
#define WIN32_LEAN_AND_MEAN
#define NTDDI_VISTA (0x06000000)
#pragma comment(lib, "Winmm.lib")
0
pgnatyukCommented:
it can be so:
#define WIN32_LEAN_AND_MEAN
#include
#include
#pragma comment(lib, "Winmm.lib")

without the changes in the project settings.
0
tango2009Author Commented:
I have been adding this into my main but I have these errors

mainscroller.cpp(46) : error C2601: 'PlayWav' : local function definitions are illegal

mainscroller.cpp(49) : error C2664: 'PlaySoundW' : cannot convert parameter 1 from 'const char [22]' to 'LPCWSTR'

mainscroller.cpp(47) : error C2065: 'IDR_SELECT' : undeclared identifier

This is my main below
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include <sstream>
#include "ScrollSprite.h"
#include "Scroller.h"
#include "AnimatedSprite.h"
#include "powerupScroller.h"
#include "Scrollpower.h"
#include "Explosion.h"
#include <time.h>
#include <windows.h>
#define SND_FILENAME 0x20000
#define SND_LOOP 8
#define SND_ASYNC 1
#define WIN32_LEAN_AND_MEAN
#define NTDDI_VISTA (0x06000000)
#pragma comment(lib, "Winmm.lib")
#include <Mmsystem.h>


using std::endl;


int main()
{

	//initialisation - lots of this code could be put into functions for 
	//neatness and separation of concerns. You need to declare objects here to draw them
	//but the set up for those objects could be done in a function or a class

	//window dimensions 
	unsigned int width=600;
	unsigned int height=480;
	
	//we need a timer to update things - get a clock
	sf::Clock clock;
	static float timeAccumulator=0.0;
    
	//load resources for the scroller - images and sounds (if you have any)	
	sf::Image backGround;
	if(!backGround.LoadFromFile("images/backGrnd2.jpg")) std::cout<<"File not found background.jpg"<<std::endl;


void PlayWav(HINSTANCE hinstance)
{
        PlaySound((LPCSTR)IDR_SELECT, hinstance, SND_ASYNC | SND_RESOURCE);
}
   PlaySound("sounds/explosion1.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC); 

    sf::Image gameover;
	if(!gameover.LoadFromFile("images/gameover.jpg")) std::cout<<"File not found gameover.jpg"<<std::endl;

    sf::Image title;
	if(!title.LoadFromFile("images/title.png")) std::cout<<"File not found title.jpg"<<std::endl;
	
	sf::Image aScroll;	
	if(!aScroll.LoadFromFile("images/rock.png")) std::cout<<"File not found rock.png"<<std::endl;

    sf::Image bScroll;	
	if(!bScroll.LoadFromFile("images/navalmine.png")) std::cout<<"File not found navalmine.png"<<std::endl;

    sf::Image cScroll;	
	if(!cScroll.LoadFromFile("images/barrel.png")) std::cout<<"File not found barrel.png"<<std::endl;

    sf::Image dScroll;	
	if(!dScroll.LoadFromFile("images/ship.png")) std::cout<<"File not found ship.png"<<std::endl;

    sf::Image aNimat;	
	if(!aNimat.LoadFromFile("images/sub.png")) std::cout<<"File not found sub.png"<<std::endl;

	sf::Image expo;
	if(!expo.LoadFromFile("images/explosion.png")) std::cout<<"File not found explosion.png"<<std::endl;

	//resouces loaded
    int level = 0;
	int lives = 0;
   

   	AnimatedSprite anim(aNimat,Vector2f(0,-50),Vector2f(5,1),0,Color(255,255,255,255),9,5);
	
	//resouces loaded
	anim.Scale(3,3);
	
    int scrollPosMax = 2000;
    int vertPosMax = 300;

    srand ( time(NULL) );


   
	anim.setInterval(1.05);
	anim.Move(200,200);
    
	
	sf::Sprite backGndSprite(backGround);
	backGndSprite.Scale(0.75f,0.8f);

    sf::Sprite screen(title);
	screen.Scale(0.75f,0.8f);

    sf::Sprite game(gameover);
	game.Scale(0.75f,0.8f);


    /*int left1, left2;
	int right1, right2;
	int top1, top2;
	int bottom1, bottom2;

	left1 = Vector2f->x;
	left2 = object2->x;
	right1 = Vector2f->x + vector2f->width;
    right2 = object2->x + object2->width;
    top1 = vector2f->y;
    top2 = object2->y;
    bottom1 = vector2f->y + vector2f->height;
    bottom2 = object2->y + object2->height;*/


	

	//set up the scroller data
	ScrollSprite scrollingSprite(dScroll);
	scrollingSprite.setScrollPos( rand() % scrollPosMax );
	scrollingSprite.setVertPos(300);

	Scrollpower scrollingSprite0(cScroll);
	scrollingSprite0.setScrollPos( rand() % scrollPosMax );
	scrollingSprite0.setVertPos(300);
	

	ScrollSprite scrollingSprite1(aScroll);
	scrollingSprite1.setScrollPos( rand() % scrollPosMax );
	scrollingSprite1.setVertPos(320);

	ScrollSprite scrollingSprite2(aScroll);
	scrollingSprite2.setScrollPos( rand() % scrollPosMax );
	scrollingSprite2.setVertPos(380);
	scrollingSprite2.SetScale(3,3);

	ScrollSprite scrollingSprite3(cScroll);
	scrollingSprite3.setScrollPos( rand() % scrollPosMax );
	scrollingSprite3.setVertPos(400);
	scrollingSprite3.SetScale(1,1);
	
	ScrollSprite scrollingSprite4(aScroll);
	scrollingSprite4.setScrollPos( rand() % scrollPosMax );
	scrollingSprite4.setVertPos(300);

	ScrollSprite scrollingSprite5(bScroll);
	scrollingSprite5.setScrollPos( rand() % scrollPosMax );
	scrollingSprite5.setVertPos(20);

	ScrollSprite scrollingSprite6(aScroll);
	scrollingSprite6.setScrollPos( rand() % scrollPosMax );
	scrollingSprite6.setVertPos(380);
	scrollingSprite6.SetScale(3,3);

	ScrollSprite scrollingSprite7(aScroll);
	scrollingSprite7.setScrollPos( rand() % scrollPosMax );
	scrollingSprite7.setVertPos(4000);
	scrollingSprite7.SetScale(3,3);

    ScrollSprite scrollingSprite8(bScroll);
	scrollingSprite8.setScrollPos( rand() % scrollPosMax );
	scrollingSprite8.setVertPos(4000);
	scrollingSprite8.SetScale(3,3);

    ScrollSprite scrollingSprite9(bScroll);
	scrollingSprite9.setScrollPos( rand() % scrollPosMax );
	scrollingSprite9.setVertPos(4000);
	scrollingSprite9.SetScale(3,3);

    ScrollSprite scrollingSprite10(bScroll);
	scrollingSprite10.setScrollPos( rand() % scrollPosMax );
	scrollingSprite10.setVertPos(35);
	scrollingSprite10.SetScale(1,1);

 


	std::vector<ScrollSprite*> pSprite;
	pSprite.push_back(&scrollingSprite);
	pSprite.push_back(&scrollingSprite1);
	pSprite.push_back(&scrollingSprite2);
	pSprite.push_back(&scrollingSprite3);
	pSprite.push_back(&scrollingSprite4);
	pSprite.push_back(&scrollingSprite5);
	pSprite.push_back(&scrollingSprite6);
	pSprite.push_back(&scrollingSprite7);
	pSprite.push_back(&scrollingSprite8);
	pSprite.push_back(&scrollingSprite9);
	pSprite.push_back(&scrollingSprite10);
	 
    std::vector<Scrollpower*> sSprite;
	sSprite.push_back(&scrollingSprite0);




  
	//nb - scroller window width needs to match window size
	
    Scroller scr(2000,width,pSprite,400);
	
    powerupScroller sc(2000,width,sSprite,400);

    
	// Create main window
    sf::RenderWindow App(sf::VideoMode(width, height), "Scroller Window"); 
	
    // Start the display loop
    while (App.IsOpened())
    {
		
		sf::Event Event;
          
		//check inputs in the event queue
				 while (App.GetEvent(Event))
				{
					// Close window : exit
					if (Event.Type == sf::Event::Closed)
						App.Close();
					// Escape key : exit
					if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
						App.Close();

					//up arrow key : does nothing
					if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Up))
					{
                        
                        
					    anim.Move(0,-20);
						//to do something on up key write here
												
					}

	                if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Down))
					{
                        
                       anim.Move(0,20);
						//to do something on up key write here
												
					}

                     if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::S))
					
					{
                        
					 screen.Rotate(100.00);
					}


			         
                     if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::W))
					
					{
                     
					 anim.Rotate(30.00);
					}

					
					
					//other events are ignored
				}

				 //update the things that need updating in the game loop

				 float f=clock.GetElapsedTime();
				 clock.Reset();
				 timeAccumulator+=f;
				 scr.update(f);
				 sc.update(f);
				 anim.update(f);
				 

				 //draw the things you have to draw
                  
				  App.Draw(backGndSprite);
				  App.Draw(anim);
                  App.Draw(scr);
				  App.Draw(sc);
                  App.Draw(screen);
				 
                 
				

				 //Monitoring the display function
				std::stringstream str;
				 str<<"The display rate is ";		
				 
				 str<<1/f;
				 //str<<"  the accumulated time is "<<timeAccumulator;
                 str<<1/f;
				 std::string s;
				 std::getline(str,s);
				 str.clear();				 
				 sf::String TextScore(s.c_str(),sf::Font::GetDefaultFont(),15);
					TextScore.SetPosition(0,0);
					TextScore.SetColor(sf::Color(255, 0, 0));
					App.Draw(TextScore);

                 std::stringstream stv;
				 stv<<"The level is "<<level;
				 //stv<<1/f;
				 std::string sv;
				 std::getline(stv,sv);
				 stv.clear();
				 sf::String Text(sv.c_str(),sf::Font::GetDefaultFont(),15);
				 Text.SetPosition(10,20);
				 Text.SetColor(sf::Color(255,0,0));
				 App.Draw(Text);


			     std::stringstream stvt;
				 stvt<<"The distance travelled "<<timeAccumulator<<"Mps";
				 stv<<1/f;
				 std::string sx;
				 std::getline(stvt,sx);
				 stvt.clear();
				 sf::String Dist(sx.c_str(),sf::Font::GetDefaultFont(),15);
				 Dist.SetPosition(20,30);
				 Dist.SetColor(sf::Color(255,0,0));
				 App.Draw(Dist);


                 std::stringstream stvs;
				 stvs<<"LIVES "<<lives;
				 //stvs<<1/f;
				 std::string sm;
				 std::getline(stvs,sm);
				 stvt.clear();
				 sf::String life(sm.c_str(),sf::Font::GetDefaultFont(),15);
				 life.SetPosition(20,40);
				 life.SetColor(sf::Color(255,0,0));
				 App.Draw(life);
				  
				if (timeAccumulator > 10)

				{

				      level = 1;
                     
					 
					 

				}

               
	            if (timeAccumulator > 50)

				{

				      level = 2;
                      
					 

				}


                if (timeAccumulator > 100)

				{

				      level = 3;
                      
					  

				}
                

			

				if (lives == 1)

				{

                     App.Draw(game);
                  
				}
                  
				


			
					
			
        // Finally, display the rendered frame on screen
        App.Display();
    }

    
    return EXIT_SUCCESS;

}

Open in new window

0
pgnatyukCommented:
Delete this block
void PlayWav(HINSTANCE hinstance)
{
        PlaySound((LPCSTR)IDR_SELECT, hinstance, SND_ASYNC | SND_RESOURCE);
}

Change the beginning:
#include
#include
#include
#include
#include "ScrollSprite.h"
#include "Scroller.h"
#include "AnimatedSprite.h"
#include "powerupScroller.h"
#include "Scrollpower.h"
#include "Explosion.h"
#include
#define NTDDI_VISTA (0x06000000)
#include
#include
#pragma comment(lib, "Winmm.lib")

That's all
0
tango2009Author Commented:
I have done that I get this error still

mainscroller.cpp(42) : error C2664: 'PlaySoundW' : cannot convert parameter 1 from 'const char [22]' to 'LPCWSTR'

This is my changed main below
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include <sstream>
#include "ScrollSprite.h"
#include "Scroller.h"
#include "AnimatedSprite.h"
#include "powerupScroller.h"
#include "Scrollpower.h"
#include "Explosion.h"
#include <time.h>
#define NTDDI_VISTA (0x06000000)
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "Winmm.lib")


using std::endl;


int main()
{

	//initialisation - lots of this code could be put into functions for 
	//neatness and separation of concerns. You need to declare objects here to draw them
	//but the set up for those objects could be done in a function or a class

	//window dimensions 
	unsigned int width=600;
	unsigned int height=480;
	
	//we need a timer to update things - get a clock
	sf::Clock clock;
	static float timeAccumulator=0.0;
    
	//load resources for the scroller - images and sounds (if you have any)	
	sf::Image backGround;
	if(!backGround.LoadFromFile("images/backGrnd2.jpg")) std::cout<<"File not found background.jpg"<<std::endl;



    PlaySound("sounds/explosion1.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC); 

    sf::Image gameover;
	if(!gameover.LoadFromFile("images/gameover.jpg")) std::cout<<"File not found gameover.jpg"<<std::endl;

    sf::Image title;
	if(!title.LoadFromFile("images/title.png")) std::cout<<"File not found title.jpg"<<std::endl;
	
	sf::Image aScroll;	
	if(!aScroll.LoadFromFile("images/rock.png")) std::cout<<"File not found rock.png"<<std::endl;

    sf::Image bScroll;	
	if(!bScroll.LoadFromFile("images/navalmine.png")) std::cout<<"File not found navalmine.png"<<std::endl;

    sf::Image cScroll;	
	if(!cScroll.LoadFromFile("images/barrel.png")) std::cout<<"File not found barrel.png"<<std::endl;

    sf::Image dScroll;	
	if(!dScroll.LoadFromFile("images/ship.png")) std::cout<<"File not found ship.png"<<std::endl;

    sf::Image aNimat;	
	if(!aNimat.LoadFromFile("images/sub.png")) std::cout<<"File not found sub.png"<<std::endl;

	sf::Image expo;
	if(!expo.LoadFromFile("images/explosion.png")) std::cout<<"File not found explosion.png"<<std::endl;

	//resouces loaded
    int level = 0;
	int lives = 0;
   

   	AnimatedSprite anim(aNimat,Vector2f(0,-50),Vector2f(5,1),0,Color(255,255,255,255),9,5);
	
	//resouces loaded
	anim.Scale(3,3);
	
    int scrollPosMax = 2000;
    int vertPosMax = 300;

    srand ( time(NULL) );


   
	anim.setInterval(1.05);
	anim.Move(200,200);
    
	
	sf::Sprite backGndSprite(backGround);
	backGndSprite.Scale(0.75f,0.8f);

    sf::Sprite screen(title);
	screen.Scale(0.75f,0.8f);

    sf::Sprite game(gameover);
	game.Scale(0.75f,0.8f);


    /*int left1, left2;
	int right1, right2;
	int top1, top2;
	int bottom1, bottom2;

	left1 = Vector2f->x;
	left2 = object2->x;
	right1 = Vector2f->x + vector2f->width;
    right2 = object2->x + object2->width;
    top1 = vector2f->y;
    top2 = object2->y;
    bottom1 = vector2f->y + vector2f->height;
    bottom2 = object2->y + object2->height;*/


	

	//set up the scroller data
	ScrollSprite scrollingSprite(dScroll);
	scrollingSprite.setScrollPos( rand() % scrollPosMax );
	scrollingSprite.setVertPos(300);

	Scrollpower scrollingSprite0(cScroll);
	scrollingSprite0.setScrollPos( rand() % scrollPosMax );
	scrollingSprite0.setVertPos(300);
	

	ScrollSprite scrollingSprite1(aScroll);
	scrollingSprite1.setScrollPos( rand() % scrollPosMax );
	scrollingSprite1.setVertPos(320);

	ScrollSprite scrollingSprite2(aScroll);
	scrollingSprite2.setScrollPos( rand() % scrollPosMax );
	scrollingSprite2.setVertPos(380);
	scrollingSprite2.SetScale(3,3);

	ScrollSprite scrollingSprite3(cScroll);
	scrollingSprite3.setScrollPos( rand() % scrollPosMax );
	scrollingSprite3.setVertPos(400);
	scrollingSprite3.SetScale(1,1);
	
	ScrollSprite scrollingSprite4(aScroll);
	scrollingSprite4.setScrollPos( rand() % scrollPosMax );
	scrollingSprite4.setVertPos(300);

	ScrollSprite scrollingSprite5(bScroll);
	scrollingSprite5.setScrollPos( rand() % scrollPosMax );
	scrollingSprite5.setVertPos(20);

	ScrollSprite scrollingSprite6(aScroll);
	scrollingSprite6.setScrollPos( rand() % scrollPosMax );
	scrollingSprite6.setVertPos(380);
	scrollingSprite6.SetScale(3,3);

	ScrollSprite scrollingSprite7(aScroll);
	scrollingSprite7.setScrollPos( rand() % scrollPosMax );
	scrollingSprite7.setVertPos(4000);
	scrollingSprite7.SetScale(3,3);

    ScrollSprite scrollingSprite8(bScroll);
	scrollingSprite8.setScrollPos( rand() % scrollPosMax );
	scrollingSprite8.setVertPos(4000);
	scrollingSprite8.SetScale(3,3);

    ScrollSprite scrollingSprite9(bScroll);
	scrollingSprite9.setScrollPos( rand() % scrollPosMax );
	scrollingSprite9.setVertPos(4000);
	scrollingSprite9.SetScale(3,3);

    ScrollSprite scrollingSprite10(bScroll);
	scrollingSprite10.setScrollPos( rand() % scrollPosMax );
	scrollingSprite10.setVertPos(35);
	scrollingSprite10.SetScale(1,1);

 


	std::vector<ScrollSprite*> pSprite;
	pSprite.push_back(&scrollingSprite);
	pSprite.push_back(&scrollingSprite1);
	pSprite.push_back(&scrollingSprite2);
	pSprite.push_back(&scrollingSprite3);
	pSprite.push_back(&scrollingSprite4);
	pSprite.push_back(&scrollingSprite5);
	pSprite.push_back(&scrollingSprite6);
	pSprite.push_back(&scrollingSprite7);
	pSprite.push_back(&scrollingSprite8);
	pSprite.push_back(&scrollingSprite9);
	pSprite.push_back(&scrollingSprite10);
	 
    std::vector<Scrollpower*> sSprite;
	sSprite.push_back(&scrollingSprite0);




  
	//nb - scroller window width needs to match window size
	
    Scroller scr(2000,width,pSprite,400);
	
    powerupScroller sc(2000,width,sSprite,400);

    
	// Create main window
    sf::RenderWindow App(sf::VideoMode(width, height), "Scroller Window"); 
	
    // Start the display loop
    while (App.IsOpened())
    {
		
		sf::Event Event;
          
		//check inputs in the event queue
				 while (App.GetEvent(Event))
				{
					// Close window : exit
					if (Event.Type == sf::Event::Closed)
						App.Close();
					// Escape key : exit
					if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
						App.Close();

					//up arrow key : does nothing
					if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Up))
					{
                        
                        
					    anim.Move(0,-20);
						//to do something on up key write here
												
					}

	                if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Down))
					{
                        
                       anim.Move(0,20);
						//to do something on up key write here
												
					}

                     if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::S))
					
					{
                        
					 screen.Rotate(100.00);
					}


			         
                     if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::W))
					
					{
                     
					 anim.Rotate(30.00);
					}

					
					
					//other events are ignored
				}

				 //update the things that need updating in the game loop

				 float f=clock.GetElapsedTime();
				 clock.Reset();
				 timeAccumulator+=f;
				 scr.update(f);
				 sc.update(f);
				 anim.update(f);
				 

				 //draw the things you have to draw
                  
				  App.Draw(backGndSprite);
				  App.Draw(anim);
                  App.Draw(scr);
				  App.Draw(sc);
                  App.Draw(screen);
				 
                 
				

				 //Monitoring the display function
				std::stringstream str;
				 str<<"The display rate is ";		
				 
				 str<<1/f;
				 //str<<"  the accumulated time is "<<timeAccumulator;
                 str<<1/f;
				 std::string s;
				 std::getline(str,s);
				 str.clear();				 
				 sf::String TextScore(s.c_str(),sf::Font::GetDefaultFont(),15);
					TextScore.SetPosition(0,0);
					TextScore.SetColor(sf::Color(255, 0, 0));
					App.Draw(TextScore);

                 std::stringstream stv;
				 stv<<"The level is "<<level;
				 //stv<<1/f;
				 std::string sv;
				 std::getline(stv,sv);
				 stv.clear();
				 sf::String Text(sv.c_str(),sf::Font::GetDefaultFont(),15);
				 Text.SetPosition(10,20);
				 Text.SetColor(sf::Color(255,0,0));
				 App.Draw(Text);


			     std::stringstream stvt;
				 stvt<<"The distance travelled "<<timeAccumulator<<"Mps";
				 stv<<1/f;
				 std::string sx;
				 std::getline(stvt,sx);
				 stvt.clear();
				 sf::String Dist(sx.c_str(),sf::Font::GetDefaultFont(),15);
				 Dist.SetPosition(20,30);
				 Dist.SetColor(sf::Color(255,0,0));
				 App.Draw(Dist);


                 std::stringstream stvs;
				 stvs<<"LIVES "<<lives;
				 //stvs<<1/f;
				 std::string sm;
				 std::getline(stvs,sm);
				 stvt.clear();
				 sf::String life(sm.c_str(),sf::Font::GetDefaultFont(),15);
				 life.SetPosition(20,40);
				 life.SetColor(sf::Color(255,0,0));
				 App.Draw(life);
				  
				if (timeAccumulator > 10)

				{

				      level = 1;
                     
					 
					 

				}

               
	            if (timeAccumulator > 50)

				{

				      level = 2;
                      
					 

				}


                if (timeAccumulator > 100)

				{

				      level = 3;
                      
					  

				}
                

			

				if (lives == 1)

				{

                     App.Draw(game);
                  
				}
                  
				


			
					
			
        // Finally, display the rendered frame on screen
        App.Display();
    }

    
    return EXIT_SUCCESS;

}

Open in new window

0
pgnatyukCommented:
Change this line:
PlaySound(L"sounds/explosion1.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);

I added 'L' before the file name.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Game Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.