示例#1
0
bool Matriz::quitarEntidad(Entidad* elemento){

	if (!elemento || !elemento->verPosicion()) {
		// ErrorLog::getInstance()->escribirLog("Error al querer remover [" + elemento->name + "]: No se encuentra en el mapa.", LOG_ERROR);
		return false;
	}

	Posicion* pos = elemento->verPosicion();
	if (! posicionPertenece(pos))
		return false;

	// Obtengo el tamanio de la entidad a quitar
	int altura_x = elemento->verTamX();
	int ancho_y = elemento->verTamY();

	// Por ahora solo desreferencio a la entidad en las posiciones en que estaba ubicada
	for(int i = 0; i < altura_x; i++){
		for(int j = 0; j < ancho_y; j++) {

			casillas[pos->getRoundX() + i][pos->getRoundY() + j] = nullptr;
			mapDeOcupaciones[pos->getRoundX() + i][pos->getRoundY() + j] = 0;
			// cout << "Se vació la posicion: " << pos->toStrRound() << endl;
		}
	}
	this->cantidad_entidades--;
	return true;
}
示例#2
0
list<Posicion*> Matriz::caminoMinimo(Posicion posAct, Posicion posDest, terrain_type_t validTerrain){

	int actX = posAct.getRoundX();
	int actY = posAct.getRoundY();
	int destX = posDest.getRoundX();
	int destY = posDest.getRoundY();
	this->actualizarMapDeOcupaciones();
	return this->calculadorCamino->calcularCaminoMinimo(actX,actY,destX,destY,this->mapDeOcupaciones, this->mapDeTerreno, validTerrain);

}
示例#3
0
// Calcula la distancia hamiltoniana entre una posicion y una entidad.
int Matriz::distanciaEntre(Posicion pos, Entidad* ent) {
	int distX = 0;
	int distY = 0;

	int minX = ent->verPosicion()->getRoundX();
	int minY = ent->verPosicion()->getRoundY();
	int maxX = minX + ent->verTamX();
	int maxY = minY + ent->verTamY();

	int actX = pos.getRoundX();
	int actY = pos.getRoundY();

	if (actX < maxX && actX >= minX)
		distX = 0;
	else if (actX >= maxX)
		distX = actX - maxX + 1;
	else
		distX = minX - actX;

	if (actY < maxY && actY >= minY)
		distY = 0;
	else if (actY >= maxY)
		distY = actY - maxY + 1;
	else
		distY = minY - actY;
	return distX + distY;
}
示例#4
0
void Matriz::settearTipoTerreno(Posicion pos, terrain_type_t tipo) {
	if (this->posicionPertenece(&pos)) {
		mapDeTerreno[pos.getRoundX()][pos.getRoundY()] = tipo;
	}
}
示例#5
0
terrain_type_t Matriz::verTipoTerreno(Posicion pos) {
	if (this->posicionPertenece(&pos)) {
		return mapDeTerreno[pos.getRoundX()][pos.getRoundY()];
	}
	return TERRAIN_GRASS;
}