Esempio n. 1
0
void cargaCosas(){
    music.openFromFile("Song5.ogg");
    buffer.loadFromFile("canon.wav");
	sound.setBuffer(buffer);
	music.setLoop(true);
	music.play();
}
bool SoundManager::loadSoundsFromDir(File& dir){
	if(!dir.exists() || !dir.isDirectory()){
		return false;
	}
	bool success = true;
	for(File file : dir.listFiles()){
		if(file.isDirectory()){
			success = !loadSoundsFromDir(file) ? false : success;
			continue;
		}

		SoundBuffer* localBuffer = new SoundBuffer();

		if(!localBuffer->loadFromFile(file.path())){
			delete localBuffer;
			logger::warning("Failed to load sound: " + file.path());
			success = false;
			continue;
		}

		// TODO: fix dynamic naming
		String category = file.parent().nameNoExtension();
		String name = file.nameNoExtension();

		// Adding sound to the map and set
		soundBoard[category][name] = localBuffer;
		sounds.insert(localBuffer);
	}
	// All sound loaded
	return success;
}
Esempio n. 3
0
	bool init() {
		VideoMode videoMode(width, height);
		window.create(videoMode, "Break Out");
		window.setVerticalSyncEnabled(true);
		window.setFramerateLimit(FRAMES_PER_SECOND);

		 if (!font.loadFromFile("res\\stocky.ttf"))
            return false;  
 
        if (!soundBuffer1.loadFromFile("res\\blip.wav"))
            return false;
         
        if (!soundBuffer2.loadFromFile("res\\blam.wav"))
            return false;
         
        if (!soundBuffer3.loadFromFile("res\\blap.wav"))
            return false;
 
        if (!soundBuffer4.loadFromFile("res\\blop.wav"))
            return false;

		setup();
		return true;
	}
