コード例 #1
0
void CicloDeJuego::iniciar()
{
	cout << "_____________________________________________________\n  Linen Mist- Raul Ramos Macias - @MetroGoldyMayer  \n_____________________________________________________" ;

	//Genera el mundo
	Nivel* nivel = new Nivel();

	//Comando de entrada
	string comando;
	//Vector conteniendo el comando separado por espacios
	vector<string> instrucciones;
   
	//Ciclo de juego
    while(1 == 1)
	{
		//Introducción del nuevo comando
        comando.clear();
        cout << "\n\n> ";
        getline(cin, comando);

		//Separación de palabras del comando
		instrucciones.clear();
		separarPalabras(comando, instrucciones);
		nivel->operacion(instrucciones);

		if (nivel->isGameOver() == true) {
			delete nivel;
			nivel = new Nivel();
		}
	}
}
コード例 #2
0
ファイル: Juego.cpp プロジェクト: francoap/TPI-Algo1
void Juego::Mostrar(std::ostream& os)
{
	os << "Instancia de Juego\n";
	os << "=================\n";
	os << "\n";

    // FLORES
	os << "Flores:\n";
	os << "\n";

	int i = 0;

	while(i < _flores.size())
	{
		Flor f = _flores[i];

		f.Mostrar(os);

		i++;
	}
	// FLORES - END

	os << "\n";

	// VAMPIROS
	os << "Vampiros:\n";
	os << "\n";

	i = 0;

	while(i < _vampiros.size())
	{
		Vampiro v = _vampiros[i];

	    v.Mostrar(os);

		i++;
	}
    // VAMPIROS - END

	os << "\n";

	// NIVELES
	os << "Niveles:\n";
	os << "\n";

	i = 0;

	while(i < _niveles.size())
    {
    	Nivel n = _niveles[i];

    	n.Mostrar(os);

    	i++;
    }
	// NIVELES - END
}
コード例 #3
0
ファイル: Juego.cpp プロジェクト: francoap/TPI-Algo1
void Juego::Guardar(std::ostream& os)
{
	os << "{ J [ ";

    // FLORES
	int i = 0;

	while(i < _flores.size())
	{
		Flor f = _flores[i];

		f.Guardar(os);
        
        os << " ";

		i++;
	}	
	// FLORES - END

	os << "] [ ";
    
    // VAMPIROS
	i = 0;

	while(i < _vampiros.size())
	{
		Vampiro v = _vampiros[i];

		v.Guardar(os);

		os << " ";

		i++;
	}
    // VAMPIROS - END

	os << "] [ ";

    // NIVELES
    i = 0;

    while(i < _niveles.size())
    {
    	Nivel n = _niveles[i];

    	n.Guardar(os);

    	os << " ";

    	i++;
    }
    // NIVELES - END

    os <<"] }";
}
コード例 #4
0
ファイル: Juego.cpp プロジェクト: francoap/TPI-Algo1
void Juego::altoCheat(int n)
{
    Nivel nivel = _niveles.at(n);

    unsigned long i = 0;

    while(i < nivel.vampirosN().size())
    {	
        nivel.vampirosN().at(i).vida = nivel.vampirosN().at(i).vida / 2;
        i++;
    }
	
	std::vector<VampiroEnJuego> vampirosNuevosDeN;

	unsigned long j = 0;

    while(j < nivel.vampirosN().size())
    {
        if (nivel.vampirosN().at(j).vida > 0)
        {
	    	vampirosNuevosDeN.push_back(nivel.vampirosN().at(j));
        }
		j++;
    }

    nivel.vampirosN() = vampirosNuevosDeN;
}
コード例 #5
0
ファイル: Juego.cpp プロジェクト: francoap/TPI-Algo1
std::vector<int> Juego::nivelesGanados()
{
    std::vector<int> res;

    int i = 0;

    while(i < _niveles.size())
    {
        Nivel n = _niveles.at(i);

        if (n.spawningN().size() == 0 && n.vampirosN().size() == 0)
        {
            res.push_back(i);
        }

        i++;
    }
    return res;
}
コード例 #6
0
ファイル: Juego.cpp プロジェクト: kevinfra/Algo1-TPI
void Juego::Cargar(istream& is)
{
	string juego;
	getline(is, juego, 'J');
	string basura;
	string cambioTipo;
	getline(is, cambioTipo, ' ');
	char ultimoCambio=cambioTipo.back();
	while (ultimoCambio != ']') {
		Flor cargaF;
		cargaF.Cargar(is);
		this->_flores.push_back(cargaF);
		getline(is, basura, ' ');
		getline(is, cambioTipo, ' ');
		ultimoCambio = cambioTipo.back();
	}
	getline(is, basura, ' ');
	getline(is, cambioTipo, ' ');
	ultimoCambio = cambioTipo.back();
	while (ultimoCambio != ']') {
		Vampiro cargaF;
		cargaF.Cargar(is);
		this->_vampiros.push_back(cargaF);
		getline(is, basura, ' ');
		getline(is, cambioTipo, ' ');
		ultimoCambio = cambioTipo.back();
	}
	getline(is, basura, ' ');
	getline(is, cambioTipo, ' ');
	ultimoCambio = cambioTipo.back();
	while (ultimoCambio != ']') {
		Nivel cargaN;
		cargaN.Cargar(is);
		this->_niveles.push_back(cargaN);
		getline(is, basura, ' ');
		getline(is, cambioTipo, ' ');
		ultimoCambio = cambioTipo.back();
	}
	this->_nivelActual = 0;
}
コード例 #7
0
Nivel* NivelParser::parseNivel(const char *nivelArchivo)
{
////    // crear un documento tinyXML y cargar el mapa xml
    TiXmlDocument nivelDocument;
    nivelDocument.LoadFile(nivelArchivo);

    // crear el objeto nivel
    Nivel* pNivel = new Nivel();

    // get el nodo raiz y desplegar algunos valores
    TiXmlElement* pRoot = nivelDocument.RootElement();

    std::cout << "Loading level:\n" << "Version: " << pRoot->Attribute("version") << "\n";
    std::cout << "Width:" << pRoot->Attribute("width") << " - Height:" << pRoot->Attribute("height") << "\n";
    std::cout << "Tile Width:" << pRoot->Attribute("tilewidth") << " - Tile Height:" << pRoot->Attribute("tileheight") << "\n";

    pRoot->Attribute("tilewidth", &magnitudTile);
    pRoot->Attribute("width", &ancho);
    pRoot->Attribute("height", &altura);

    //sabemos que propiedades es el primer hijo de raiz
    TiXmlElement* pProperties = pRoot->FirstChildElement();

    //  Debemos analizar las texturas necesarias para este nivel, que se han añadido a las propiedades
    for(TiXmlElement* e = pProperties->FirstChildElement(); e != NULL; e = e->NextSiblingElement())
    {
        if(e->Value() == std::string("property"))
        {
            parseTexturas(e);
        }
    }

    // ahora debemos parsear los conjutos de tiles
    for(TiXmlElement* e = pRoot->FirstChildElement(); e != NULL; e = e->NextSiblingElement())
    {
        if(e->Value() == std::string("tileset"))
        {
            parseConjuntoTiles(e, pNivel->getConjuntoTiles());
        }
    }

    // parsear las capas de objetos
    for(TiXmlElement* e = pRoot->FirstChildElement(); e != NULL; e = e->NextSiblingElement())
    {
        if(e->Value() == std::string("objectgroup") || e->Value() == std::string("layer"))
        {
            if(e->FirstChildElement()->Value() == std::string("object"))
            {
                parseCapaObjeto(e, pNivel->getCapas(), pNivel);
            }
            else if(e->FirstChildElement()->Value() == std::string("data") ||
                    (e->FirstChildElement()->NextSiblingElement() != 0 && e->FirstChildElement()->NextSiblingElement()->Value() == std::string("data")))
            {
                parseCapaTile(e, pNivel->getCapas(), pNivel->getConjuntoTiles(), pNivel->getCapasDeColision());
            }
        }
    }

    return pNivel;
}
コード例 #8
0
ファイル: Juego.cpp プロジェクト: francoap/TPI-Algo1
void Juego::Cargar(std::istream& is)
{
	using namespace std;

	is.ignore(2);

	string tipo = "";
	getline(is, tipo, ' ');

	if(tipo == "J")
	{
		// FLORES

		is.ignore(2);
		
		vector<Flor> floresJuego;
		string noCargoFlores = "";
		string noHayMasFlores = "";
		noCargoFlores = is.peek();
		
		if (noCargoFlores == "]")
		{
			noHayMasFlores== "]";
			_flores = floresJuego;
		}
		
		else
		{
			while(noHayMasFlores != "]")
			{
				Flor f;
			
				f.Cargar(is);

				floresJuego.push_back(f);

				is.ignore(2);
			
				noHayMasFlores = is.peek();
			}

			_flores = floresJuego;
		}
	// FLORES - END

		is.ignore(4);

	// VAMPIROS		
		vector<Vampiro> vampirosJuego;
		string noCargoVampiros = "";
		string noHayMasVampiros = "";
		noCargoVampiros = is.peek();
		
		if (noCargoVampiros == "]")
		{
			noHayMasVampiros== "]";
			_vampiros = vampirosJuego;
		}
		
		else
		{
			while(noHayMasVampiros != "]")
			{
				Vampiro v;

				v.Cargar(is);

				vampirosJuego.push_back(v);

				is.ignore(2);
			
				noHayMasVampiros = is.peek();
			}

			_vampiros = vampirosJuego;
		}
	// VAMPIROS - END

		is.ignore(4);

	// NIVELES
		vector<Nivel> nivelesJuego;
		string noCargoNiveles = "";
		string noHayMasNiveles = "";
		noCargoNiveles = is.peek();
		
		if (noCargoNiveles == "]")
		{
			noHayMasNiveles == "]";
			_niveles = nivelesJuego;
		}

		else
		{
			while(noHayMasNiveles != "]")
			{
				Nivel n;

				n.Cargar(is);

				nivelesJuego.push_back(n);

				is.ignore(4);

				noHayMasNiveles = is.peek();
			}

			_niveles = nivelesJuego;
		}

	// NIVELES - END

	 }
}
コード例 #9
0
ファイル: main.cpp プロジェクト: Cahl96/Pong
int main()
{
    //Allegro inits
    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    ALLEGRO_TIMER *timer = NULL;
    ALLEGRO_TIMER *frametimer = NULL;
    ALLEGRO_FONT *font = NULL;
    ALLEGRO_BITMAP *background = NULL;
    ALLEGRO_BITMAP *cancha = NULL;
    ALLEGRO_BITMAP *verde = NULL;
    ALLEGRO_BITMAP *amarillo = NULL;
    ALLEGRO_BITMAP *gris = NULL;
    ALLEGRO_BITMAP *naranja = NULL;
    ALLEGRO_BITMAP *azul= NULL;
    ALLEGRO_BITMAP *rosado = NULL;
    ALLEGRO_SAMPLE *song = NULL;

    const int maxFrame = 8;
    int curFrame = 0;
    int frameCunt = 0;
    int frameDelay = 5;

    bool done = true;
    bool reDraw = false;
    bool  menu = true;
    bool instrucciones = true;
    bool scores = false;
    bool isGameOver = false;
    int ganador = 0;
    int frameWidth = 32;
    int frameHeight = 32;

    if(!al_init())
        return -1;

    display = al_create_display(WIDTH, HEIGHT);
    al_set_window_title(display, "PONG!");
    al_set_window_position(display, 200, 200);

    al_init_primitives_addon();
    al_install_audio();
    al_init_acodec_addon();
    al_init_image_addon();
    al_install_keyboard();
    al_init_font_addon();
    al_init_ttf_addon();
    al_reserve_samples(2);

    event_queue = al_create_event_queue();
    timer = al_create_timer(1.0 / FPS);
    frametimer = al_create_timer(1.0 / frameFPS);

    font = al_load_font("Assets/font1.ttf", 18, 0);
    background = al_load_bitmap("Assets/background.png");
    cancha = al_load_bitmap("Assets/cancha.png");
    song = al_load_sample("Assets/cancion_fondo.ogg");
    verde = al_load_bitmap("Assets/crystalgreen32.png");
    azul = al_load_bitmap("Assets/crystalblue32.png");
    amarillo = al_load_bitmap("Assets/crystalyellow32.png");
    naranja = al_load_bitmap("Assets/crystalorange32.png");
    gris = al_load_bitmap("Assets/crystalgray32.png");
    rosado = al_load_bitmap("Assets/crystalpink32.png");

    al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_register_event_source(event_queue, al_get_display_event_source(display));

    Nivel n;
    Jugador pL(1);
    Jugador pR(2);
    Bola b;
    vector<Puntzje*> puntajes;
    puntajes.push_back(new Puntzje("Jugador 1: ", pL.score));
    puntajes.push_back(new Puntzje("Jugador 2: ", pR.score));

    al_play_sample(song, 1, 0, 1, ALLEGRO_PLAYMODE_LOOP, NULL);
    al_start_timer(timer);
    al_start_timer(frametimer);

    while(done)
    {
        ALLEGRO_EVENT ev;
        al_wait_for_event(event_queue, &ev);

        if(ev.type == ALLEGRO_EVENT_TIMER)
        {

            if(++frameCunt >= frameDelay)
            {
                if(++curFrame >= maxFrame)
                    curFrame = 0;

                frameCunt = 0;
            }

            reDraw = true;

            if(keys[UP])
                pR.y -= pR.velocity;

            if(keys[DOWN])
                pR.y += pR.velocity;

            if(keys[w])
                pL.y -= pL.velocity;

            if(keys[s])
                pL.y += pL.velocity;

            if(keys[SPACE])
            {
                if(isGameOver)
                {
                    isGameOver = false;
                    b.resetBall();
                    pR.reestablecerPuntos();
                    pL.reestablecerPuntos();
                }
            }

            if(keys[p])
            {
                isGameOver = false;
                menu = false;
                instrucciones = false;
                pR.reestablecerPuntos();
                pL.reestablecerPuntos();
            }

            if(keys[i])
            {
                isGameOver = false;
                instrucciones = true;
                menu = false;
                pR.reestablecerPuntos();
                pL.reestablecerPuntos();
            }

            if(keys[r])
            {
                isGameOver = false;
                instrucciones = false;
                menu = false;
                scores = true;
            }

            if(!isGameOver)
            {
                b.update();
                pL.collision();
                pR.collision();
                b.collision(pL, pR);

                if(pR.score == SCORE)
                {
                    pR.escribirScores("scores", puntajes);
                    ganador = 2;
                    isGameOver = true;
                }
                else if(pL.score == SCORE)
                {
                    pL.escribirScores("scores", puntajes);
                    ganador = 1;
                    isGameOver = true;
                }
            }

        } else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
            done = false;
        else if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
            switch(ev.keyboard.keycode)
            {
                case ALLEGRO_KEY_ESCAPE:
                    done = false;
                    break;
                case ALLEGRO_KEY_W:
                    keys[w] = true;
                    break;
                case ALLEGRO_KEY_S:
                    keys[s] = true;
                    break;
                case ALLEGRO_KEY_UP:
                    keys[UP] = true;
                    break;
                case ALLEGRO_KEY_DOWN:
                    keys[DOWN] = true;
                    break;
                case ALLEGRO_KEY_SPACE:
                    keys[SPACE] = true;
                    break;
                case ALLEGRO_KEY_P:
                    keys[p] = true;
                    break;
                case ALLEGRO_KEY_I:
                    keys[i] = true;
                    break;
                case ALLEGRO_KEY_R:
                    keys[r] = true;
                    break;
            }
        else if(ev.type == ALLEGRO_EVENT_KEY_UP)
            switch(ev.keyboard.keycode)
            {
                case ALLEGRO_KEY_ESCAPE:
                    done = false;
                    break;
                case ALLEGRO_KEY_W:
                    keys[w] = false;
                    break;
                case ALLEGRO_KEY_S:
                    keys[s] = false;
                    break;
                case ALLEGRO_KEY_UP:
                    keys[UP] = false;
                    break;
                case ALLEGRO_KEY_DOWN:
                    keys[DOWN] = false;
                    break;
                case ALLEGRO_KEY_SPACE:
                    keys[SPACE] = false;
                    break;
                case ALLEGRO_KEY_P:
                    keys[p] = false;
                    break;
                case ALLEGRO_KEY_I:
                    keys[i] = false;
                    break;
                case ALLEGRO_KEY_R:
                    keys[r] = false;
                    break;
            }

        if(reDraw && al_is_event_queue_empty(event_queue))
        {
            reDraw = false;
            if(menu)
            {
                al_draw_bitmap(background, 0, 0, NULL);
                al_draw_text(font, al_map_rgb(0, 0, 0), WIDTH/2, HEIGHT/2-40, ALLEGRO_ALIGN_CENTRE, "P. Iniciar Juego");
                al_draw_text(font, al_map_rgb(0, 0, 0), WIDTH/2, HEIGHT/2, ALLEGRO_ALIGN_CENTRE, "I. Instrucciones");
                al_draw_text(font, al_map_rgb(0, 0, 0), WIDTH/2, HEIGHT/2+40, ALLEGRO_ALIGN_CENTRE, "ESC. Salir");
                al_draw_bitmap_region(verde, curFrame*frameWidth, 0, frameWidth, frameHeight, 10, 2, 0);
                al_draw_bitmap_region(azul, curFrame*frameWidth, 0, frameWidth, frameHeight, 50, 2, 0);
                al_draw_bitmap_region(amarillo, curFrame*frameWidth, 0, frameWidth, frameHeight, 90, 2, 0);
                al_draw_bitmap_region(naranja, curFrame*frameWidth, 0, frameWidth, frameHeight, 130, 2, 0);
                al_draw_bitmap_region(rosado, curFrame*frameWidth, 0, frameWidth, frameHeight, 170, 2, 0);
                al_draw_bitmap_region(gris, curFrame*frameWidth, 0, frameWidth, frameHeight, 210, 2, 0);

            }
            else if(instrucciones)
            {
                al_draw_bitmap(background, 0, 0, NULL);
                al_draw_text(font, al_map_rgb(0, 255, 27), WIDTH/2, HEIGHT/2-40, ALLEGRO_ALIGN_CENTRE, "Jugador 1: W y S (subir y bajar)");
                al_draw_text(font, al_map_rgb(0, 255, 27), WIDTH/2, HEIGHT/2, ALLEGRO_ALIGN_CENTRE, "Jugador 2: ARRIBA y ABAJO (subir y bajar)");
                al_draw_text(font, al_map_rgb(0, 255, 27), WIDTH/2, HEIGHT/2+80, ALLEGRO_ALIGN_CENTRE, "El que llegue a 10 pts gana!");
                al_draw_text(font, al_map_rgb(0, 255, 27), WIDTH/2, HEIGHT/2+120, ALLEGRO_ALIGN_CENTRE, "Presiona 'p' para jugar!");
            }
            else if(!isGameOver)
            {
                al_draw_bitmap(cancha, 0, 0, NULL);
                n.render();
                pL.render();
                pR.render();
                b.render();

                al_draw_text(font, al_map_rgb(277, 134, 27), WIDTH/2, 10, ALLEGRO_ALIGN_CENTRE, "PONG");
                al_draw_text(font, al_map_rgb(0, 0, 0), 10, 2, ALLEGRO_ALIGN_LEFT, "Jugador 1");
                al_draw_textf(font, al_map_rgb(0, 0, 0), 10, 20, ALLEGRO_ALIGN_LEFT, "%i   ", pL.score);
                al_draw_text(font, al_map_rgb(0, 0, 0), WIDTH-10, 2, ALLEGRO_ALIGN_RIGHT, "Jugador 2");
                al_draw_textf(font, al_map_rgb(0, 0, 0), WIDTH-10, 20, ALLEGRO_ALIGN_RIGHT, "%i  ", pR.score);
            }
            else
            {
                if(ganador == 1)
                {
                    al_draw_textf(font, al_map_rgb(0, 255, 27), WIDTH/2, HEIGHT/2-80, ALLEGRO_ALIGN_RIGHT, "Jugador 1: %i  ", pL.score);
                    al_draw_textf(font, al_map_rgb(0, 255, 27), WIDTH/2, HEIGHT/2-80, ALLEGRO_ALIGN_LEFT," %i :Jugador 2 ", pR.score);
                    al_draw_text(font, al_map_rgb(277, 134, 27), WIDTH/2, HEIGHT/2, ALLEGRO_ALIGN_CENTRE, "--- JUGADOR 1 GANA ---");
                    al_draw_text(font, al_map_rgb(277, 134, 27), WIDTH/2, HEIGHT/2+40, ALLEGRO_ALIGN_CENTRE, "--- Jugador 2 pierde xD ---");
                }
                else if(ganador == 2)
                {
                    al_draw_textf(font, al_map_rgb(0, 255, 27), WIDTH/2, HEIGHT/2-80, ALLEGRO_ALIGN_RIGHT, "Jugador 1: %i  ", pL.score);
                    al_draw_textf(font, al_map_rgb(0, 255, 27), WIDTH/2, HEIGHT/2-80, ALLEGRO_ALIGN_LEFT," %i :Jugador 2  ", pR.score);
                    al_draw_text(font, al_map_rgb(277, 134, 27), WIDTH/2, HEIGHT/2, ALLEGRO_ALIGN_CENTRE, "--- JUGADOR 2 GANA ---");
                    al_draw_text(font, al_map_rgb(277, 134, 27), WIDTH/2, HEIGHT/2+40, ALLEGRO_ALIGN_CENTRE, "--- Jugador 1 pierde (malo) ---");
                }

                al_draw_text(font, al_map_rgb(277, 134, 27), WIDTH/2, HEIGHT/2+80, ALLEGRO_ALIGN_CENTRE, "SPACE para jugar de nuevo | ESC para salir");
            }

            al_flip_display();
            al_clear_to_color(al_map_rgb(0,0,0));
        }


    }

    al_destroy_event_queue(event_queue);
    al_destroy_display(display);
    al_destroy_font(font);
    al_destroy_bitmap(background);
    al_destroy_bitmap(cancha);
    al_destroy_bitmap(verde);
    al_destroy_bitmap(azul);
    al_destroy_bitmap(rosado);
    al_destroy_bitmap(amarillo);
    al_destroy_bitmap(naranja);
    al_destroy_bitmap(gris);
    al_destroy_sample(song);

    return 0;
}