예제 #1
0
void finish()
{
	RenderWindow window(VideoMode(500,500),"", Style::None);
	Texture text;
	text.loadFromFile("images/finish.png");
	Sprite finish; finish.setTexture(text);
	Music music;
	music.openFromFile("music/finish.ogg");
	music.play();
	
	while(window.isOpen())
    {
		Event event;
		while (window.pollEvent(event))
		{
			if(IntRect(420,461,57,36).contains(Mouse::getPosition(window)))
				{
					if(Mouse::isButtonPressed(Mouse::Left))
					{
						music.stop();
						window.close();
					}
			}

		}
		window.clear();
		window.draw(finish);
		window.display();
	 }
}
void HelpScreen::processLevelTick(unsigned int millisElapsed) {
	Music *music = (Music*) ResourcesManager::getResource("MenuMusic");
	ButtonItem *backButton = (ButtonItem*) userInterface->getItem("ZBackButton");
	if (backButton->isPressed()) {
		music->stop(500);
		userInterface->startFadeOut(200);
		actionAfterFade = 1;
	}
	if (actionAfterFade > 0 && !userInterface->isFading()) {
		GameMenu *menu = new GameMenu();
		GameApp::getInstance()->setCurrentLevel(menu);
	}

	Level::processLevelTick(millisElapsed);
}
예제 #3
0
void menu(RenderWindow &window)
 {
	 Texture menuText1, menuText2, menuText3, menuBackground;
	 menuBackground.loadFromFile("images/menu1.jpg");
	 menuText2.loadFromFile("images/cat.jpg");
	 Sprite menuLoad(menuText2);
	 Sprite menuBg(menuBackground);
	 bool isMenu = 1;
	 int menuNum = 0;
	 menuBg.setPosition(0,0);
	 Music music;
	 music.openFromFile("music/menu.ogg");
	 music.play();

	 Font font;
	 font.loadFromFile("dumb.ttf");
	 Text text("", font, 38); text.setStyle(Text::Bold);
	 Text text2("", font, 38); text2.setStyle(Text::Bold);
	 Text text3("", font, 38); text3.setStyle(Text::Bold);
	 text.setString("New Game");
	 text2.setString("Load");
	 text3.setString("Exit");
	 text.setPosition(485, 410);
	 text2.setPosition(550, 450);
	 text3.setPosition(550,568);


	 while(isMenu)
	 {
		text.setColor(Color(254,150,121));
		text2.setColor(Color(254,150,121));
		text3.setColor(Color(254,150,121));
		menuNum = 0;

		 window.clear(Color(129,181,221));
		 //New Game
		 if(IntRect(500,410,200,60).contains(Mouse::getPosition(window)))
		 {
			 text.setColor(Color(98,198,223));
			 menuNum = 1;
		 }
		 //Load Game
		 if(IntRect(550,488,200,60).contains(Mouse::getPosition(window)))
		 {
			 text2.setColor(Color(98,198,223));
			 menuNum = 2;
		 }
		 //Exit
		 if(IntRect(500,564,200,60).contains(Mouse::getPosition(window)))
		 {
			 text3.setColor(Color(98,198,223));
			 menuNum = 3;
		 }


		if(Mouse::isButtonPressed(Mouse::Left))
		{
			if(menuNum == 1)
			{
				music.stop();
				return;
			}
			if(menuNum == 2)
			{
				window.draw(menuLoad);
				window.display();
				while(!Keyboard::isKeyPressed(Keyboard::Escape))
				{;}
			}
			if(menuNum == 3)
			{
				music.stop();
				window.close();
				isMenu = false;
			}
		}
		 window.draw(menuBg);
		 window.draw(text);
		 window.draw(text2);
		 window.draw(text3);
		 window.display();
	 }
 }
