示例#1
0
int main()
{
    allegro_init();
    install_keyboard();

    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, 900, 600, 0, 0);

    buffer = create_bitmap(900, 600);
    roca = load_bitmap("Images/roca.bmp", NULL);

    while(!key[KEY_ESC])
    {

        dibujar_mapa();
        pantalla();
    }


    return 0;
}
示例#2
0
bool Vista::run() {
	bool quit = false;
	SDL_Event e;
	int mov_x = 0, mov_y = 0;
	//this->transformador->transformar_isometrica_pantalla(pers->getReferenciaMapaX()-referencia_mapa_x,pers->getReferenciaMapaY()-referencia_mapa_y,mov_x,mov_y);
	double personaje_x, personaje_y;
	while (SDL_PollEvent(&e) != 0) {
		if (e.type == SDL_QUIT) {
			quit = true;
		}
		//cheat
		if (e.type == SDL_KEYDOWN) {
			switch (e.key.keysym.sym) {
			case SDLK_c:
				if (this->modelo->get_entidad_seleccionada()) {
					this->gameController->crearPersonajeEdificio("gandalf",
							this->modelo->get_entidad_seleccionada()->getId());
				}
				break;
			}
		}
		if (e.type == SDL_MOUSEBUTTONUP) {
			if (e.button.button == SDL_BUTTON_LEFT) {
				esta_eligiendo = false;
				termino_de_elegir = true;
				SDL_GetMouseState(&seleccion_x_final, &seleccion_y_final);
				int pant_x = seleccion_x_final;
				int pant_y = seleccion_y_final; //por si cambian en setear seleccion
				double a, b;
				this->transformador->transformar_pantalla_isometrica(pant_x,
						pant_y, a, b);
				this->corregir_referencia_coordenadas_pantalla_mapa(a, b);
				//if (!this->modelo->afueraDelMapa(a, b)) {
					this->setear_seleccion();
					//si seleeciono sobre mapa
				if (seleccion_y_final < this->barra->obtenerYDondeSeDibuja()) {
					//proteger contra tocas afuera del mapa
					if (!this->modelo->afueraDelMapa(floor(a), floor(b))) {
						//si ve donde esta haciendo click
						if (this->modelo->oscuridad(0, floor(a), floor(b)) == VISIBLE) {
							if (this->entidadACrear) {
								//no lo puede crear en lugar donde no ve
								if (!this->modelo->tocaSombra(entidadACrear)
										&& this->modelo->getJugador()->puedePagar(
												entidadACrear->getCosto())&&this->modelo->puedoCrearSiEsPuerto(entidadACrear)) {
									//TODO crear con muchos tipitos
									//si puede crear es porque tiene un tipito seleccionado
									if (this->modelo->mapa->puedeUbicar(
											entidadACrear)) {
										this->modelo->getJugador()->pagar(
												entidadACrear->getCosto());
										this->gameController->crearEdificio(
												this->entidadACrear->mostrar_contenido().getNombre(),
												this->modelo->devolverPersonajeSeleccionado().front()->getId(),
												floor(a), floor(b));
									}

									//podria moverse a cuando recibe que se creo asi se deja de dibjar
									//en ese momento
								}
							} else {
								//si no creo estoy seleccionando
								this->barra->setDisplay(
								modelo->seleccionar(a, b));
							}
						}
						//si clickeo pase lo q pase dejo de dibujar
						this->dejarDeDibujarEdificio();

					}else{
						this->barra->borrarDisplay();
						this->dejarDeDibujarEdificio();
						this->modelo->limpiarSeleccion();
					}

				} else {
						tuple<ObjetoMapa*, int> tipo = this->barra->seleccionar(
								pant_x, pant_y);
						ObjetoMapa* objeto = std::get<0>(tipo);
						if (objeto) {
							Costo costo;
							costo.setCosto(objeto->oro, objeto->piedra,
									objeto->madera, objeto->comida);
							if (std::get<1>(tipo) >= 0) {
								if (this->modelo->getJugador()->puedePagar(
										costo)) {
									this->gameController->crearPersonajeEdificio(
											objeto->nombre, std::get<1>(tipo));
									Mix_PlayChannel(-1, musica_creacion, 0);
									this->modelo->getJugador()->pagar(costo);
								}

							} else {
								this->cargarEdificioACrear(objeto->nombre);
							}
							//elegir entre mandar a crear personaje o crear edificio

						}
					}

				//}


			}

		}
		if (e.type == SDL_MOUSEBUTTONDOWN) {

			if (e.button.button == SDL_BUTTON_RIGHT) {
				this->dejarDeDibujarEdificio();
				SDL_GetMouseState(&mov_x, &mov_y);
				this->transformador->transformar_pantalla_isometrica(mov_x,
						mov_y, personaje_x, personaje_y);
				this->corregir_referencia_coordenadas_pantalla_mapa(personaje_x,
						personaje_y);
				Posicion p = Posicion(personaje_x, personaje_y);
				//le envia al server que cambie el destino
				vector<Personaje*> personajes =
						this->modelo->devolverPersonajeSeleccionado();

				if (!personajes.empty()) {
					vector<Personaje*>::iterator it = personajes.begin();
					for (; it != personajes.end(); it++) {
						Personaje* personaje = (*it);
						if (personaje->getNombreJugador()
								== this->modelo->nombreJugador()) {
							this->gameController->cambiar_destino_personaje(
									personaje->getId(), personaje_x,
									personaje_y);
							this->gameController->interactuar(personaje, p);
						}
					}
				}

			}
			//TODO
			//no dejo que se dibuje el edificio si clique

			if (e.button.button == SDL_BUTTON_LEFT) {
				double a, b;
				SDL_GetMouseState(&seleccion_x_inicio, &seleccion_y_inicio);
				this->transformador->transformar_pantalla_isometrica(seleccion_x_inicio,
						seleccion_y_inicio, a, b);
				this->corregir_referencia_coordenadas_pantalla_mapa(a, b);
				if (seleccion_y_inicio < this->barra->obtenerYDondeSeDibuja()
						&& !this->entidadACrear ) {
					esta_eligiendo = true;
					this->modelo->limpiarSeleccion();
				}


			}
		}

		if (e.type == SDL_KEYDOWN) {
			this->dejarDeDibujarEdificio();
			SDL_Keycode keyPressed = e.key.keysym.sym;

			switch (keyPressed) {
			case SDLK_ESCAPE:
				quit = true;
				break;
			case SDLK_r:
				return true;

			}
		}
	}
	SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);
	SDL_RenderClear(gRenderer);
	dibujar_mapa();
	modelo->actualizarMapa(); //lo tiene que hacer el server
	SDL_GetMouseState(&mov_x, &mov_y);
	dibujar_edificio(mov_x, mov_y);
	dibujar_barra();
	detectar_mouse_borde();
	SDL_RenderPresent(gRenderer);
	this->termino_de_elegir = false;
	return quit;
}
示例#3
0
int main(){
    //funciones allegro
    allegro_init();
    install_mouse();
    install_keyboard();

    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, 500, 400, 0, 0);

    srand(time(NULL)); //semilla para el random

    //cargar imagenes iniciales
    buffer2 = create_bitmap(500,400);
    fondo1 = load_bitmap("blanco.bmp",NULL);
    fondo2 = load_bitmap("empezar.bmp",NULL);
    fondo3 = load_bitmap("sdj.bmp",NULL);
    cursor = load_bitmap("cursor.bmp",NULL);

    bool salida = false;
    coord food;

    while(!salida && !key[KEY_ESC]){ //hazlo mientras no choque o no se pulse la tecla ESC

        if(mouse_x > 141 && mouse_x < 318 && mouse_y > 255 && mouse_y < 293){ //si está dentro de las coordenadas
            blit(fondo2, buffer2,0,0,0,0,500,400);
            if(mouse_b & 1){ //si se clickea "EMPEZAR", carga las imagenes y empieza el juego

                buffer = create_bitmap(880, 660);
                roca = load_bitmap("roca.bmp", NULL);
                pacbmp = load_bitmap("snake.bmp",NULL);
                snake = create_bitmap(33,33);
                comida = load_bitmap("Comida.bmp",NULL);

                set_gfx_mode(GFX_AUTODETECT_WINDOWED, 880, 660, 0, 0);

                serpiente s;

                food.y=(1+rand()%(MAXFILES-2)); //poner comida aleatoriamente dentro de los limites de la pantalla
                food.x=(1+rand()%(MAXCOLS-2));

                while(!key[KEY_ESC] &&  !s.game_over()  ){

                        draw_sprite(buffer,comida,food.x*30,food.y*30);//manda a dibujar comida

                        //establecer direcciones
                        if(key[KEY_RIGHT]) s.setdir(1);
                        else if(key[KEY_LEFT]) s.setdir(0);
                        else if(key[KEY_UP]) s.setdir(2);
                        else if(key[KEY_DOWN]) s.setdir(3);

                        s.mover_personaje();

                        //si come, que ponga otra comida, aumente puntos y tamano
                        if(s.getcuerpox(0)/30 == food.x && s.getcuerpoy(0)/30==food.y){

                                food.y=(1+rand()%(MAXFILES-2));
                                food.x=(1+rand()%(MAXCOLS-2));
                                s.settam(1);
                                s.setpuntos(10);
                        }

                        dibujar_mapa();
                        s.dibujar_personaje();

                        //funciones allegro que muestra por pantalla, en este caso, puntos y tamano
                        char c1[10];
                        textout_ex(buffer,font,"Tamano:",50,630,0xfff000,-1);
                        textout_ex(buffer, font, itoa(s.gettam(),c1,10), 110, 630,  0xfff000, -1);
                        textout_ex(buffer,font,"Puntos:",50,640,0xfff000,-1);
                        textout_ex(buffer, font, itoa(s.getpuntos(),c1,10), 110, 640,  0xfff000, -1);

                        pantalla();
                        rest(150);


                        //limpia los buffer
                        clear(buffer);
                        clear(snake);
                        //////////////////////////////////////////////////////////////////////game over

                        if(s.game_over()){
                            set_color_depth(32);
                            set_gfx_mode(GFX_AUTODETECT_WINDOWED, 500, 400, 0, 0);

                            for(int i=0; i<10; ){
                                buffer3 = create_bitmap(500,400);
                                perder = load_bitmap("perder.bmp",NULL);
                                blit(perder, screen, 0,0,0,0,880,660);
                                rest(150);
                                i++;
                            }//end for

                        }//end if

                        salida=true; //sal, es decir, termina el while
                }//end while

          }//end if mouse

                destroy_bitmap(buffer);
    }//if salida



    //si se pulsa el ratón dentro de estas coordenadas (en la imagen referencia a la opción SALIR), pon salida a true
    else if(mouse_x > 103 && mouse_x < 394 && mouse_y > 302 && mouse_y < 341){
        blit(fondo3,buffer2,0,0,0,0,500,400);
        if(mouse_b & 1){
            salida=true;
        }
    }//end elseif

    else blit(fondo1,buffer2,0,0,0,0,500,400);

    //coge coordenadas del cursor y lo muestra
    masked_blit(cursor,buffer2,0,0,mouse_x,mouse_y,13,22);
    blit(buffer2,screen,0,0,0,0,500,400);
    }//while salida


}//end main