Exemple #1
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();
		};
	};
};
Exemple #2
0
void RosalilaInputs::loadFromXML(int jugador,Receiver* receiver)
{
    this->jugador=jugador;
    this->receiver=receiver;
    this->inteligencia_artificial=false;
    string xml_path=assets_directory+"misc/inputs.xml";
    TiXmlDocument doc_t(xml_path.c_str());
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;

    std::vector<Boton> botones_temp;
    for(TiXmlNode* input=doc->FirstChild("Input");
            input!=NULL;
            input=input->NextSibling("Input"))
    {
        if(jugador==atoi(input->ToElement()->Attribute("player")))
        {
            //Key
            if(strcmp("keyboard",input->ToElement()->Attribute("type"))==0)
            {
                for(TiXmlNode* boton=input->FirstChild("button");
                        boton!=NULL;
                        boton=boton->NextSibling("button"))
                {
                    int key=0;
                    if(boton->ToElement()->Attribute("input")[0]=='Q' || boton->ToElement()->Attribute("input")[0]=='q')
                        key=SDLK_q;
                    if(boton->ToElement()->Attribute("input")[0]=='W' || boton->ToElement()->Attribute("input")[0]=='w')
                        key=SDLK_w;
                    if(boton->ToElement()->Attribute("input")[0]=='E' || boton->ToElement()->Attribute("input")[0]=='e')
                        key=SDLK_e;
                    if(boton->ToElement()->Attribute("input")[0]=='R' || boton->ToElement()->Attribute("input")[0]=='r')
                        key=SDLK_r;
                    if(boton->ToElement()->Attribute("input")[0]=='T' || boton->ToElement()->Attribute("input")[0]=='t')
                        key=SDLK_t;
                    if(boton->ToElement()->Attribute("input")[0]=='Y' || boton->ToElement()->Attribute("input")[0]=='y')
                        key=SDLK_y;
                    if(boton->ToElement()->Attribute("input")[0]=='U' || boton->ToElement()->Attribute("input")[0]=='u')
                        key=SDLK_u;
                    if(boton->ToElement()->Attribute("input")[0]=='I' || boton->ToElement()->Attribute("input")[0]=='i')
                        key=SDLK_i;
                    if(boton->ToElement()->Attribute("input")[0]=='O' || boton->ToElement()->Attribute("input")[0]=='o')
                        key=SDLK_o;
                    if(boton->ToElement()->Attribute("input")[0]=='P' || boton->ToElement()->Attribute("input")[0]=='p')
                        key=SDLK_p;
                    if(boton->ToElement()->Attribute("input")[0]=='A' || boton->ToElement()->Attribute("input")[0]=='a')
                        key=SDLK_a;
                    if(boton->ToElement()->Attribute("input")[0]=='S' || boton->ToElement()->Attribute("input")[0]=='s')
                        key=SDLK_s;
                    if(boton->ToElement()->Attribute("input")[0]=='D' || boton->ToElement()->Attribute("input")[0]=='d')
                        key=SDLK_d;
                    if(boton->ToElement()->Attribute("input")[0]=='F' || boton->ToElement()->Attribute("input")[0]=='f')
                        key=SDLK_f;
                    if(boton->ToElement()->Attribute("input")[0]=='G' || boton->ToElement()->Attribute("input")[0]=='g')
                        key=SDLK_g;
                    if(boton->ToElement()->Attribute("input")[0]=='H' || boton->ToElement()->Attribute("input")[0]=='h')
                        key=SDLK_h;
                    if(boton->ToElement()->Attribute("input")[0]=='J' || boton->ToElement()->Attribute("input")[0]=='j')
                        key=SDLK_j;
                    if(boton->ToElement()->Attribute("input")[0]=='K' || boton->ToElement()->Attribute("input")[0]=='k')
                        key=SDLK_k;
                    if(boton->ToElement()->Attribute("input")[0]=='L' || boton->ToElement()->Attribute("input")[0]=='l')
                        key=SDLK_l;
                    if(boton->ToElement()->Attribute("input")[0]=='Z' || boton->ToElement()->Attribute("input")[0]=='z')
                        key=SDLK_z;
                    if(boton->ToElement()->Attribute("input")[0]=='X' || boton->ToElement()->Attribute("input")[0]=='x')
                        key=SDLK_x;
                    if(boton->ToElement()->Attribute("input")[0]=='C' || boton->ToElement()->Attribute("input")[0]=='c')
                        key=SDLK_c;
                    if(boton->ToElement()->Attribute("input")[0]=='V' || boton->ToElement()->Attribute("input")[0]=='v')
                        key=SDLK_v;
                    if(boton->ToElement()->Attribute("input")[0]=='B' || boton->ToElement()->Attribute("input")[0]=='b')
                        key=SDLK_b;
                    if(boton->ToElement()->Attribute("input")[0]=='N' || boton->ToElement()->Attribute("input")[0]=='n')
                        key=SDLK_n;
                    if(boton->ToElement()->Attribute("input")[0]=='M' || boton->ToElement()->Attribute("input")[0]=='m')
                        key=SDLK_m;
                    botones_temp.push_back(Boton(receiver,key,std::string(boton->ToElement()->Attribute("map"))));
                }
            }
            //Joy
            if(strcmp("joystick",input->ToElement()->Attribute("type"))==0)
            {
                for(TiXmlNode* boton=input->FirstChild("button");
                        boton!=NULL;
                        boton=boton->NextSibling("button"))
                {
                    int int_boton;
                    if(strcmp(boton->ToElement()->Attribute("input"),"up")==0)
                        int_boton=-8;
                    else if(strcmp(boton->ToElement()->Attribute("input"),"down")==0)
                        int_boton=-2;
                    else if(strcmp(boton->ToElement()->Attribute("input"),"left")==0)
                        int_boton=-4;
                    else if(strcmp(boton->ToElement()->Attribute("input"),"right")==0)
                        int_boton=-6;
                    else
                        int_boton=boton->ToElement()->Attribute("input")[0]-48;
                    botones_temp.push_back(Boton(receiver,int_boton,input->ToElement()->Attribute("joystick_number")[0]-48,boton->ToElement()->Attribute("map")));
                }
            }
        }
    }

    tecla_arriba=true;
    for(int i=0;i<20;i++)
        buffer_inputs.push_back("5");
    for(int i=0;i<20;i++)
        printable_buffer_inputs.push_back("5");
    for(int i=0;i<(int)botones_temp.size();i++)
    {
        if(botones_temp[i].getMapeo()=="2" || botones_temp[i].getMapeo()=="4" || botones_temp[i].getMapeo()=="6" || botones_temp[i].getMapeo()=="8")
        {
            this->cruz.push_back(botones_temp[i]);
        }
        else
        {
            this->botones.push_back(botones_temp[i]);
        }
    }
}
Exemple #3
0
void Input::cargarDesdeXML(int jugador,Receiver* receiver)
{
    this->jugador=jugador;
    this->receiver=receiver;
    this->inteligencia_artificial=false;
    TiXmlDocument doc_t((char*)"misc/inputs.xml");
    doc_t.LoadFile();
    TiXmlDocument *doc;
    doc=&doc_t;

    vector<Boton> botones;
    for(TiXmlNode* input=doc->FirstChild("Input");
            input!=NULL;
            input=input->NextSibling("Input"))
    {
        if(jugador==atoi(input->ToElement()->Attribute("player")))
        {
            //Key
            if(strcmp("keyboard",input->ToElement()->Attribute("type"))==0)
            {
                for(TiXmlNode* boton=input->FirstChild("button");
                        boton!=NULL;
                        boton=boton->NextSibling("button"))
                {
                    botones.push_back(Boton(receiver,(irr::EKEY_CODE)boton->ToElement()->Attribute("input")[0],stringw(boton->ToElement()->Attribute("map"))));
                }
            }
            //Joy
            if(strcmp("joystick",input->ToElement()->Attribute("type"))==0)
            {
                for(TiXmlNode* boton=input->FirstChild("button");
                        boton!=NULL;
                        boton=boton->NextSibling("button"))
                {
                    int int_boton;
                    if(strcmp(boton->ToElement()->Attribute("input"),"up")==0)
                        int_boton=-8;
                    else if(strcmp(boton->ToElement()->Attribute("input"),"down")==0)
                        int_boton=-2;
                    else if(strcmp(boton->ToElement()->Attribute("input"),"left")==0)
                        int_boton=-4;
                    else if(strcmp(boton->ToElement()->Attribute("input"),"right")==0)
                        int_boton=-6;
                    else
                        int_boton=boton->ToElement()->Attribute("input")[0]-48;
                    botones.push_back(Boton(receiver,int_boton,input->ToElement()->Attribute("joystick_number")[0]-48,boton->ToElement()->Attribute("map")));
                }
            }
        }
    }

    tecla_arriba=true;
    for(int i=0;i<20;i++)
        buffer_inputs.push_back("5");
    for(int i=0;i<(int)botones.size();i++)
    {
        if(botones[i].getMapeo()=="2" || botones[i].getMapeo()=="4" || botones[i].getMapeo()=="6" || botones[i].getMapeo()=="8")
        {
            this->cruz.push_back(botones[i]);
        }
        else
        {
            this->botones.push_back(botones[i]);
        }
    }
}