Esempio n. 4
0
void MasterClass::playSettings()
{
	Vector2u window_size = window->getSize();
	Image img = window->capture();
	Texture texture;
	//texture.loadFromImage(img);
	texture.loadFromFile("res/tex/decor/settings_menu.png");
	Vector2u texture_size = texture.getSize();
	Sprite sprite(texture);
	// 0 -> pas transparent et 255 -> transparent
	//sprite.setColor(sf::Color(255, 255, 255, 128));
	sprite.scale((float)window_size.x/texture_size.x, (float)window_size.y/texture_size.y);
	View view = window->getView();
	sprite.setPosition(view.getCenter().x - (float)window_size.x/2, 0);
	
    Font font;
    font.loadFromFile("res/font/arcade.ttf");
    vector<String> vectItems;
    vectItems.push_back("Reprendre");
    const int resume = 0;
    vectItems.push_back("<- Volume musique +>");
    const int musicsVolume = 1;
    vectItems.push_back("<- Volume bruitages +>");
    const int soundEffectsVolume = 2;
    vectItems.push_back("Menu principal");
    const int mainMenu = 3;
    Menu menu(vectItems, window, font, Menu::CENTER, (unsigned int)window_size.y*0.0444);
	
	SoundBuffer buffer;
	Sound s;
	buffer.loadFromFile("res/snd/enemy/rebel/death1.wav");
	s.setBuffer(buffer);
	
	Music music;
    music.openFromFile("res/snd/level/The_Military_System.wav");
    music.setVolume(config.musicsVolume);
    music.setLoop(true);
    music.play();
	
	while (window->isOpen() && state == SETTINGS)
	{
		sf::Event event;
		while(window->pollEvent(event))
		{
			if (event.type == Event::KeyPressed)
        	{
        		switch(event.key.code)
        		{
        			case Keyboard::Escape :
						state = previousState;
						break;
						
					case Keyboard::Up :
				    	menu.moveUp();
				    	break;
				    	
				    case Keyboard::Down :
				    	menu.moveDown();
				    	break;
				    	
				    case Keyboard::Return :
				    	switch(menu.getSelectedItemIndex())
				    	{
				    		case resume :
				    			state = previousState;
				    			break;
				    		
				    		case mainMenu :
				    			previousState = state;
								state = MAINMENU;
				    			break;
				    		
				    		default :
				    			break;
				    	}
				    	break;
					
					case Keyboard::Left :
						switch(menu.getSelectedItemIndex())
				    	{
				    		case musicsVolume :
				    			config.musicsVolume -= 10;
								if(config.musicsVolume < 0)
									config.musicsVolume = 0;
								music.setVolume(config.musicsVolume);
				    			break;
				    		
				    		case soundEffectsVolume :
				    			config.soundEffectsVolume -= 10;
								if(config.soundEffectsVolume < 0)
									config.soundEffectsVolume = 0;
								s.setVolume(config.soundEffectsVolume);
								s.play();
				    			break;
				    		
				    		default :
				    			break;
				    	}
				    	break;
						
					case Keyboard::Right :
						switch(menu.getSelectedItemIndex())
				    	{
				    		case musicsVolume :
				    			config.musicsVolume += 10;
								if(config.musicsVolume > 100)
									config.musicsVolume = 100;
								music.setVolume(config.musicsVolume);
				    			break;
				    		
				    		case soundEffectsVolume :
				    			config.soundEffectsVolume += 10;
								if(config.soundEffectsVolume > 100)
									config.soundEffectsVolume = 100;
								s.setVolume(config.soundEffectsVolume);
								s.play();
				    			break;
				    		
				    		default :
				    			break;
				    	}
				    	break;
						
					default :
						break;
        		}
			}
		}
		window->clear();
		window->draw(sprite);
        menu.draw(window);
		window->display();
	}
}
Esempio n. 5
0
int main()
{
	srand(time(nullptr));
	sf::Clock time;
	sf::View followPlayer; //private member in class
	sf::Sprite background;
	sf::Texture background_texture;
	sf::Sprite key;
	sf::Sprite key2;
	sf::Texture key_texture;
	sf::Texture mute_texture;
	sf::Sprite mute_sprite;
	vector<Key*> keys;
	vector<unsigned int> keysForDeletion;
	
	if (!background_texture.loadFromFile("Data/Sprites/background.png"))
	{
		return -1;
	}

	if (!key_texture.loadFromFile("Data/Sprites/key.png")){
		return -1;
	}

	key2.setTexture(key_texture);
	key2.setScale(5, 5);
	key.setTexture(key_texture);
	key.setScale(5, 5);

	if (!mute_texture.loadFromFile("Data/Sprites/mute_icon.png")){
		cout << "Couldn't load mute_icon.png" << endl;
	}
	mute_sprite.setTexture(mute_texture);
	mute_sprite.setScale(3, 3);
	if (!keyBuffer.loadFromFile("Data/Sounds/key_taken.wav")){
		cout << "Couldn't load key_taken.wav" << endl;
	}
	keySound.setBuffer(keyBuffer);

	/*Load the theme music and start playing it if it loads correctly*/
	if (!buffer.loadFromFile("Data/Sounds/theme.wav")){
		cout << "Couldn't load theme.wav" << endl;
	}
	else {
		theme.setBuffer(buffer);
		theme.play();
	}


	background.setTexture(background_texture);

	background.setScale(5, 5);

	/*Set the position relative the middle of the background's bounds */
	background.setPosition(-background.getLocalBounds().width / 2, -background.getLocalBounds().height / 2);
	key.setPosition(200, 150);
	key2.setPosition(350, 350);
	Player player = Player(background.getPosition(), Vector2f(background.getLocalBounds().width * background.getScale().x, background.getLocalBounds().height * background.getScale().y));

	/*Window setup*/
	sf::RenderWindow window(sf::VideoMode(1200, 720), "Presence");
	window.clear(sf::Color(255, 255, 255, 0));
	 
	/*keyCounter doesn't work when keys in between get deleted*/
	keys.push_back(new Key(player, Vector2f(background.getLocalBounds().width * background.getScale().x, background.getLocalBounds().height * background.getScale().y)));
	keys.push_back(new Key(player, Vector2f(background.getLocalBounds().width * background.getScale().x, background.getLocalBounds().height * background.getScale().y)));
	keys.push_back(new Key(player, Vector2f(background.getLocalBounds().width * background.getScale().x, background.getLocalBounds().height * background.getScale().y)));
	keys.push_back(new Key(player, Vector2f(background.getLocalBounds().width * background.getScale().x, background.getLocalBounds().height * background.getScale().y)));
	keys.push_back(new Key(player, Vector2f(background.getLocalBounds().width * background.getScale().x, background.getLocalBounds().height * background.getScale().y)));

	while (window.isOpen())
	{
		if (muted){
			if (theme.getStatus() == theme.Playing){
				theme.pause();
			}
		}
		else if(theme.getStatus() == theme.Paused){
			theme.play();
		}
		/*Deltatime*/
		sf::Time delta = time.restart();

		//EVENTS
		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::KeyPressed){
				if (event.key.code == sf::Keyboard::M){
					if (muted) muted = false;
					else muted = true;
				}
			}
			if (event.type == sf::Event::Closed || event.key.code == sf::Keyboard::Escape)
				window.close();
			player.move(event);
		}

		//LOGIC
		player.update(delta.asSeconds());

		//RENDERING
		window.clear(sf::Color(178, 148, 0, 0));
		window.draw(background);

		Vector2f cameraSpeed = getCameraSpeed(followPlayer.getCenter(), player.getPosition());
		float cameraXSpeed = cameraSpeed.x;
		float cameraYSpeed = cameraSpeed.y;

		if (!keyTaken && key.getGlobalBounds().intersects(player.getBounds())){
			cout << "HIT!" << endl;
			
			keyTaken = true;
			if (!muted) keySound.play();
		}
		if (!key2Taken && key2.getGlobalBounds().intersects(player.getBounds())){
			key2Taken = true;
			if(!muted) keySound.play();
		}
		followPlayer.setCenter(followPlayer.getCenter().x + cameraXSpeed * delta.asSeconds(), followPlayer.getCenter().y + cameraYSpeed * delta.asSeconds()); //in constructor

		followPlayer.setSize(1200, 720);
		window.setView(followPlayer);

		if (muted){
			mute_sprite.setPosition(window.mapPixelToCoords(Vector2i(1, 0)));
			window.draw(mute_sprite);
		}
		if (!keyTaken){
			window.draw(key);
		}
		if (!key2Taken){
			window.draw(key2);
		}
		player.render(window);

		int i = 0;
		/*Free memory from taken key objects*/
		for (Key* key : keys){
			if (!key->readyForDeletion()){
				key->update(delta.asSeconds());
				key->render(window);
			}
			else{
				keysForDeletion.push_back(i);
			}
			i++;
		}
		for (unsigned int index : keysForDeletion){
			Key* key_ptr = keys[index];
			keys.erase(remove(keys.begin(), keys.end(), key_ptr), keys.end());
			delete key_ptr;
		}

		keysForDeletion.clear();

		window.display();
	}

	return 0;
}
bool StartGame(RenderWindow & window, Game & game)
{
	Level lvl;
	lvl.LoadFromFile(GetLevelNumb(game));
	Image image;
	Texture texture;
	if (!image.loadFromFile("images/lvl1.png"))
		cout << "Error loading image from file " << endl;
	image.createMaskFromColor(Color(0, 128, 0));
	if (!texture.loadFromImage(image))
		cout << "Error loading texture from image " << endl;

	Sprite heartSprite;
	heartSprite.setTexture(texture);
	heartSprite.setTextureRect(IntRect(395, 151, 54, 46));
	heartSprite.setScale(0.3f, 0.3f);

	Sprite lifeSprite;
	lifeSprite.setTexture(texture);
	lifeSprite.setTextureRect(IntRect(457, 149, 29, 29));
	lifeSprite.setScale(0.8f, 0.8f);

	Font font;
	font.loadFromFile("fonts/pixel.ttf");
	Text text("", font, 25);

	game.graphic.statistic.heart = heartSprite;
	game.graphic.statistic.life = lifeSprite;
	game.graphic.text = text;
	game.isPause = true;
	game.restart = false;

	vector <Enemy*>  enemies;
	std::vector<Object> e = lvl.GetObjects("easyEnemy");
	for (Object i : e)
		enemies.push_back(new Enemy(texture, "easyEnemy", i.rect.left, i.rect.top, 53, 28));

	e = lvl.GetObjects("flyEnemy");
	for (Object i : e)
		enemies.push_back(new Enemy(texture, "flyEnemy", i.rect.left, i.rect.top, 38, 36));
	
	
	if (lvl.IsExist("trap"))
	{
		e = lvl.GetObjects("trap");
		for (Object i : e)
			enemies.push_back(new Enemy(texture, "trap", i.rect.left, i.rect.top, 32, 18));
	}


	vector <Portal*> portals;
	vector <Bullet*> bullets;
	vector <Object> objects = lvl.GetAllObjects();
	Clock clock;

	SoundBuffer shootBuffer;
	shootBuffer.loadFromFile("sound/shoot.wav");
	Sound shoot(shootBuffer);

	SoundBuffer portalBuffer;
	portalBuffer.loadFromFile("sound/portal.wav");
	Sound portal(portalBuffer);

	SoundBuffer teleportBuffer;
	teleportBuffer.loadFromFile("sound/teleport.wav");
	Sound teleport(teleportBuffer);

	SoundBuffer damageBuffer;
	damageBuffer.loadFromFile("sound/damage.wav");
	Sound damage(damageBuffer);

	SoundBuffer deathBuffer;
	deathBuffer.loadFromFile("sound/damage.wav");
	Sound gameOver(deathBuffer);

	Music music;
	music.openFromFile("sound/musicGame.ogg");
	music.play();

	Object playerObject = lvl.GetObject("player");
	Player player(texture, "Player1", playerObject.rect.left, playerObject.rect.top, 32, 32);
	player.health = game.health;
	player.heart = game.hearts;

	while (window.isOpen() && (!game.restart))
	{
		float time = float(clock.getElapsedTime().asMicroseconds());
		clock.restart();
		time = time / 800;
		Event event;
		Vector2i pixelPos = Mouse::getPosition(window);
		Vector2f pos = window.mapPixelToCoords(pixelPos);
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed || (Keyboard::isKeyPressed(Keyboard::Escape) && game.isPause))
			{
				window.close();
				game.restart = false;
			}
			if (event.type == Event::MouseButtonPressed)
			{
				pos.y = float(player.teleportY);
				if ((event.key.code == Mouse::Left) && (player.doesOpenPortal))
				{
					CreatePortal(portals, game, "blue", pos, texture);
					portal.play();
				}
				else if (event.key.code == Mouse::Right && (player.doesOpenPortal))
				{
					CreatePortal(portals, game, "yellow", pos, texture);
					portal.play();
				}
			}
			if (player.isTeleporting)
			{
				TeleportPlayer(player, portals);
				teleport.play();
			}
			if (Keyboard::isKeyPressed(Keyboard::Return))
			{
				game.isPause = false;
			}
			if (Keyboard::isKeyPressed(Keyboard::P))
			{
				game.isPause = true;
			}
			if (Keyboard::isKeyPressed(Keyboard::Tab) && game.isPause) 
			{ 
				game.restart = true; 
			}
		}
		if (player.isExit)
		{
			if (game.isEndLevel)
			{
				game.isPause = true;
			}
			else
			{
				game.level++;
				game.restart = true;
				game.health = player.health;
				game.hearts = player.heart;
			}
		}
		for (auto *e : enemies)
		{
			if ((*e).name == "flyEnemy" && (*e).isShoot)
			{
				CreateBullet(bullets, (*e).GetRect(), player, texture);
				shoot.play();
			}
		}
		EntitiesIntersection(player, enemies, portals, bullets, damage);
		if (player.alive)
		{
			setPlayerCoordinateForView(game.camera, player.GetPos().x, player.GetPos().y);
		}
		if (!game.isPause)
		{
			UpdateEnemies(objects, enemies, time, player);
			UpdatePortals(portals, time);
			UpdateBullets(objects, bullets, time);
			player.Update(objects, time, pos, game.portalH);
		}
		window.setView(game.camera);
		window.clear();
		lvl.Draw(window);
		DrawEnemies(window, enemies);
		DrawPortals(window, portals);
		DrawBullets(window, bullets);
		DrawStatistic(window, &game, player, game.camera);
		window.draw(player.sprite);
		DrawAllMessages(player, game, window);
		music.setLoop(true);
		window.display();
	}
	return game.restart;
}
Esempio n. 7
0
int main()
{
	//Crear una ventana
	Vector2f windowMedidas;
	windowMedidas.x = 640; windowMedidas.y = 360;
	RenderWindow window(VideoMode(windowMedidas.x, windowMedidas.y), "Urban Mind (Demo)");
	window.setFramerateLimit(60);
	//Crear la V-Cam
	Vector2f CamaraPosicion, CamaraMedidas;
	CamaraPosicion.x = 0; CamaraPosicion.y = 0;
	CamaraMedidas.x = 640; CamaraMedidas.y = 360;
	View Camara(FloatRect(CamaraPosicion.x, CamaraPosicion.y, CamaraMedidas.x, CamaraMedidas.y));
	Camara.setCenter(CamaraMedidas.x / 2, CamaraMedidas.y / 2);

	int Screen = 1, nivel = 1, nivelMaximoAlcanzado = nivel; // Screen 1 = Menu, 2 = Niveles, 3 Otros...

	//Menu
	Texture BackgroundIMG;
	BackgroundIMG.loadFromFile("Dibujos/MainBackground.jpg");
	Sprite BGIMG;
	BGIMG.setTexture(BackgroundIMG);
	BGIMG.setOrigin(BackgroundIMG.getSize().x / 2, BackgroundIMG.getSize().y / 2);
	BGIMG.scale(0.48, 0.48);
	BGIMG.setPosition(320, 180);
	//Musica del menu
	sf::Music BgMainMusic;
	BgMainMusic.openFromFile("Musica/MainTheme.ogg");
	BgMainMusic.setVolume(50);
	BgMainMusic.setLoop(true);
	//Musica del juego
	Music LevelMusic;
	LevelMusic.openFromFile("Musica/LevelMusic.ogg");
	LevelMusic.setVolume(80);
	LevelMusic.setLoop(true);
	//Efecto de sonide empujar caja
	SoundBuffer DragFX;
	DragFX.loadFromFile("Musica/PullBox.ogg");
	Sound BoxFx(DragFX);
	//Botones
	int Selected = 0;
	bool KeyPressed = false;
	Boton Jugar = Boton(Vector2f(320, 180), "Dibujos/1Off.png", "Dibujos/1ON.png", 0.5), Salir = Boton(Vector2f(320, 230), "Dibujos/2Off.png", "Dibujos/2ON.png", 0.5);
	//Cosas inGame
	jugador yo = jugador(0,0);
	bloque box = bloque(1);
	bloque Tile1 = bloque(0);
	Texture TexturaMeta;
	TexturaMeta.loadFromFile("Dibujos/TSprite.jpg");
	Sprite Meta;
	Meta.setTexture(TexturaMeta);
	Meta.setOrigin(TexturaMeta.getSize().x / 2, TexturaMeta.getSize().y/2);
	Meta.scale(0.1,0.1);
	Vector2f coordenadasParaGanar;
	//Letras
	Font sansation;
	sansation.loadFromFile("Retro_Computer.ttf");
	Text scoreLabel("", sansation, 12);
	scoreLabel.setPosition(34, 15 * 34);
	scoreLabel.setColor(Color::White);

	//Contenedor de posiciones (Cajas), Contenedor de posiciones (Suelo)
	vector <Vector2f> contenedorDeCajas, contenedorDeSuelo;

	//Gameloop
	while (window.isOpen())
	{
		Event event;
		while (window.pollEvent(event))
		{
			if (event.type == Event::Closed)
				window.close();
		};
		
		if (window.hasFocus()) //Si la aplicacion esta seleccionada
		{
			window.clear();

			switch (Screen)
			{
				case 1: //Menu principal

					//Si la musica no se esta reproduciendo...
					if (BgMainMusic.getStatus() != 2) 
						BgMainMusic.play();

					window.draw(BGIMG); //Dibujar fondo
					window.draw(Jugar.getSprite()); //Dibujar boton de jugar
					window.draw(Salir.getSprite()); //Dibujar boton de salir

					//Cambiar seleccion de boton
					if (!(Keyboard::isKeyPressed(Keyboard::S) || Keyboard::isKeyPressed(Keyboard::Down)) && (Keyboard::isKeyPressed(Keyboard::W) || Keyboard::isKeyPressed(Keyboard::Up)) && Selected > 0 && !KeyPressed)
					{
						Selected--;
						KeyPressed = true;
					}
					else if ((Keyboard::isKeyPressed(Keyboard::S) || Keyboard::isKeyPressed(Keyboard::Down)) && !(Keyboard::isKeyPressed(Keyboard::W) || Keyboard::isKeyPressed(Keyboard::Up)) && Selected < 1 && !KeyPressed)
					{
						Selected++;
						KeyPressed = true;
					}
					else
					{
						KeyPressed = false;
					};

					if (Selected == 0)
					{
						Jugar.SetON();
						Salir.SetOFF();
					}
					else if (Selected == 1)
					{
						Jugar.SetOFF();
						Salir.SetON();
					};

					if (Keyboard::isKeyPressed(Keyboard::Return) || Keyboard::isKeyPressed(Keyboard::Space))
					{
						if (Selected == 0)
						{
							Screen = 2;
							BgMainMusic.stop();
						}
						else if (Selected == 1)
						{
							window.close();
						};
					};
					break;

				case 2: //Niveles

					//Ajustar camara al jugador
					CamaraPosicion.x = yo.getPosition().x - CamaraMedidas.x / 2;
					CamaraPosicion.y = yo.getPosition().y - CamaraMedidas.y / 2;
					Camara.reset(FloatRect(CamaraPosicion.x, CamaraPosicion.y, CamaraMedidas.x, CamaraMedidas.y));
					//Si la musica no se esta reproduciendo...
					if (LevelMusic.getStatus() != 2)
						LevelMusic.play();

					switch (nivel)
					{
						case 0: //Nivel jugable
							window.setView(Camara);

							for (int i = 0; i < contenedorDeSuelo.size(); i++) //Dibujar escenario
							{
								Tile1.positionOnMap(&contenedorDeSuelo[i]);
								window.draw(Tile1.getSprite());
							};

							//Dibujar la meta
							Meta.setPosition(coordenadasParaGanar.x * 34, coordenadasParaGanar.y * 34);
							window.draw(Meta);

							for (int i = 0; i < contenedorDeCajas.size(); i++) //Dibujar cajas
							{
								box.positionOnMap(&contenedorDeCajas[i]);
								window.draw(box.getSprite());
							};

							if (!yo.getMovingState()) //Si no te estas moviendo...
							{
								yo.checkMove(); //Revisar que accion quieres hacer

								for (int i = 0; i < contenedorDeSuelo.size(); i++) //Comprobar si hay suelo a 1 de ti
								{
									if (yo.IsPossible(&contenedorDeSuelo[i], 1)) //Hay un suelo a 1 de ti
									{
										yo.changeFloorTest(true);
										break;
									}
									else
										yo.changeFloorTest(false);
								};

								for (int i = 0; i < contenedorDeSuelo.size(); i++) //Comprobar si hay suelo a 2 de ti
								{
									if (yo.IsPossible(&contenedorDeSuelo[i], 2)) //Hay un suelo a 2 de ti
									{
										yo.changeSecondFloorTest(true);
										break;
									}
									else
										yo.changeSecondFloorTest(false);
								};

								for (int i = 0; i < contenedorDeCajas.size(); i++) //Comprobar si hay caja a 1 de ti
								{
									if (yo.IsPossible(&contenedorDeCajas[i], 1)) //Hay una caja a 1 de ti
									{
										yo.changeBlockTest(true);
										break;
									}
									else
										yo.changeBlockTest(false);
								};

								for (int i = 0; i < contenedorDeCajas.size(); i++) //Comprobar si hay una caja a 2 de ti
								{
									if (yo.IsPossible(&contenedorDeCajas[i], 2)) //Hay caja a 2 de ti
									{
										yo.changeSecondBlockTest(true);
										break;
									}
									else
										yo.changeSecondBlockTest(false);
								};

								if (yo.getIfHoldingBox()) //Seleccionar caja
								{
									for (int i = 0; i < contenedorDeCajas.size(); i++)
									{
										if (yo.getWatchingTo() == 'W' && yo.getPosition().x == contenedorDeCajas[i].x * 34 && yo.getPosition().y - 34 == contenedorDeCajas[i].y * 34)
											yo.setBoxID(i);
										else if (yo.getWatchingTo() == 'S' && yo.getPosition().x == contenedorDeCajas[i].x * 34 && yo.getPosition().y + 34 == contenedorDeCajas[i].y * 34)
											yo.setBoxID(i);
										else if (yo.getWatchingTo() == 'A' && yo.getPosition().x - 34 == contenedorDeCajas[i].x * 34 && yo.getPosition().y == contenedorDeCajas[i].y * 34)
											yo.setBoxID(i);
										else if (yo.getWatchingTo() == 'D' && yo.getPosition().x + 34 == contenedorDeCajas[i].x * 34 && yo.getPosition().y == contenedorDeCajas[i].y * 34)
											yo.setBoxID(i);
									};
								};

								//Comprobar si te puedes mover o no
								if (yo.getFloorTest() && !yo.getBlockTest() || yo.getFloorTest() && yo.getSecondFloorTest() && yo.getBlockTest() && !yo.getSecondBlockTest() && yo.getIfHoldingBox())
									//Si hay suelo y no hay caja, o si hay suelo a 1 y 2 de ti y hay caja a l de ti y la empujas y no hay caja a 2 de ti
									yo.setGoalByKey();

								//Si la caja esta cerca
								if (yo.getPosition().x - 34 <= contenedorDeCajas[yo.getBoxID()].x * 34 && yo.getPosition().x + 34 >= contenedorDeCajas[yo.getBoxID()].x * 34 && yo.getPosition().y - 34 <= contenedorDeCajas[yo.getBoxID()].y * 34 && yo.getPosition().y + 34 >= contenedorDeCajas[yo.getBoxID()].y * 34)
									yo.setIfBoxNear(true); //Puedes empujarla/jalarla
								else
									yo.setIfBoxNear(false); //No puedes empujarla/jalarla
							};

							//Si tienes el movimiento activado, moverte
							if (yo.getMovingState())
							{
								yo.movimiento(yo.getNextMove());

								if (yo.getIfHoldingBox() && yo.getIfBoxNear()) //Si estas jalando caja y esta cerca
								{
									if (yo.getNextMove() == 'W' && contenedorDeCajas[yo.getBoxID()].x == yo.getPosition().x / 34)
									{
										if (yo.getPosition().y / 34 > contenedorDeCajas[yo.getBoxID()].y) //Si la caja esta arriba de ti
										{
											yo.Animar('W', true, 0);
											contenedorDeCajas[yo.getBoxID()].y = (yo.getPosition().y - 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
										else
										{
											yo.Animar('S', true, 180);
											contenedorDeCajas[yo.getBoxID()].y = (yo.getPosition().y + 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
									}
									else if (yo.getNextMove() == 'S' && contenedorDeCajas[yo.getBoxID()].x == yo.getPosition().x / 34)
									{
										if (yo.getPosition().y / 34 > contenedorDeCajas[yo.getBoxID()].y)
										{
											yo.Animar('W', true, 0);
											contenedorDeCajas[yo.getBoxID()].y = (yo.getPosition().y - 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
										else
										{
											yo.Animar('S', true, 180);
											contenedorDeCajas[yo.getBoxID()].y = (yo.getPosition().y + 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
									}
									else if (yo.getNextMove() == 'A' && contenedorDeCajas[yo.getBoxID()].y == yo.getPosition().y / 34)
									{
										if (yo.getPosition().x / 34 > contenedorDeCajas[yo.getBoxID()].x)
										{
											yo.Animar('A', true, 270);
											contenedorDeCajas[yo.getBoxID()].x = (yo.getPosition().x - 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
										else
										{
											yo.Animar('D', true, 90);
											contenedorDeCajas[yo.getBoxID()].x = (yo.getPosition().x + 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
									}
									else if (yo.getNextMove() == 'D' && contenedorDeCajas[yo.getBoxID()].y == yo.getPosition().y / 34)
									{
										if (yo.getPosition().x / 34 < contenedorDeCajas[yo.getBoxID()].x)
										{
											yo.Animar('D', true, 90);
											contenedorDeCajas[yo.getBoxID()].x = (yo.getPosition().x + 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
										else
										{
											yo.Animar('A', true, 270);
											contenedorDeCajas[yo.getBoxID()].x = (yo.getPosition().x - 34) / 34;
											if (BoxFx.getStatus() != 2)
												BoxFx.play();
										}
									}
									else
										yo.Animar(yo.getNextMove(), false, 0);
								}
								else
									yo.Animar(yo.getNextMove(), false, 0);
							};

							window.draw(yo.getCharSprite()); //Dibujar personaje

							//Texto
							window.draw(scoreLabel);
							scoreLabel.setPosition(yo.getPosition().x - CamaraMedidas.x / 2, yo.getPosition().y + CamaraMedidas.y / 2 - scoreLabel.getCharacterSize());
							scoreLabel.setString("Level: " + to_string(nivelMaximoAlcanzado));

							if(yo.getPosition().x == coordenadasParaGanar.x*34 && yo.getPosition().y == coordenadasParaGanar.y*34)
							{
								nivelMaximoAlcanzado++;
								nivel = nivelMaximoAlcanzado;
								//Vaciar los vectores
								contenedorDeCajas.clear();
								contenedorDeSuelo.clear();
								//Cambiar la caja seleccionada
								yo.setBoxID(0);
							}

							break;

						case 1: //Cargar nivel 1
							//Posicion del jugador
							yo.setPosition(5, 1);
							//Asignar cosas
							contenedorDeCajas.push_back(Vector2f(0, 1));
							contenedorDeSuelo.push_back(Vector2f(0, 1));
							contenedorDeSuelo.push_back(Vector2f(1, 1));
							contenedorDeSuelo.push_back(Vector2f(2, 1));
							contenedorDeSuelo.push_back(Vector2f(3, 1));
							contenedorDeSuelo.push_back(Vector2f(4, 1));
							contenedorDeSuelo.push_back(Vector2f(5, 1));
							//Meta
							coordenadasParaGanar.x = 1;
							coordenadasParaGanar.y = 1;
							//ir al jugable
							nivel = 0;
							break;
						case 2: //Cargar nivel 2
							//Posicion del jugador
							yo.setPosition(4, 2);
							//Asignar cosas
							contenedorDeCajas.push_back(Vector2f(2, 2));
							contenedorDeSuelo.push_back(Vector2f(2, 1));
							contenedorDeSuelo.push_back(Vector2f(3, 1));
							contenedorDeSuelo.push_back(Vector2f(1, 2));
							contenedorDeSuelo.push_back(Vector2f(2, 2));
							contenedorDeSuelo.push_back(Vector2f(3, 2));
							contenedorDeSuelo.push_back(Vector2f(4, 2));
							contenedorDeSuelo.push_back(Vector2f(2, 3));
							//Meta
							coordenadasParaGanar.x = 1;
							coordenadasParaGanar.y = 2;
							//ir al jugable
							nivel = 0;
							break;
						case 3: //Cargar nivel 3
							//Posicion del jugador
							yo.setPosition(3, 3);
							//Asignar cosas
							contenedorDeCajas.push_back(Vector2f(1, 3));
							contenedorDeSuelo.push_back(Vector2f(1, 1));
							contenedorDeSuelo.push_back(Vector2f(2, 1));
							contenedorDeSuelo.push_back(Vector2f(3, 1));
							contenedorDeSuelo.push_back(Vector2f(1, 2));
							contenedorDeSuelo.push_back(Vector2f(3, 2));
							contenedorDeSuelo.push_back(Vector2f(1, 3));
							contenedorDeSuelo.push_back(Vector2f(2, 3));
							contenedorDeSuelo.push_back(Vector2f(3, 3));
							contenedorDeSuelo.push_back(Vector2f(1, 4));
							//Meta
							coordenadasParaGanar.x = 1;
							coordenadasParaGanar.y = 4;
							//ir al jugable
							nivel = 0;
							break;
						case 4: //Cargar nivel 4
							//Posicion del jugador
							yo.setPosition(10, 13);
							//Asignar cosas
							contenedorDeCajas.push_back(Vector2f(8, 13));
							contenedorDeCajas.push_back(Vector2f(10, 9));
							contenedorDeCajas.push_back(Vector2f(8, 7));
							contenedorDeCajas.push_back(Vector2f(8, 4));
							contenedorDeCajas.push_back(Vector2f(11, 2));
							contenedorDeCajas.push_back(Vector2f(2, 7));
							contenedorDeCajas.push_back(Vector2f(4, 2));
							//fila 1
							contenedorDeSuelo.push_back(Vector2f(4, 1));
							contenedorDeSuelo.push_back(Vector2f(7, 1));
							contenedorDeSuelo.push_back(Vector2f(8, 1));
							contenedorDeSuelo.push_back(Vector2f(9, 1));
							contenedorDeSuelo.push_back(Vector2f(11, 1));
							//fila 2
							contenedorDeSuelo.push_back(Vector2f(4, 2));
							contenedorDeSuelo.push_back(Vector2f(6, 2));
							contenedorDeSuelo.push_back(Vector2f(7, 2));
							contenedorDeSuelo.push_back(Vector2f(9, 2));
							contenedorDeSuelo.push_back(Vector2f(10, 2));
							contenedorDeSuelo.push_back(Vector2f(11, 2));
							//fila 3
							contenedorDeSuelo.push_back(Vector2f(1, 3));
							contenedorDeSuelo.push_back(Vector2f(2, 3));
							contenedorDeSuelo.push_back(Vector2f(3, 3));
							contenedorDeSuelo.push_back(Vector2f(4, 3));
							contenedorDeSuelo.push_back(Vector2f(6, 3));
							contenedorDeSuelo.push_back(Vector2f(8, 3));
							contenedorDeSuelo.push_back(Vector2f(11, 3));
							//fila 4
							contenedorDeSuelo.push_back(Vector2f(1, 4));
							contenedorDeSuelo.push_back(Vector2f(4, 4));
							contenedorDeSuelo.push_back(Vector2f(5, 4));
							contenedorDeSuelo.push_back(Vector2f(6, 4));
//							contenedorDeSuelo.push_back(Vector2f(7, 4));
							contenedorDeSuelo.push_back(Vector2f(8, 4));
							contenedorDeSuelo.push_back(Vector2f(9, 4));
							contenedorDeSuelo.push_back(Vector2f(10, 4));
							contenedorDeSuelo.push_back(Vector2f(11, 4));
							//fila 5
							contenedorDeSuelo.push_back(Vector2f(1, 5));
							contenedorDeSuelo.push_back(Vector2f(4, 5));
							contenedorDeSuelo.push_back(Vector2f(8, 5));
							//fila 6
							contenedorDeSuelo.push_back(Vector2f(1, 6));
							contenedorDeSuelo.push_back(Vector2f(3, 6));
							contenedorDeSuelo.push_back(Vector2f(4, 6));
							contenedorDeSuelo.push_back(Vector2f(8, 6));
							//fila 7
							contenedorDeSuelo.push_back(Vector2f(1, 7));
							contenedorDeSuelo.push_back(Vector2f(2, 7));
							contenedorDeSuelo.push_back(Vector2f(3, 7));
							contenedorDeSuelo.push_back(Vector2f(4, 7));
							contenedorDeSuelo.push_back(Vector2f(8, 7));
							contenedorDeSuelo.push_back(Vector2f(9, 7));
							contenedorDeSuelo.push_back(Vector2f(10, 7));
							//fila 8
							contenedorDeSuelo.push_back(Vector2f(3, 8));
							contenedorDeSuelo.push_back(Vector2f(8, 8));
							contenedorDeSuelo.push_back(Vector2f(10, 8));
							//fila 9
							contenedorDeSuelo.push_back(Vector2f(8, 9));
							contenedorDeSuelo.push_back(Vector2f(9, 9));
							contenedorDeSuelo.push_back(Vector2f(10, 9));
							contenedorDeSuelo.push_back(Vector2f(11, 9));
							//fila 10
							contenedorDeSuelo.push_back(Vector2f(9, 10));
							//fila 11
							contenedorDeSuelo.push_back(Vector2f(8, 11));
							contenedorDeSuelo.push_back(Vector2f(9, 11));
							contenedorDeSuelo.push_back(Vector2f(10, 11));
							//fila 12
							contenedorDeSuelo.push_back(Vector2f(8, 12));
							//fila 13
							contenedorDeSuelo.push_back(Vector2f(7, 13));
							contenedorDeSuelo.push_back(Vector2f(8, 13));
							contenedorDeSuelo.push_back(Vector2f(9, 13));
							contenedorDeSuelo.push_back(Vector2f(10, 13));
							//Meta
							coordenadasParaGanar.x = 4;
							coordenadasParaGanar.y = 1;
							//ir al jugable
							nivel = 0;
							break;

						default:
							LevelMusic.stop();
							nivel = 1;
							nivelMaximoAlcanzado = 1;
							window.setView(window.getDefaultView());
							Screen = 1;
							break;
					};
					break;
				default:
					Screen = 1;
					break;
			};

			window.display();
		};
	};
};
bool startGame (int & startLevel, RenderWindow & window, int & lives) {

    view.reset(FloatRect(0, 0, 700, 600));


    Level lvl;

    switch (startLevel) {
    case 1:
        lvl.LoadFromFile("level1.tmx");
        break;
    case 2:
        lvl.LoadFromFile("level2.tmx");
        break;
    case 3:
        lvl.LoadFromFile("level3.tmx");
        break;
    }
    //lvl.LoadFromFile("level1.tmx");

    SoundBuffer coinBuffer;
    coinBuffer.loadFromFile("sounds/coin.wav");
    Sound coinSound;
    coinSound.setBuffer(coinBuffer);
    SoundBuffer deathBuffer;
    deathBuffer.loadFromFile("sounds/mariodie.wav");
    Sound deathSound;
    deathSound.setBuffer(deathBuffer);
    SoundBuffer stageBuffer;
    stageBuffer.loadFromFile("sounds/stage.wav");
    Sound stageSound;
    stageSound.setBuffer(stageBuffer);

    Image heroImage;
    heroImage.loadFromFile("images/mario.png");
    heroImage.createMaskFromColor(Color(255, 255, 255));
    Image easyEnemyImage;
    easyEnemyImage.loadFromFile("images/EasyEnemy.png");
    easyEnemyImage.createMaskFromColor(Color(255, 255, 255));
    Image coinImage;
    coinImage.loadFromFile("images/coin.png");
    coinImage.createMaskFromColor(Color(255, 255, 255));
    Image mediumEnemyImage;
    mediumEnemyImage.loadFromFile("images/MediumEnemy.png");
    mediumEnemyImage.createMaskFromColor(Color(255, 255, 255));
    Image movePlatformImage;
    movePlatformImage.loadFromFile("images/MovingPlatform.png");

    std::list<Entity*> entities;
    std::list<Entity*>::iterator it;
    std::list<Entity*>::iterator it2;

    std::vector<Object> e = lvl.GetObjects("EasyEnemy");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Enemy(easyEnemyImage, "EasyEnemy", lvl, e[i].rect.left, e[i].rect.top, 15, 25));
    }
    e = lvl.GetObjects("coin");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Coin(coinImage, "coin", lvl, e[i].rect.left, e[i].rect.top, 15, 15));
    }
    e = lvl.GetObjects("MediumEnemy");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Enemy(mediumEnemyImage, "MediumEnemy", lvl, e[i].rect.left, e[i].rect.top, 16, 24));
    }
    e = lvl.GetObjects("exit");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Exit(mediumEnemyImage, "exit", lvl, e[i].rect.left, e[i].rect.top, 16, 24));
    }
    e = lvl.GetObjects("fire");
    for (int i = 0; i < e.size(); i++) {
        entities.push_back(new Fire(mediumEnemyImage, "fire", lvl, e[i].rect.left, e[i].rect.top, 16, 24));
    }
    e = lvl.GetObjects("MovingPlatform");
    for (int i = 0; i < e.size(); i++)
        entities.push_back(new MovingPlatform(movePlatformImage, "MovingPlatform", lvl, e[i].rect.left, e[i].rect.top, 95, 22));

    Object player = lvl.GetObject("player");
    Player p(heroImage, "Player", lvl, player.rect.left, player.rect.top, 22, 38);

    Clock clock;

    while (window.isOpen())
    {

        float time = clock.getElapsedTime().asMicroseconds();

        clock.restart();
        time = time / 800;

        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        for (it = entities.begin(); it != entities.end();) {
            Entity *b = *it;
            b->update(time);
            if (b->life == false) {
                it = entities.erase(it);
                delete b;
            }
            else it++;
        }

        for (it = entities.begin(); it != entities.end(); it++) {
            if (((*it)->name == "MovingPlatform") && ((*it)->getRect().intersects(p.getRect())))
            {
                Entity *movPlat = *it;
                if (p.dy>0)
                    if (p.y + p.height < movPlat->y + movPlat->height)
                    {
                        p.y = movPlat->y - p.height + 3;
                        p.x += movPlat->dx*time;
                        p.dy = 0;
                        p.onGround = true;
                    }
            }
            if ((*it)->getRect().intersects(p.getRect())) {
                if ((*it)->name == "EasyEnemy" || (*it)->name == "MediumEnemy") {
                    if ((p.dy>0) && (p.onGround == false) && (p.y + p.height < (*it)->y + (*it)->height)) {
                        p.dy = -0.3;
                        (*it)->lives--;
                        if ((*it)->name == "EasyEnemy")
                            (*it)->sprite.setTextureRect(IntRect(60, 8, 16, 8));
                        p.Score++;
                    }
                    else {
                        if (((*it)->lives != 0)) {
                            deathSound.play();
                            p.lives--;
                            lives--;
                            return false;
                        }
                    }
                }
                if ((*it)->name == "fire") {
                    deathSound.play();
                    p.lives--;
                    lives--;
                    return false;
                }
                if ((*it)->name == "coin") {
                    p.Score++;
                    coinSound.play();
                    (*it)->life = false;
                }
                if ((*it)->name == "exit") {
                    stageSound.play();
                    startLevel++;
                    return false;
                }
            }
            for (it2 = entities.begin(); it2 != entities.end(); it2++) {
                if ((*it)->getRect() != (*it2)->getRect())
                    if (((*it)->getRect().intersects((*it2)->getRect())) && ((*it)->name == "EasyEnemy")) {
                        (*it)->dx *= -1;
                        (*it)->sprite.scale(-1.5, 1.5);
                    }
            }
        }
        p.update(time);



        if (Keyboard::isKeyPressed(Keyboard::Escape)) {
            lives = 0;
            return false;
        }

        window.setView(view);
        window.clear(Color(167, 207, 218));
        lvl.Draw(window);


        for (it = entities.begin(); it != entities.end(); it++) {
            window.draw((*it)->sprite);
        }

        window.draw(p.sprite);
        window.display();
    }

    return 0;

}
Esempio n. 9
0
void AmmoView::loadRessources()
{	
	if(textures.size() > 0)
		return;

	/* === TEXTURES === */
	Texture* tex;

	/* BULLET */
	tex = new Texture();
    tex->loadFromFile("res/tex/ammo/bullet.png");
    textures.push_back(tex);

    textures.push_back(NULL);
    textures.push_back(NULL);

    /* FLAME */
	tex = new Texture();
    tex->loadFromFile("res/tex/ammo/flame.png");
    textures.push_back(tex);
    
    textures.push_back(NULL);
    
    /* GRENADE */
	tex = new Texture();
    tex->loadFromFile("res/tex/ammo/grenade.png");
    textures.push_back(tex);
    
	
    /* === ANIMATIONS ===*/
    animations_list[BULLET] = loadAnimationsFromFile("res/xml/ammo/bullet.xml");
    animations_list[FLAME] = loadAnimationsFromFile("res/xml/ammo/flame.xml");
    animations_list[GRENADE] = loadAnimationsFromFile("res/xml/ammo/grenade.xml");
    

   
    /* === SONS === */

    /* BULLET */
	SoundBuffer* buffer = new SoundBuffer();
	buffer->loadFromFile("res/snd/ammo/bullet.wav");
    Sound* s = new Sound();
    s->setBuffer(*buffer);
    sounds.push_back(s);

    /* HEAVY_BULLET */
    buffer = new SoundBuffer();
	buffer->loadFromFile("res/snd/ammo/shotgun.wav");
    s = new Sound();
    s->setBuffer(*buffer);
    sounds.push_back(s);

    /* LIGHT_BULLET */
    sounds.push_back(NULL);

    /* FLAME */
    buffer = new SoundBuffer();
	buffer->loadFromFile("res/snd/ammo/flame.wav");
    s = new Sound();
    s->setBuffer(*buffer);
    sounds.push_back(s);

    /* ROCKET */
    sounds.push_back(NULL);

    /* GRENADE */
    buffer = new SoundBuffer();
	buffer->loadFromFile("res/snd/ammo/grenade.wav");
    s = new Sound();
    s->setBuffer(*buffer);
    sounds.push_back(s);

}
Esempio n. 10
0
int main()
{  
    RenderWindow window(VideoMode(800, 250), "Mario v0.1 Alpha");
	Texture tileSet;
	tileSet.loadFromFile("Mario_Tileset.png");

	//===========================
	PLAYER Mario(tileSet);
	//==========[Bot]============
	ENEMY  enemy[3];
	enemy[0].set(tileSet,48*16,13*16);//1lvl
	enemy[1].set(tileSet,110*16,13*16);
	enemy[2].set(tileSet,48*16,30*16);//2lvl
	/*enemy[3].set(tileSet,110*16,13*16);
	enemy[4].set(tileSet,48*16,13*16);//3lvl
	enemy[5].set(tileSet,110*16,13*16);*/
	//===========================
	Sprite tile(tileSet);
	SoundBuffer buffer;
	//==========[«вук]============
	buffer.loadFromFile("Jump.ogg");
	Sound sound(buffer);
	//==========[Ўрифты]==========
	sf::Font font;
	font.loadFromFile("arial.ttf");
	//==========[ћеню]============
	Texture menu_texture1,menu_texture2,menu_texture3,about_texture;
	menu_texture1.loadFromFile("111.png");
	menu_texture2.loadFromFile("222.png");
    menu_texture3.loadFromFile("333.png");
	about_texture.loadFromFile("about.png");
	Sprite menu1(menu_texture1),menu2(menu_texture2),menu3(menu_texture3),about(about_texture);
	if(NewGm==true) {
		NewGame:
		GameOver=false;
		Mario.rect.left=100; Mario.rect.top=180;
		Mario.sprite.setPosition(100, 180);  
		offsetX = Mario.rect.left-100; 
		enemy[0].life=true; enemy[1].life=true;
		offsetY = Mario.rect.top-180; 
		std::cout<<Mario.rect.left<<"   "<< Mario.rect.top<<std::endl;
		NewGm=false;
	}

	bool Menu=1;
	int MenuNum=0;
	menu1.setPosition(100,30);
	menu2.setPosition(100,90);
    menu3.setPosition(100,150);

	while(Menu)
	{	   
	   menu1.setColor(Color::White);
	   menu2.setColor(Color::White);
	   menu3.setColor(Color::White);
	   MenuNum=0;
	   window.clear(Color(0,0,0));

	   if (IntRect(100,30,300,50).contains(Mouse::getPosition(window))) {menu1.setColor(Color::Yellow); MenuNum=1;}
       if (IntRect(100,90,300,50).contains(Mouse::getPosition(window))) {menu2.setColor(Color::Yellow); MenuNum=2;}
       if (IntRect(100,150,300,50).contains(Mouse::getPosition(window))) {menu3.setColor(Color::Yellow); MenuNum=3;}

	   if (Mouse::isButtonPressed(Mouse::Left))
	     {
			 if (MenuNum==1) Menu=false;
			 if (MenuNum==2) {window.draw(about); window.display(); while(!Keyboard::isKeyPressed(Keyboard::Escape)) ;}
			 if (MenuNum==3)  {window.close();Menu=false;}

	     }
		window.draw(menu1);
        window.draw(menu2);
		window.draw(menu3);
		window.display();
	}
	//==========[¬рубаем музыку в игру]============
	Music music;
    music.openFromFile("Mario_Theme.ogg");
    music.play();
	//==================[»гра]=====================
	Clock clock;

    while (GameOver==false)
    { 
		float time = clock.getElapsedTime().asMicroseconds();
		clock.restart();
		time = time/500;
		if (time > 20) time = 20; 

        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == Event::Closed)      
                window.close();
		}
		if (Keyboard::isKeyPressed(Keyboard::Left)) Mario.dx=-0.1; 
	    if (Keyboard::isKeyPressed(Keyboard::Right)) Mario.dx=0.1;
	    if (Keyboard::isKeyPressed(Keyboard::Up)) if (Mario.onGround) { Mario.dy=-0.27; Mario.onGround=false;  sound.play(); }
	 
		 Mario.update(time);
		 enemy[0].update(time);
		 enemy[1].update(time);
		 enemy[2].update(time);

		 if  (Mario.rect.intersects(enemy[0].rect))
		 {
			 if (enemy[0].life) {
				 if (Mario.dy>0) { enemy[0].dx=0; Mario.dy=-0.2; enemy[0].life=false;}
				 else { Mario.dy=-0.27; GameOver=true; }
			 }
		 }
		 if  (Mario.rect.intersects(enemy[1].rect))
		 {
			 if (enemy[1].life) {
				 if (Mario.dy>0) { enemy[1].dx=0; Mario.dy=-0.2; enemy[1].life=false;}
				 else { Mario.dy=-0.27; GameOver=true; }
			 }
		 }
		 if  (Mario.rect.intersects(enemy[2].rect))
		 {
			 if (enemy[2].life) {
				 if (Mario.dy>0) { enemy[2].dx=0; Mario.dy=-0.2; enemy[2].life=false;}
				 else { Mario.dy=-0.27; GameOver=true; }
			 }
		 }
		 if (Mario.rect.left>200) offsetX = Mario.rect.left-200;
		 window.clear(Color(107,140,255));
		 for (int i=0; i<H; i++)
			 for (int j=0; j<W; j++)
			 { 
				switch(TileMap[i][j]) {
					case 'P':  tile.setTextureRect( IntRect(143-16*3,112,16,16)); break; 
					case 'k': tile.setTextureRect( IntRect(143,112,16,16)); break; 
					case 'c': tile.setTextureRect( IntRect(143-16,112,16,16)); break; 
					case 't': tile.setTextureRect( IntRect(0,47,32,95-47)); break; 
					case 'm': tile.setTextureRect( IntRect(96,6,202-47,111)); break; 
					case 'g': tile.setTextureRect( IntRect(0,16*9-5,3*16,16*2+5)); break; 
					case 'G': tile.setTextureRect( IntRect(145,222,222-145,255-222)); break; 
					case 'd': tile.setTextureRect( IntRect(0,106,74,127-106)); break; 
					case 'w': tile.setTextureRect( IntRect(99,224,140-99,255-224)); break; 
					case 'r': tile.setTextureRect( IntRect(143-32,112,16,16)); break; 
					default: continue;
				}

  			    tile.setPosition(j*16-offsetX,i*16 - offsetY) ; 
		        window.draw(tile);
			}
		window.draw(Mario.sprite);
	    window.draw(enemy[0].sprite);
		window.draw(enemy[1].sprite);
		window.draw(enemy[2].sprite);
		window.display();
    }
	while(Win)
	{	
		GameOver=false;
		window.clear(Color(0,0,0));
		sf::Text text("You Win! :3", font); 
		text.setPosition(100,30);
		text.setCharacterSize(30);
		text.setStyle(sf::Text::Bold);
		text.setColor(sf::Color::Yellow);
		window.draw(text);	
		sf::Text text1("Press ESC", font); 
		text1.setPosition(100,60);
		text1.setCharacterSize(30);
		text1.setStyle(sf::Text::Bold);
		text1.setColor(sf::Color::Red);
		window.draw(text1);	
		window.display();
		if (Keyboard::isKeyPressed(Keyboard::Escape)) { goto NewGame; NewGm=true; }
	}
	while(GameOver)
	{	   
		window.clear(Color(0,0,0));
		sf::Text text("Game Over :c", font); 
		text.setPosition(100,30);
		text.setCharacterSize(30);
		text.setStyle(sf::Text::Bold);
		text.setColor(sf::Color::Red);
		window.draw(text);	
		sf::Text text1("Press ESC", font); 
		text1.setPosition(100,60);
		text1.setCharacterSize(30);
		text1.setStyle(sf::Text::Bold);
		text1.setColor(sf::Color::Red);
		window.draw(text1);	
		window.display();
		if (Keyboard::isKeyPressed(Keyboard::Escape)) { goto NewGame; NewGm=true; }
	}
    return 0;
}
Esempio n. 11
0
void mainLevel(RenderWindow &window)
{
	//>>>>>>>>>>>>>>>---Level---<<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Level lvl;
	 lvl.LoadFromFile("map.tmx");

	//>>>>>>>>>>>>>>>>---Load basic image for level1----<<<<<<<<<<<<<<<<<
	Texture texture;
	texture.loadFromFile("images/level1empty.jpg");
	Sprite level(texture);

	Texture texture2; 
	texture2.loadFromFile("images/levelShad.png");
	Sprite level2(texture2);

	Texture texture3;
	texture3.loadFromFile("images/level12.png");
	Sprite level3(texture3);
	//>>>>>>>>>>>>>>>>---Music---<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Music mainSong;
	 mainSong.openFromFile("music/level1.ogg");
	 mainSong.play();
	 mainSong.setLoop(true);
	 mainSong.setVolume(75);

	 //>>>>>>>>>>>>>>>>---Create a cat---<<<<<<<<<<<<<<<<<<<
	 Object player = lvl.GetObject("cat");
	 Player cat("cat.png", lvl, player.rect.left, player.rect.top, 60, 120, 55, 25);
	 Clock clock;

	 //>>>>>>>>>>>>>>>>---Sounds----<<<<<<<<<<<<<<<<<<<
	SoundBuffer buf1, buf2;
	buf1.loadFromFile("music/meow1.ogg");
	buf2.loadFromFile("music/meow2.ogg");
	Sound meow1, meow2;
	meow1.setBuffer(buf1);
	meow2.setBuffer(buf2);

	SoundBuffer buf;
	buf.loadFromFile("music/steklo.ogg");
	Sound glass;
	glass.setBuffer(buf); glass.setVolume(100);

	 //Objects
	 Furniture posters("tayles1.png",  160, 660, 210, 250, 280, 215);
	 Furniture bed("tayles1.png", 420, 80, 280, 310, 250, 440);
	 Furniture toys("tayles1.png", 120, 470, 180, 150, 220, 545);
	 Furniture upShelf("tayles1.png", 700, 652.5, 120, 97.5, 350, 83);
	 Furniture cabinet("tayles1.png", 75, 40, 250, 350, 605, 305);
	 Furniture mop("tayles1.png", 515, 785, 165, 241, 587, 385);
	 Furniture flower("tayles1.png",780, 65, 170, 330, 147, 285);
	 Furniture ball("tayles1.png", 905, 615, 40, 55, 357, 190);
	 Furniture books("tayles1.png", 860, 735, 125, 80, 290, 187);
	 Furniture brokenBall("tayles1.png",920, 540, 90, 42, 430, 430);
	 
	 Furniture door("tayles2.png", 0, 560, 80, 340, 870, 350);
	 Furniture brokenLight("tayles2.png", 10, 110, 50, 70, 795, 430);
	 Furniture light("tayles2.png", 20, 20, 35, 70, 220, 565);
	 Furniture bath("tayles2.png", 80, 50, 320, 380, 1010, 330);
	 Furniture carpet("tayles2.png", 100, 500, 100, 140, 870, 530);
	 Furniture mirror("tayles2.png", 90, 700, 110, 290, 1200, 300);
	 Furniture sink("tayles2.png", 290, 440, 150, 240, 1190, 450);
	 int cntMeow = 0;
	 Object ob = lvl.GetObject("catPlace");
	  while (window.isOpen())
    {
		
		float time = clock.getElapsedTime().asMicroseconds();
		clock.restart();
		time = time/500;
		Vector2i pos = Mouse::getPosition(window);

        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

			if (event.type == Event::MouseButtonPressed){
					if (event.key.code == Mouse::Left)
					{
						int cntMeow = meow(meow1, meow2, cat, pos);
						//>>>>>>BALL<<<<<<<<<<<<<<
						if(cat.sprite.getGlobalBounds().intersects(ob.rect))
						{
							if(cntMeow == -1)
							{
								ball.falling(event, window, pos, lvl, time);
								glass.play();
								ball.moving(event, window, pos, "ball", lvl);
							}
						}
						cat.clickedThings(window, light);
						//BOOKS>>>>----<<<<<<
						if(books.isPlayed == false)
						{
							if (books.sprite.getGlobalBounds().contains(pos.x, pos.y))
							{
								mainSong.pause();
								MiniGame_Books();
								books.isPlayed = true;
								mainSong.play();
							}
						}

					}
			}		
					
					toys.moving(event, window, pos, "toys", lvl);
					if(light.isPlayed == false)
						light.moving(event, window, pos, "light", lvl);
					

	
        }
		
		

		cat.Update(time);

		window.clear(Color::Black);
		lvl.Draw(window);
		if(cat.room == 0)
			window.draw(level);
		if(cat.room == 1)
			window.draw(level2); 
		if(cat.room == 2)
			window.draw(level3);
			
		window.draw(posters.sprite);
		window.draw(bed.sprite);
		window.draw(light.sprite);
		window.draw(toys.sprite);
		window.draw(upShelf.sprite);
		window.draw(cabinet.sprite);
		window.draw(mop.sprite);
		window.draw(flower.sprite);
		if(ball.isPlayed == false)
			window.draw(ball.sprite);
		else
			window.draw(brokenBall.sprite);
		window.draw(books.sprite);



		if(cat.room == 2){
			window.draw(bath.sprite);
			window.draw(mirror.sprite);
			window.draw(sink.sprite);
		}

		if(cat.room == 1 || cat.room == 2){
			if(light.isPlayed == false)
			window.draw(brokenLight.sprite);
			window.draw(carpet.sprite);
			window.draw(door.sprite);
		}
		

		window.draw(cat.sprite);
		
		window.display();
    }

}
Esempio n. 12
0
void SoundHandler::initializeSounds()
{
	criticalTimer = new Clock();
	messageTimer = new Clock();
	soundTimer = new Clock();
	spellTimer = new Clock();
	urgentTimer = new Clock();
	
	criticalSound = new Sound();
	genericSound = new Sound();
	message = new Sound();
	spellSound = new Sound();
	urgentSound = new Sound();


	SoundBuffer* buffer;
	Music* music;
	string name;

	sounds.push_back("gold_drop_1");
	sounds.push_back("gold_drop_2");
	sounds.push_back("gold_drop_3");
	sounds.push_back("imp_mine_1");
	sounds.push_back("imp_mine_2");
	sounds.push_back("imp_mine_3");
	sounds.push_back("imp_mine_4");
	sounds.push_back("imp_mine_5");
	sounds.push_back("imp_mine_6");
	sounds.push_back("imp_spawn");
	sounds.push_back("imp_step_1");
	sounds.push_back("imp_step_2");
	sounds.push_back("imp_step_3");
	sounds.push_back("imp_step_4");
	sounds.push_back("option_failure");
	sounds.push_back("option_select_1");
	sounds.push_back("option_select_2");
	sounds.push_back("tile_build");
	sounds.push_back("tile_cave-in_1");
	sounds.push_back("tile_cave-in_2");
	sounds.push_back("tile_cave-in_3");
	sounds.push_back("tile_select");
	sounds.push_back("tile_sell");
	sounds.push_back("voice_bigger_treasury");
	sounds.push_back("voice_game_saved");
	sounds.push_back("voice_game_loaded");
	sounds.push_back("voice_need_treasury");
	sounds.push_back("voice_tunneled_new_area");

	int length = sounds.size();

	for (int i = 0; i < length; i++)
	{
		buffer = new SoundBuffer();
		name = sounds[i];
		buffer->loadFromFile("Resources/" + name + ".ogg");
		soundMap[name] = buffer;
	}

	songs.push_back("game_music");
	songs.push_back("menu_music");
	length = songs.size();

	for (int i = 0; i < length; i++)
	{
		music = new Music();
		name = songs[i];
		music->openFromFile("Resources/" + name + ".ogg");
		musicMap[name] = music;
	}
}
Esempio n. 13
0
void EnemyView::loadRessources(TypeEnemy t)
{
	if(textures[t] != NULL)
		return;

	/* REBEL */
	if(t == REBEL)
	{
		// TEXTURE
		Texture* tex = new Texture();
	    tex->loadFromFile("res/tex/enemy/rebel.png");
	    textures[REBEL] = tex;

	    // ANIMATION
	    animations_list[REBEL] = loadAnimationsFromFile("res/xml/enemy/rebel.xml");

	    // SOUNDS
	    SoundBuffer* buffer;

	    buffer = new SoundBuffer;
		buffer->loadFromFile("res/snd/enemy/rebel/death1.wav"); // DEATH
	    sounds_buffers[REBEL].push_back(buffer);

	    buffer = new SoundBuffer;
		buffer->loadFromFile("res/snd/enemy/rebel/death2.wav"); // DEATH2
	    sounds_buffers[REBEL].push_back(buffer); 

	    buffer = new SoundBuffer;
		buffer->loadFromFile("res/snd/enemy/rebel/death3.wav"); // DEATH3
	    sounds_buffers[REBEL].push_back(buffer); 
	}

	/* BOWSER */
	else if(t == BOWSER)
	{
		// TEXTURE
		Texture* tex = new Texture();
	    tex->loadFromFile("res/tex/enemy/bowser.png");
	    textures[BOWSER] = tex;

	    // ANIMATION
	    animations_list[BOWSER] = loadAnimationsFromFile("res/xml/enemy/bowser.xml");

	    // SOUNDS
	    SoundBuffer* buffer;

	    buffer = new SoundBuffer;
		buffer->loadFromFile("res/snd/enemy/bowser/death.wav"); // DEATH
	    sounds_buffers[BOWSER].push_back(buffer);

	    buffer = new SoundBuffer;
		buffer->loadFromFile("res/snd/enemy/bowser/death2.wav"); // DEATH2
	    sounds_buffers[BOWSER].push_back(buffer);
	}

	/* FLYING */
	else if(t == FLYING)
	{
		// TEXTURE
		Texture* tex = new Texture();
	    tex->loadFromFile("res/tex/enemy/flying.png");
	    textures[FLYING] = tex;

	    // ANIMATION
	    animations_list[FLYING] = loadAnimationsFromFile("res/xml/enemy/flying.xml");

	    // SOUNDS
	    SoundBuffer* buffer;

	    buffer = new SoundBuffer;
		buffer->loadFromFile("res/snd/enemy/flying/death.wav"); // DEATH
	    sounds_buffers[FLYING].push_back(buffer);
	}
}