예제 #4
0
void Menu::menu(RenderWindow & app, int width, int height) {
	bool musicIsPlaying = true;
	Music music;
	music.openFromFile("sounds/menuMusic.ogg");
	music.setLoop(true);

	Texture menuTexture1, menuTexture2, menuTexture3, aboutTexture, menuBackground;
	menuTexture1.loadFromFile("images/StartGame.png");
	menuTexture2.loadFromFile("images/LeaderBoard.png");
	menuTexture3.loadFromFile("images/exit.png");
	menuBackground.loadFromFile("images/menu.png");
	Sprite menu1(menuTexture1), menu2(menuTexture2), menu3(menuTexture3), menuBg(menuBackground);
	bool isMenu = 1;
	int menuNum = 0;
	menu1.setPosition(400, 300);
	menu2.setPosition(400, 375);
	menu3.setPosition(400, 450);
	menuBg.setPosition(0, 0);

	while (isMenu)
	{
		if (musicIsPlaying)
		{
			music.play();
			musicIsPlaying = false;
		}

		menu1.setColor(Color::White);
		menu2.setColor(Color::White);
		menu3.setColor(Color::White);
		menuNum = 0;
		app.clear(Color(129, 181, 221));

		if (IntRect(400, 300, 300, 50).contains(Mouse::getPosition(app))) 
		{ 
			menu1.setColor(Color::Blue); 
			menuNum = 1; 
		}
		if (IntRect(400, 375, 300, 50).contains(Mouse::getPosition(app))) 
		{
			menu2.setColor(Color::Blue); 
			menuNum = 2; 
		}
		if (IntRect(400, 450, 300, 50).contains(Mouse::getPosition(app))) 
		{
			menu3.setColor(Color::Blue); 
			menuNum = 3; 
		}

		if (Mouse::isButtonPressed(Mouse::Left))
		{
			if (menuNum == 1)
			{
				music.stop();
				const char * filename = "score.txt";
				isMenu = false;
				Game * game = new Game(width, height);
				int score = game->run(app);
				int prevScore;
				ifstream scoreFile;
				scoreFile.open(filename);
				scoreFile >> prevScore;
				scoreFile.close();
				if (score > prevScore)
				{
					ofstream scoreFile;
					scoreFile.open(filename);
					scoreFile << score;
					scoreFile.close();
				}
				isMenu = true;
			}
			//if (menuNum == 2) { window.draw(about); window.display(); while (!Keyboard::isKeyPressed(Keyboard::Escape)); }
			if (menuNum == 3) 
			{ 
				app.close(); isMenu = false; 
			}
			musicIsPlaying = true;
		}

		app.draw(menuBg);
		app.draw(menu1);
		app.draw(menu2);
		app.draw(menu3);
		printTopScore(app);
		app.display();
	}
예제 #5
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();
		};
	};
};
예제 #6
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;
	 Music skyrim, muse, bathMus;
	 bathMus.openFromFile("music/bath.ogg");
	 Object mus = lvl.GetObject("muse");
	 muse.openFromFile("music/synd.ogg"); muse.setVolume(100);
	 skyrim.openFromFile("music/skyrim.ogg"); skyrim.setVolume(100);
	 mainSong.openFromFile("music/level1.ogg");
	 mainSong.play();
	 mainSong.setLoop(true);
	 mainSong.setVolume(75);

	 //>>>>>>>>>>>>>>>>---Create a cat---<<<<<<<<<<<<<<<<<<<
	 Object player = lvl.GetObject("cat");
	 Object fish = lvl.GetObject("fish");
	 Object mo = lvl.GetObject("mouse");
	 Object ob = lvl.GetObject("catPlace");


	 Player cat("cat.png", lvl, 68, 429, 60, 120, player.rect.left,  player.rect.top, ELSE);
	 
	 Clock clock;
	 Clock gameTimeClock;
	 int sinkCnt = 0;

	 //>>>>>>>>>>>>>>>>---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, buf3;
	buf.loadFromFile("music/steklo.ogg");
	buf3.loadFromFile("music/mouse.ogg");
	Sound glass; Sound mouseS;
	glass.setBuffer(buf); glass.setVolume(100);
	mouseS.setBuffer(buf3);
	
	 //Objects
	 Furniture posters("tayles1.png",  160, 660, 210, 250, 280, 215, POSTERS);
	 Furniture bed("tayles1.png", 420, 80, 280, 310, 250, 440, ELSE); 
	 Furniture toys("tayles1.png", 120, 470, 180, 150, 220, 545, TOYS);
	 Furniture upShelf("tayles1.png", 700, 652.5, 120, 97.5, 350, 83, SHELF);
	 Furniture cabinet("tayles1.png", 75, 40, 250, 350, 605, 305, CABINET); 
	 Furniture mop("tayles1.png", 515, 785, 165, 241, 587, 385, MOP); 
	 Furniture flower("tayles1.png",780, 65, 170, 330, 147, 285, ELSE);
	 Furniture ball("tayles1.png", 905, 615, 40, 55, 357, 190, BALL); 
	 Furniture books("tayles1.png", 860, 735, 125, 80, 290, 187, BOOKS); 
	 Furniture brokenBall("tayles1.png",920, 540, 90, 42, 430, 430, ELSE); 
	 Furniture key("tayles1.png", 1, 1, 25, 25, 430, 425, KEY);
	 Furniture cabinetEnd("cabinet.png", 20, 50, 270, 350, 590, 290, ELSE); 
	 Furniture girl("girlHair.png", 1,1, 96, 45, 1075, 350, ELSE);
	 
	 Furniture door("tayles2.png", 0, 560, 80, 340, 870, 350, ELSE);
	 Furniture puddle("tayles1.png",789, 1000, 204, 75, 1057, 559, ELSE);
	 Furniture brokenLight("tayles2.png", 10, 110, 50, 70, 795, 430, ELSE);
	 Furniture light("tayles2.png", 20, 20, 35, 70, 220, 565, ELSE);
	 Furniture bath("tayles2.png", 80, 50, 320, 380, 1010, 330, BATH);
	 Furniture openBath("bathr.png", 264, 79, 339, 369, 1015, 315, ELSE);
	 Furniture carpet("tayles2.png", 100, 500, 100, 140, 870, 530, ELSE);
	 Furniture mirror("tayles2.png", 90, 700, 110, 290, 1200, 300, ELSE);
	 Furniture sink("tayles2.png", 290, 440, 150, 240, 1190, 450, SINK);
	 Furniture sinkWater("bathr.png", 22, 180, 197, 427, 1200, 540, ELSE);
	 Furniture mou("mouse.png",  2, 21, 32, 25, mo.rect.left, mo.rect.top, ELSE);
	 
	 
	 std::list<Furniture> fList;
	 std::list<Furniture>::iterator it;
	 fList.push_back(posters);
	 fList.push_back(toys);
	 fList.push_back(upShelf);
	 fList.push_back(cabinet);
	 fList.push_back(mop);
	 fList.push_back(ball);
	 fList.push_back(books);
	 fList.push_back(key);
	 fList.push_back(puddle);
	 fList.push_back(brokenLight);
	 fList.push_back(bath);
	 fList.push_back(sink);
	 for(it = fList.begin(); it != fList.end(); it++){
		 it->setSub((void *)&it, writeMess);
	 }

	 int cntMeow = 1, cntGame = 0, click = 0, clickBath = 1, clickSink = 1;
	 bath.isPlayed = true;
	 sink.isPlayed = true;


	  while (window.isOpen())
    {
		
		float time = clock.getElapsedTime().asMicroseconds();
		float sinkTime = gameTimeClock.getElapsedTime().asSeconds();
		if(clickSink < 2)
			gameTimeClock.restart();
		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){

					if (fish.rect.contains(pos.x, pos.y) && key.isPlayed == true){
						mainSong.stop();
						finish();
						window.close();
					}
					if (cat.sprite.getGlobalBounds().contains(pos.x, pos.y))
					{
						cntMeow++;
						if(cntMeow == 5)
						{
							meow2.play();
							cntMeow = 0;
						}
						else
							meow1.play();
					}
					 
					toys.trueMove(pos);
					if(light.isPlayed == false) light.trueMove(pos);
					if(ball.isPlayed == true && books.isPlayed == true) key.trueMove(pos);
					if(puddle.isPlayed == true) mop.trueMove(pos);
					click = light.clickedThings(pos);
					clickBath = bath.clickedThings(pos);
					clickSink = sink.clickedThings(pos);


					if (upShelf.sprite.getGlobalBounds().contains(pos.x, pos.y)){
						skyrim.play();
					}
					if (mus.rect.contains(pos.x, pos.y)){
						muse.play();
					}
					if (girl.sprite.getGlobalBounds().contains(pos.x, pos.y) && cat.room == 2){
						mainSong.pause();
						gameOver();
						mainSong.play();
					}
					if(mou.isPlayed == false)
						{
							if (mou.sprite.getGlobalBounds().contains(pos.x, pos.y))
							{
								mainSong.pause();
								mouseS.play();
								//gameRunning();
								mou.isPlayed = true;
								mainSong.play();
							}
						}

						if(books.isPlayed == false)
						{
							if (books.sprite.getGlobalBounds().contains(pos.x, pos.y))
							{
								mainSong.pause();
								MiniGame_Books();
								books.isPlayed = true;
								mainSong.play();
							}
						}
				}
					
			if (event.type == Event::MouseButtonReleased)
				if (event.key.code == Mouse::Left){
					toys.isMove = false;
					key.isMove = false;
					if(light.isPlayed == false) light.isMove = false;
					 mop.isMove = false;
				}
		}
		if(sinkTime > 5 && clickSink == 2) puddle.isPlayed = true;

		if(clickBath == 2 && cat.room == 2)
			bathMus.play();

		if(click == -1){}
		else if(click == 1 || click == 2)
			cat.room = click;
		toys.intersect("toys",lvl); toys.move(pos); 
		if(mop.isPlayed == false)
		{
			mop.intersect("mop", lvl);
			mop.move(pos);
		}
		if(light.isPlayed == false) 
		{
			light.intersect("light", lvl);
			light.move(pos);
		}
		if(ball.isPlayed == true && books.isPlayed == true){
			if(mop.isPlayed == true)
				key.intersect("key", lvl);
			if(key.isPlayed == false)
				key.move(pos);
		}
		if(ball.isPlayed == false && books.isPlayed == true){
			if(cat.sprite.getGlobalBounds().intersects(ob.rect))
			{
				if(cntMeow == 0)
				{
					ball.falling(event, window, pos, lvl, time);
					glass.play();
					ball.isPlayed = true;
					ball.intersect("ball", 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);
		if(key.isPlayed == true)
			window.draw(cabinetEnd.sprite);
		else
			window.draw(cabinet.sprite);
		window.draw(upShelf.sprite);
		window.draw(flower.sprite);
		if(ball.isPlayed == false)
			window.draw(ball.sprite);
		else
		{
			window.draw(brokenBall.sprite);
			window.draw(key.sprite);
		}
		window.draw(books.sprite);

		
		if(mou.isPlayed == false){
			window.draw(mou.sprite);
		}
		else
			window.draw(light.sprite);
		window.draw(toys.sprite);


		if(cat.room == 2){
				
			 if(clickBath == 2){
				window.draw(girl.sprite);
				window.draw(openBath.sprite);
			 }
			 else
				 window.draw(bath.sprite);
			window.draw(mirror.sprite);

			 if(clickSink == 2)
				window.draw(sinkWater.sprite);
			 else
				 window.draw(sink.sprite);

			 if(puddle.isPlayed == true && mop.isPlayed == false)
				window.draw(puddle.sprite);
		}

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

		for(it = fList.begin(); it != fList.end(); it++)
			{
				if(it->sprite.getGlobalBounds().contains(pos.x, pos.y))
				{
					if(it->f.cb_fn != NULL)
					{
						cb_fn fn;
						fn = (cb_fn)it->f.cb_fn;
						fn(&window, it->type, &pos);
					}
				}
			}
		
		window.display();
    }

}
void HelpScreen::onFinish() {
	Music *music = (Music*) ResourcesManager::getResource("MenuMusic");
	Sound::stopAllSfx();
	music->stop(0);
}