Exemplo n.º 1
0
void Maze::surroundMaze() {
  //bottom + top layer
  for (int x=0;x<xSize_;x++) {
    setWall(x,0,SIDE_DOWN);
    setWall(x,ySize_-1,SIDE_UP);
  }
  for (int y=0;y<ySize_;y++) {
    setWall(0,y,SIDE_LEFT);
    setWall(xSize_-1,y,SIDE_RIGHT);
  }
}
Exemplo n.º 2
0
Map::Map(int width, int height) : width(width),height(height) {
  int i;
    tiles=new Tile[width*height];
    for(i = 0; i < 80; i++){
      setWall(i,0);
      setWall(i,40);
    }

    for(i = 1; i < 40; i++){
      setWall(0,i);
      setWall(79,i);
    }
}
Exemplo n.º 3
0
dist checkSideStatic(bool accurate) {
  moveILR(-30, 0);
  rangeFGet(&r.s); // addLog(&r.s, &r.l);
  
  // Range trigs
  double rFRS = rangeFRSide(r.s.rangeFR);
  double rFLS = rangeFLSide(r.s.rangeFL);
  double rFRF = rangeFRFront(r.s.rangeFR);
  double rFLF = rangeFLFront(r.s.rangeFL);

  // Setting bools
  sidesAreEqual = ((r.s.rangeFL - r.s.rangeFL) <= 5);
  sideLInfinite = (r.s.rangeFL == 100);
  sideRInfinite = (r.s.rangeFR == 100 );
  sidesAreInfinite = (sideLInfinite == true && sideRInfinite == true);
  sideLisCloser = (r.s.rangeFL < r.s.rangeFR);
  sideLRisk = (r.s.rangeFL < 15);
  sideRRisk = (r.s.rangeFR < 15);
  sideLFar = (r.s.rangeFL > 30);
  sideRFar = (r.s.rangeFR < 40);

  // Calculate angle
  setWall();
  printf( "checkSide %lF %lF %i %i\n", rangeFLSide(r.s.rangeFL), rangeFRSide(r.s.rangeFR), r.s.rangeFL, r.s.rangeFR );
  return (dist){ r.s.rangeFL, r.s.rangeFR};
}
Exemplo n.º 4
0
void Labirinth::setWalls(int w)
// check walls already placed, than insert new wall pieces up to desired number
{
  std::cout << "at present time there are " << walls << " walls in labirinth" << std::endl;
  int rand_x;
  int rand_y;
  int i;
  int result;
  i = 0;
  while (walls < w)
  {
    ++i;
    std::cout << "placing walls..." << std::endl;
    rand_x = (rand() + time(0)) % x_side;
    rand_y = (rand() + time(0)) % y_side; 
    result = readTile(rand_x, rand_y);
    std::cout << i << " , (" << rand_x << "," << rand_y << ") , " << result << std::endl;  
    if ( result == 0)
    {
      setWall(rand_x, rand_y);
      ++walls;
      std::cout << "placed wall number " << walls << " at (" << rand_x << "," << rand_y << ")" << std::endl;
    } 
    else
    {
      std::cout << "this is just a wall or exit... another tile will be used" << std::endl;
    }
  }
  std::cout << "at present time there are " << walls << " walls in labirinth" << std::endl;
}
Exemplo n.º 5
0
void
Maze::init()
{
	int i = 0;
	int j = 0;
	int k = 0;

	index_start_row = 0;
	index_start_col = 0;
	index_goal_row = 7;
	index_goal_col = 7;

	/* init the wall with unknown */
	for (i = 0; i < mazeMAX_ROW_SIZE; i++)
	{
		for (j = 0; j < mazeMAX_COL_SIZE; j++)
		{
			setDistance(i,j,UNREACHED);
			for (k = (int) row_plus; k <= (int) col_minus; k++)
			{
				setWall(i, j, (dir_e) k, unknown);
			}
		}
	}

	/* wrap the wall */
	for (i = 0; i < mazeMAX_ROW_SIZE; i++)
	{
		setWall(i, 0, col_minus, wall);
		setWall(i, mazeMAX_ROW_SIZE - 1, col_plus, wall);
	}
	for (j = 0; j < mazeMAX_COL_SIZE; j++)
	{
		setWall(0, j, row_minus, wall);
		setWall(mazeMAX_COL_SIZE - 1, j, row_plus, wall);
	}

	/* fill the first cell */
	setWall(0, 0, row_plus, wall);
	setWall(0, 0, col_plus, empty);
	setWall(0, 0, row_minus, wall);
	setWall(0, 0, col_minus, wall);

	/* update the cell */
	updateCell();
}
Exemplo n.º 6
0
void Map::componentRendering()
{
    for(int i = 0; i < width; i++)
    {
        for(int j = 0; j < height; j++) 
        {
            //setting walls
            if(grounds[i][j].symbol == WALL) 
            {
                setWall(i,j);
            }
            //setting characters
            else if(grounds[i][j].symbol == PLAYER)
            { 
                hasPlayer = true;
                player = new Character("player",i,j,PLAYER, TCODColor::white);
                characters.push(player);
            //setting guards
            }else if(grounds[i][j].symbol == GUARD)
            {
                hasGuard = true;
                Character *guard = new Guard("guard",i,j,GUARD,
                        TCODColor::orange);
                characters.push(guard);
            //setting money
            }else if(grounds[i][j].symbol == MONEY)
            {
                hasMoney = true;
                Item *money = new Item("money",i,j,MONEY,TCODColor::green);
                items.push(money);
                amountOfMoney++;
            //setting keys
            }else if(grounds[i][j].symbol == KEY)
            {
                hasKey = true;
                numberOfKey++;
                initialNumberOfKey++;
                Item *key = new Item("key",i,j,KEY,TCODColor::cyan);
                items.push(key);
            
            //setting lock
            }else if(grounds[i][j].symbol == LOCK)
            {
                hasDoor = true;
                numberOfDoor++;
                TCODColor *te = new TCODColor(102,102,0);
                Item *lock = new Item("lock",i,j,LOCK,*te);
                items.push(lock);
            
            }
        }
    }
}
Exemplo n.º 7
0
dist checkBack(bool accurate) {
  rangeSGet(&r.s);
  backAreEqual = ((r.s.rangeFL - r.s.rangeFL) <= 5);
  backLisInfinite = (r.s.rangeSL == 38);
  backRisInfinite = (r.s.rangeSR == 38);
  backsAreInfinite = (backLisInfinite && backRisInfinite);
  backLisCloser = (r.s.rangeSL < r.s.rangeSR);
  backLRisk = (r.s.rangeSL < 8);
  backRRisk = (r.s.rangeSR < 8);
  setWall();
  return (dist){r.s.rangeSL,r.s.rangeSR};
}
Exemplo n.º 8
0
void Maze::setWall(const Point &p,Direction d,bool exists){
	switch(d){
		case DirectionLeft:
		case DirectionTop:
			if(isInside(p)){
				cellAt(p)=cellAt(p).cellBySetWall(d,exists);
			}
			break;
		case DirectionRight:
		case DirectionBottom:
			return setWall(p.neighbor(d),DirectionReverse(d),exists);
	}
}
Exemplo n.º 9
0
void Map::randomInit()
{
	tiles=new Tile[width*height];
	//generate the wall		
	for (int x = 0; x < width; x++) {
		for (int y = 0; y < height; y++) {
			bool at_edge = x == 0 || x == width - 1 || y == 0 || y == height - 1;
			TCODRandom *rng=TCODRandom::getInstance();
			int r = rng->getInt(0,100);	//random
			if (at_edge) {
				setWall(x,y); //wall around the map
			}else if(r<mode){
				setWall(x,y);	//wall randomly in the map
			}else if(r==88){
				setItem(x,y,1); //generate keys
			}else if(r==77){
				setItem(x,y,0); //generate money
			}
		}
	}
	//generate the lock
	setItem(width/2, height/2, 2);	
}
Exemplo n.º 10
0
dist checkSide(bool accurate, int angleL, int angleR) {
  sensors horizontal;

  // dist encodersDiff;
  // encodersDiff.l =  r.l.sensors[r.l.index].encodersL - r.l.sensors[prevIndex(&r.l)].encodersL;
  // encodersDiff.r =  r.l.sensors[r.l.index].encodersR - r.l.sensors[prevIndex(&r.l)].encodersR;
  // double encodersAngle = angle(encodersDiff.l, encodersDiff.r)*180/M_PI;
  // printf("Encoders angle %lf\n", encodersAngle);
  
  // if (isRotatingL) initial = (dist){.l = -60, .r = 30}; // TODO to be automagically calculated
  // if (isRotatingR) initial = (dist){.l = -30, .r = 60};
  
  // Tracking horizontal
  moveILR(-45, 45);
  rangeFGet(&horizontal);
  /*/printf("\n UUUUUUU %i %i\n\n", horizontal.rangeFL, horizontal.rangeFR);/**/
  
  // Tracking wanted angle
  moveILR(angleL, angleR);
  rangeFGet(&r.s); // addLog(&r.s, &r.l);
  printf("\n checkSide %d \n", r.s.rangeFL);
  
  // Range trigs
  double rFRS = rangeFRSide(r.s.rangeFR);
  double rFLS = rangeFLSide(r.s.rangeFL);
  double rFRF = rangeFRFront(r.s.rangeFR);
  double rFLF = rangeFLFront(r.s.rangeFL);

  // Setting bools
  sidesAreEqual = ((r.s.rangeFL - r.s.rangeFL) <= 5);
  sideLInfinite = (r.s.rangeFL == 100);
  sideRInfinite = (r.s.rangeFR == 100 );
  sidesAreInfinite = (sideLInfinite == true && sideRInfinite == true);
  sideLisCloser = (r.s.rangeFL < r.s.rangeFR);
  sideLRisk = (rangeFLSide(r.s.rangeFL) < 15);
  sideRRisk = (rangeFRSide(r.s.rangeFR) < 15);

  // Calculate angle
  int angleDifL = angleL + 45;
  int angleDifR = angleR - 45;
  angleWall.l = (horizontal.rangeFL != 100 && r.s.rangeFL != 100) ? wallAngle(horizontal.rangeFL, r.s.rangeFL, angleDifL) : -1;
  angleWall.r = (horizontal.rangeFR != 100 && r.s.rangeFR != 100) ? wallAngle(horizontal.rangeFR, r.s.rangeFR, angleDifR) : -1;

  // Return distance and set wall if needed
  setWall();
  printf( "checkSide %lF %lF %i %i\n", rangeFLSide(r.s.rangeFL), rangeFRSide(r.s.rangeFR), r.s.rangeFL, r.s.rangeFR );
  return (dist){ rangeFLSide(r.s.rangeFL), rangeFRSide(r.s.rangeFR)};
}
Exemplo n.º 11
0
bool View::handleEvent( const Event& event )
{
    switch( event.type )
    {
    case Event::VIEW_RESIZE:
    {
        const ResizeEvent& resize = event.resize;
        if( resize.dw == 0.f || resize.dh == 0.f )
            return true;

        switch( getCurrentType( ))
        {
        case TYPE_WALL:
        {
            const float ratio( resize.dw / resize.dh );
            Wall wall( impl_->baseFrustum.getWall( ));
            wall.resizeHorizontal( ratio );

            lunchbox::ScopedFastWrite mutex( impl_->eventLock );
            setWall( wall );
            break;
        }

        case View::TYPE_PROJECTION:
        {
            const float ratio( resize.dw / resize.dh );
            eq::Projection projection( impl_->baseFrustum.getProjection( ));
            projection.resizeHorizontal( ratio );

            lunchbox::ScopedFastWrite mutex( impl_->eventLock );
            setProjection( projection );
            break;
        }

        case eq::View::TYPE_NONE:
            break;
        default:
            LBUNIMPLEMENTED;
            break;
        }
        return true;
    }
    }

    return false;
}
Exemplo n.º 12
0
void SquareMaze::solveMaze_helper(int x, int y, vector<int> & path, int * lastRow)
{
	if(y == height - 1)
		lastRow[x] = path.size();
	if(canTravel(x, y, 0))
	{
		path.push_back(0);
		setWall(x, y, 0, true);
		solveMaze_helper(x + 1, y, path, lastRow);
		path.pop_back();
		setWall(x, y, 0, false);
	}
	
	if(canTravel(x, y, 1))
	{
		path.push_back(1);
		setWall(x, y, 1, true);
		solveMaze_helper(x, y + 1, path, lastRow);
		path.pop_back();
		setWall(x, y, 1, false);
	}
	
	if(canTravel(x, y, 2))
	{		
		path.push_back(2);
		setWall(x - 1, y, 0, true);
		solveMaze_helper(x - 1, y, path, lastRow);
		path.pop_back();
		setWall(x - 1, y, 0, false);
	}
	
	if(canTravel(x, y, 3))
	{
		path.push_back(3);
		setWall(x, y - 1, 1, true);
		solveMaze_helper(x, y - 1, path, lastRow);
		path.pop_back();
		setWall(x, y - 1, 1, false);
	}
	return;
}
Exemplo n.º 13
0
void TerrainTile::decode(const int bitset)
{
  clearFlags();

  if (bitset & 0x1)    {  setTree(true);      }
  if (bitset & 0x2)    {  setRock(true);      }
  if (bitset & 0x4)    {  setWater(true);     }
  if (bitset & 0x8)    {  setBuilding(true);  }
  if (bitset & 0x10)   {  setTree(true);      }
  if (bitset & 0x20)   {  setGarden(true);    }
  if (bitset & 0x40)   {  setRoad(true);      }
  if (bitset & 0x100)  {  setAqueduct(true);  }

  if (bitset & 0x200)  {  setElevation(true); }
  if (bitset & 0x400)  {  setRock( true );    }
  if (bitset & 0x800)  {  setMeadow(true);    }
  if (bitset & 0x4000) {  setWall(true);      }
  if (bitset & 0x8000) {  setGateHouse(true); }
}
Exemplo n.º 14
0
bool View::handleEvent(const EventType type, const SizeEvent& event)
{
    if (type != EVENT_VIEW_RESIZE)
        return false;

    if (event.dw == 0.f || event.dh == 0.f)
        return true;

    switch (getCurrentType())
    {
    case TYPE_WALL:
    {
        const float ratio(event.dw / event.dh);
        Wall wall(_impl->baseFrustum.getWall());
        wall.resizeHorizontal(ratio);

        lunchbox::ScopedFastWrite mutex(_impl->eventLock);
        setWall(wall);
        return true;
    }

    case View::TYPE_PROJECTION:
    {
        const float ratio(event.dw / event.dh);
        eq::Projection projection(_impl->baseFrustum.getProjection());
        projection.resizeHorizontal(ratio);

        lunchbox::ScopedFastWrite mutex(_impl->eventLock);
        setProjection(projection);
        return true;
    }

    default:
        LBUNIMPLEMENTED;
    case eq::View::TYPE_NONE:
        return false;
    }
}
Exemplo n.º 15
0
//Se llama desde el cliente y es un paquete recibido del servidor
void NetworkEngine::managePacketFromServer( RakNet::Packet * packet )
{
	switch (packet->data[0])
	{
	//Mensajes de Raknet
	case ID_DISCONNECTION_NOTIFICATION:
		removeServerFile();
		close();
	case ID_CONNECTION_LOST:
		close();
		GameManager::getInstance()->changeState(StateMenuMain::getInstance());
		break;
	case ID_INVALID_PASSWORD:
		std::cout << "ERROR: El servidor al que intentabas reconectarte no es el mismo del que hay ahora\n";
		removeServerFile();
		close();
		GameManager::getInstance()->changeState(StateMenuMain::getInstance());
	case ID_UNCONNECTED_PONG:
		lanServerFound(packet);
		break;

	//Nuestros mensajes
	case ID_SERVER_PLAYER_LIST:
		//Recoger jugadores 
		//El problema es como avisa desde aquí al estado para que actualice la GUI
		updatePlayerList(packet);
		break;
	case ID_SERVER_STRING_MESSAGE:
		showMessageFromServer(packet);

		break;
	case ID_SERVER_GAME_STARTING:
		createFileServer();
		if(!waitingForServer) //Parche para que se conecte sin cambiar de estado para Test Online
		{
			GameManager::getInstance()->changeState(StateClientInGame::getInstance());
		}
		waitingForServer = false;
		break;

	case ID_SERVER_YOUR_CHARACTER:
		putTheCharacter(packet);
		break;
	case ID_SERVER_GIVE_EXPERIENCE:
		experienceForPlayers(packet);
		break;
	case ID_GLOBAL_GAMEOBJECT_MESSAGE:
		onGameObjectMessage(packet);
		break;
	case ID_SET_EMPTY:
		setEmpty(packet);
		break;
	case ID_SET_WALL:
		setWall(packet);
		break;
	case ID_GAME_OVER:
		gameOverFromServer(packet);
		break;
	case ID_NEXT_WAVE:
		nextWave(packet);
		break;
	}
}
Exemplo n.º 16
0
bool SquareMaze::solveMaze_second_helper(int x, int y, vector<int> & path, int dest)
{
	if(x == dest&&y == height -1)
		return true;
	if(canTravel(x, y, 0))
	{
		path.push_back(0);
		setWall(x, y, 0, true);
		if(solveMaze_second_helper(x + 1, y, path, dest))
		{
			setWall(x, y, 0, false);
			return true;
		}
		path.pop_back();
		setWall(x, y, 0, false);
	}
	
	if(canTravel(x, y, 1))
	{
		path.push_back(1);
		setWall(x, y, 1, true);
		if(solveMaze_second_helper(x, y + 1, path, dest))
		{
			setWall(x, y, 1, false);
			return true;
		}
		path.pop_back();
		setWall(x, y, 1, false);
	}
	
	if(canTravel(x, y, 2))
	{		
		path.push_back(2);
		setWall(x - 1, y, 0, true);
		if(solveMaze_second_helper(x - 1, y, path, dest))
		{
			setWall(x - 1, y, 0, false);
			return true;
		}
		path.pop_back();
		setWall(x - 1, y, 0, false);
	}
	
	if(canTravel(x, y, 3))
	{
		path.push_back(3);
		setWall(x, y - 1, 1, true);
		if(solveMaze_second_helper(x, y - 1, path, dest))
		{
			setWall(x, y-1, 1, false);
			return true;
		}
		path.pop_back();
		setWall(x, y - 1, 1, false);
	}
	return false;
}