Conj<Posicion> Campus::Vecinos(Posicion pos) { Conj<Posicion> conjPosiciones = Conj<Posicion>(); if (PosValida(ProxPosicion(pos, abajo))) { conjPosiciones.AgregarRapido(ProxPosicion(pos, abajo)); } else { conjPosiciones.AgregarRapido(Posicion(-1, -1)); } if (PosValida(ProxPosicion(pos, arriba))) { conjPosiciones.AgregarRapido(ProxPosicion(pos, arriba)); } else { conjPosiciones.AgregarRapido(Posicion(-1, -1)); } if (PosValida(ProxPosicion(pos, der))) { conjPosiciones.AgregarRapido(ProxPosicion(pos, der)); } else { conjPosiciones.AgregarRapido(Posicion(-1, -1)); } if (PosValida(ProxPosicion(pos, izq))) { conjPosiciones.AgregarRapido(ProxPosicion(pos, izq)); } else { conjPosiciones.AgregarRapido(Posicion(-1, -1)); } return conjPosiciones; }
Conj<Posicion> Campus::IngresosMasCercanos(Posicion pos) { Conj<Posicion> conjunto = Conj<Posicion>(); Posicion superior = Posicion(pos.x, 0); Posicion inferior = Posicion(pos.x, Filas()-1); if (Distancia(pos, superior) <= Distancia(pos, inferior)) conjunto.Agregar(superior); if (Distancia(pos, superior) >= Distancia(pos, inferior)) conjunto.Agregar(inferior); return conjunto; }
Posicion Campus::ProxPosicion(Posicion pos, Direccion direccion) { switch (direccion) { case izq: return Posicion(pos.x-1, pos.y); case der: return Posicion(pos.x+1, pos.y); case arriba: return Posicion(pos.x, pos.y-1); case abajo: return Posicion(pos.x, pos.y+1); } }
bool Campus::operator==(Campus &otro) { bool filaColumna = Filas() == otro.Filas() && Columnas() == otro.Columnas(); if (filaColumna) { for (int c = 0; c < Columnas(); ++c) { for (int f = 0; f < Filas(); ++f) { if (Ocupada(Posicion(c, f)) != otro.Ocupada(Posicion(c, f))) { return false; } } } return true; } else { return false; } }
Arreglo<Posicion> Campus::DeConjAArreglo(Conj<Posicion> c) { Arreglo<Posicion> arreglo = Arreglo<Posicion>(c.Cardinal()); Conj<Posicion>::Iterador itConjunto = c.CrearIt(); Nat i = 0; while (itConjunto.HaySiguiente()) { // Copiar lo siguiente.. if (itConjunto.Siguiente() != Posicion(-1, -1)) { arreglo.Definir(i, itConjunto.Siguiente()); } ++i; itConjunto.Avanzar(); } return arreglo; }
CampusEscena::CampusEscena() { onTimerTick = gcnew EventHandler(this, &CampusEscena::timerTick); onKeyDown = gcnew KeyEventHandler(this, &CampusEscena::teclaDown); onKeyUp = gcnew KeyEventHandler(this, &CampusEscena::teclaUp); onMouseClick = gcnew MouseEventHandler(this, &CampusEscena::mouseClick); Mapas::plazuela_mapa = gcnew PlazuelaMapa(); Mapas::pabellonA_mapa = gcnew PabellonAMapa(); Mapas::pabellonB_mapa = gcnew PabellonBMapa(); Mapas::sotano_mapa = gcnew SotanoMapa(); Mapas::jardin_mapa = gcnew JardinMapa(); Mapa::mapa_actual = Mapas::plazuela_mapa; Marco::marco = gcnew Marco(gcnew Posicion(9, 9, true)); PROFESORES::Profesor1 = gcnew Profesor(1, Mapas::plazuela_mapa, gcnew Posicion(16, 3, true)); PROFESORES::Profesor2 = gcnew Profesor(3, Mapas::pabellonB_mapa, gcnew Posicion(16, 11, true)); PROFESORES::Profesor3 = gcnew Profesor(5, Mapas::sotano_mapa, gcnew Posicion(16, 6, true)); PROFESORES::Profesor4 = gcnew Profesor(7, Mapas::jardin_mapa, gcnew Posicion(11, 4, true)); PROFESORES::Profesor5 = gcnew Profesor(9, Mapas::pabellonA_mapa, gcnew Posicion(2, 10, true)); }
#include "Winform.h" namespace Bomberman { Item::Item(Posicion^ p, Items pTipo) { tipo = oItem; tipoItem = pTipo; posicion = gcnew Posicion(p->x, p->y); } void Item::MostrarSprite(Graphics^ graphics) { if (tipoItem == Cura) graphics->DrawImage(Imagenes::Cura, Rectangle(posicion->x, posicion->y, 64, 64)); else if (tipoItem == Powerade) graphics->DrawImage(Imagenes::Powerade, Rectangle(posicion->x, posicion->y, 64, 64)); else if (tipoItem == BombaPlus) graphics->DrawImage(Imagenes::BombaPlus, Rectangle(posicion->x, posicion->y, 64, 64)); else if (tipoItem == Pasamuros) graphics->DrawImage(Imagenes::PasaMuros, Rectangle(posicion->x, posicion->y, 64, 64)); } }
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; }
void Interprete::procesarMensajeDeServer(msg_t msg) { dibujo_t dibujo; Personaje* p; switch (msg.type) { case KEEPALIVE: break; case MOVER_PERSONAJE: // printf("MOVER_PERSONAJE\n"); this->gameCtrl->mover_personaje(msg.paramInt1, msg.paramDouble1, msg.paramDouble2); break; case LOGIN: // printf("LOGIN\n"); if (this->gameCtrl->esNombre(msg.paramNombre)) { this->vista->setear_vista(msg.paramNombre); } break; case NUEVO_PERSONAJE: printf("NUEVO_PERSONAJE\n"); p = this->gameCtrl->conectarCliente(msg.paramNombre, msg.paramTipo, msg.paramDouble1, msg.paramDouble2, msg.paramInt1); this->vista->crearPersonaje(string(msg.paramTipo), p); //printf("termino NUEVO PERSONAJE\n"); break; case COMENZAR_PARTIDA: //printf("COMENZAR_PARTIDA\n"); this->start = true; break; case QUIT: //printf("QUIT\n"); this->gameCtrl->desconectar(msg.paramNombre); break; case CREAR_ENTIDAD: //printf("CREAR_ENTIDAD\n"); this->gameCtrl->agregarEntidad(msg.paramNombre, msg.paramDouble1, msg.paramDouble2, 0); //setear id de entidades this->gameCtrl->setId(msg.paramDouble1, msg.paramDouble2, msg.paramInt1); break; case CREAR_RECURSO: //printf("CREAR_RECURSO\n"); this->gameCtrl->agregarEntidad(msg.paramNombre, msg.paramDouble1, msg.paramDouble2, msg.paramInt1); break; case RECONNECT: //printf("RECONNECT\n"); this->gameCtrl->reconectar(msg.paramNombre); break; case PARAM_MAPA: //printf("PARAM_MAPA\n"); this->gameCtrl->juego->escenario->size_x = msg.paramDouble1; this->gameCtrl->juego->escenario->size_y = msg.paramDouble2; this->gameCtrl->setMapa(msg.paramDouble1,msg.paramDouble2); break; case CONFIGURACION: //printf("CONFIGURACION\n"); this->gameCtrl->setConfiguracion((int) msg.paramDouble1, (int) msg.paramDouble2); break; case DISCONNECT: //printf("DISCONNECT\n"); this->gameCtrl->desconectar(msg.paramNombre); break; case ACTUALIZACION_RECURSOS: //printf("ACTUALIZACION_RECURSOS\n"); this->gameCtrl->acutalizarRecursos(msg.paramNombre, msg.paramInt1, msg.paramDouble1, msg.paramDouble2); break; case SET_ID_RECURSO: //printf("SET_ID_RECURSO\n"); this->gameCtrl->setId(msg.paramDouble1, msg.paramDouble2, msg.paramInt1); break; case ELIMINAR_ENTIDAD: //printf("ELIMINAR_ENTIDAD\n"); this->gameCtrl->eliminarEntidad(msg.paramInt1); break; case FIN_INICIALIZACION: //printf("FIN_INICIALIZACION\n"); break; case ATACAR: //printf("ATACAR\n"); this->gameCtrl->ataque(msg.paramInt1, msg.paramDouble1, msg.paramDouble2); break; case ELIMINAR_PERSONAJE: //printf("ELIMINAR_PERSONAJE\n"); this->gameCtrl->eliminar_personaje(msg.paramInt1); break; case ELIMINAR: //printf("ELIMINAR\n"); this->gameCtrl->eliminar(msg.paramInt1); break; case CONSTRUIR: //printf("CONSTRUIR\n"); this->gameCtrl->construir(msg.paramInt1, msg.paramDouble1, msg.paramDouble2); break; case EMPEZAR_ACCION: //printf("EMPEZAR_ACCION\n"); this->gameCtrl->empezarAccion(msg.paramInt1,Posicion(msg.paramDouble1,msg.paramDouble2)); break; case TERMINAR_ACCION: //printf("TERMINAR_ACCION\n"); this->gameCtrl->terminarAccion(msg.paramInt1); break; case CREAR_ENTIDAD_CONSTRUIDA: //printf("CREAR_ENTIDAD_CONSTRUIDA\n"); this->gameCtrl->agregarEntidad(msg.paramNombre, msg.paramDouble1, msg.paramDouble2, 0); //setear id de entidades this->gameCtrl->setId(msg.paramDouble1, msg.paramDouble2, msg.paramInt1); this->gameCtrl->finalizarConstruccion(msg.paramInt1); break; case CAMBIAR_PERSONAJE: //printf("CAMBIAR_PERSONAJE\n"); this->gameCtrl->cambiar_personaje(msg.paramInt1, msg.paramNombre, msg.paramTipo); break; case ELIMINAR_TODOS: //printf("ELIMINAR_TODOS\n"); this->gameCtrl->eliminarTodos(msg.paramTipo); break; case PIERDE: //printf("PIERDE\n"); this->gameCtrl->meFijoSiPerdi(msg.paramNombre); break; default: break; } }
//Cambie, no hace falta que sea menor estricto Posicion Posicion::RestarPosiciones(const Posicion& p1,const Posicion& p2){ assert(p2.y <= p1.y && p2.x <= p1.x); return Posicion(p1.x-p2.x,p1.y-p2.y); }
Posicion Posicion::SumarPosiciones(const Posicion& p1,const Posicion& p2){ return Posicion(p1.x+p2.x,p1.y+p2.y); }
void AvionSecundario::setPosicion(int x, int y) { this->superficieOcupada->moverAPosicion(Posicion(x, y)); }