Ejemplo n.º 1
0
void            Map::setBonus()
{
    checkRight();
    checkLeft();
    checkUp();
    checkDown();
}
Ejemplo n.º 2
0
void testNavigate(){
    
    int check, nextX, nextY;
    initDir(); //start by getting the initial direction
    solution = createStack();
    push(solution, current); // add the starting square to the stack
    
    while (current->val != 'F'){  // the maze sloving loop
        printf("current position: (%d, %d)\ncurrent direction: %c\n",current->x, current->y,dir);
        switch(dir){
            case 'n':
                check = checkUp();
                nextX = current->x;
                nextY = current->y - 1;
                break;
            case 's':
                check = checkDown();
                nextX = current->x;
                nextY = current->y + 1;
                break;
            case 'e':
                check = checkRight();
                nextX = current->x + 1;
                nextY = current->y;
                break;
            case 'w':
                check = checkLeft(); 
                nextX = current->x - 1;
                nextY = current->y;
                break;
        } 
        if (check == 1){ // if you can move, the next space is not a wall
            printf("the square ahead is not a wall!\n");
            if (maze[nextX][nextY]->wasHere == 1){ //we have been there already
                printf("we have been here before!\n");
                if (otherOptions(nextX, nextY) == 1){ // there are other options
                    printf("we have other options, lets turn\n");
                    changeDir();
                    printf("new direction: %c\n",dir);
                } else { // no other options will need to go back to where we have been
                    printf("we have no other options we must go this way\n");
                    pop(solution); // pop from stack
                    current->deadEnd = 1;
                    current = maze[nextX][nextY]; // move
                }
            } else {
                printf("we have not been here before, lets go!\n");
                current = maze[nextX][nextY]; // move
                current-> wasHere = 1;
                push(solution, current); // add to stack
            }
        } else {
            printf("the square ahead is a wall, we must change directions\n");
            changeDir();
            printf("new direction: %c\n",dir);
        }
        char c = getchar();
    }
}
Ejemplo n.º 3
0
//------------------------------------------------------------------------------
void
Game::checkBorders()
{
    checkLeft();
    checkRight();
    checkTop();
    checkBottom();
}
Ejemplo n.º 4
0
int main()                                    // Main function
{
  low(26);
  low(27);
  int irLeft, irRight;
  // Add startup code here.
 
  int leftDist, rightDist;

  while(1)
  {
    drive_setRampStep(10);
    drive_ramp(64, 64);
    
    while(1)
    {
      
      irLeft = checkLeft();
      irRight = checkRight();
      irRight = ping_cm(8);
      print ("left = %d,  right = %d \n", irLeft, irRight);
      if(irLeft == 1)
      {
        high(26);
      }
      else
      {
        low(26);
      }        
      if(ping_cm(8)<=10)
      {
        high(27);
      }
      else
      {
        low(27);
      }                        
      if(irLeft == 1)
      {
        
        drive_ramp(0, 0);
        turnLeftH();
        print (" Left empty hall detected");
        break;
      } 
      if (ping_cm(8)<=9)
      {
        drive_ramp(0, 0);
        turnBack();
        print (" End of the line");
        break;
      }               
    }      
  }    
    
     
}
Ejemplo n.º 5
0
void Character::moveLeft(RMTiledMap *tiledMap){
    if(this->getPosition().x == 0 && this->getPosition().y == 13){
        this->setPosAgian(ccp(WIDTH - 1, 13), (CCLayer*)this->getSprite()->getParent() , tiledMap);
        this->setRunCurrent(2);
    }
    else if(checkLeft(tiledMap, this->position)){
        this->spr->runAction(CCMoveBy::create(this->getVelocity(), ccp(tiledMap->getTiledMap()->getTileSize().width * (-1), 0)));
        this->position = ccp(this->position.x - 1, this->position.y);
        this->setRunCurrent(2);
    }
}
Ejemplo n.º 6
0
bool BoundingBox::pointInBounds(int xp, int yp)
{
    // Check if the point is in between the top bottom and side lines (all return 0 or negative)
    if(checkTop(xp,yp)<= 0 && 
       checkBottom(xp,yp) <= 0 && 
       checkLeft(xp,yp)<=0 &&
       checkRight(xp,yp) <= 0)
        return true;
    
    return false;
}
Ejemplo n.º 7
0
//判断上下左右
void RootEngine::checkFourSides(StarModel* model)
{
    if (checkedBlocks->containsObject(model)) {
        return;
    }else {
        checkedBlocks->addObject(model);
    }
    checkUp(model);
    checkDown(model);
    checkLeft(model);
    checkRight(model);
}
Ejemplo n.º 8
0
void navigate(){
    
    int check, nextX, nextY;
    initDir(); //start by getting the initial direction
    solution = createStack();
    push(solution, current); // add the starting square to the stack
    
    while (current->val != 'F'){  // the maze sloving loop
        switch(dir){
            case 'n':
                check = checkUp();
                nextX = current->x;
                nextY = current->y - 1;
                break;
            case 's':
                check = checkDown();
                nextX = current->x;
                nextY = current->y + 1;
                break;
            case 'e':
                check = checkRight();
                nextX = current->x + 1;
                nextY = current->y;
                break;
            case 'w':
                check = checkLeft(); 
                nextX = current->x - 1;
                nextY = current->y;
                break;
        }
        
        if (check == 1){ // if you can move, the next space is not a wall
            if (maze[nextX][nextY]->wasHere == 1){ //we have been there already
                if (otherOptions(nextX, nextY) == 1){ // there are other options
                    changeDir();
                } else { // no other options will need to go back to where we have been
                    pop(solution); // pop from stack
                    current->deadEnd = 1;
                    current = maze[nextX][nextY]; // move
                }
            } else {
                current = maze[nextX][nextY]; // move
                current-> wasHere = 1;
                push(solution, current); // add to stack
            }
        } else {
            changeDir();
        }
    }
}
Ejemplo n.º 9
0
void BoundingBox::calculateResize(int xp, int yp,bool locked, int corner, double *ans)
{
    double  xn = 0, 
            yn = 0, 
            dh = 0, 
            dw = 0,
            xO1 = 0,
            yO1 = 0;
    
    if(corner == CBL)
    {
        
        // Find intersection (xn, yn) of two lines
        // bottom of element and perpendicular line going through (xp, yp)
        xn = (mainSlope * xp - sideSlope * xO - yp + yO) / (mainSlope - sideSlope);
        yn = mainSlope * (xn - xp) + yp;
        
        // Calculate the change in width and height (dw, dh)
        dh = sqrt( pow((xO - xn),2) + pow((yO - yn),2) );
        dw = sqrt( pow((xp - xn),2) + pow((yp - yn),2) );
        
        // If the point is inside the box (negative value from checkLeft/Bottom)
        // The size is getting smaller
        if(checkLeft(xp, yp) < 0)
            dw = dw * -1;
        if(checkBottom(xp, yp) < 0)
            dh = dh * -1;
        
        // if width/ height is negative invert the dw/dh
        if(width < 0)
            dw = dw*-1;
        if(height < 0)
            dh = dh*-1;
        
        // If the aspect ratio is locked choose the bigger change and scale the other appropriately
        if(locked)
        {
            if(fabs(dw) > fabs(dh))
            {            
                // Use dw, scale height proportionaly to find dh
                double scale = (double)(dw+width)/width;
                double h = height*scale;
                
                // The new dh
                dh = h - height;
            }else
            {
                double scale = (double)(dh+height)/height;
                double w = width*scale;
                
                // The new dw
                dw = w - width;
            }
        }
        
        // New origin is (xp,yp)
        xO1 = xp;
        yO1 = yp;
    }
    
    if(corner == CBR)
    {
        // Find intersection (xn, yn) of two lines
        // bottom of element and perpendicular line going through (xp, yp)
        xn = (mainSlope * xp - sideSlope * xBR - yp + yBR) / (mainSlope - sideSlope);
        yn = mainSlope * (xn - xp) + yp;
        
        // Calculate the change in width and height (dw, dh)
        dh = sqrt( (xBR - xn)*(xBR - xn) + (yBR - yn)*(yBR - yn) );
        dw = sqrt( (xp - xn)*(xp - xn) + (yp - yn)*(yp - yn) );
        
        // If the point is inside the right or bottom then the shape is getting smaller dw/dh should be negative
        if(checkRight(xp, yp) < 0)
            dw = dw * -1;
        if(checkBottom(xp, yp) < 0)
            dh = dh * -1;
        
        // if width/ height is negative invert the dw/dh
        if(width < 0)
            dw = dw*-1;
        if(height < 0)
            dh = dh*-1;
        
        // If the aspect ratio is locked choose the bigger change and scale the other appropriately
        if(locked)
        {
            if(fabs(dw) > fabs(dh))
            {            
                // Use dw, scale height proportionaly to find dh
                double scale = (double)(dw+width)/width;
                double h = height*scale;
                
                // The new dh
                dh = h - height;
            }else
            {
                double scale = (double)(dh+height)/height;
                double w = width*scale;
                
                // The new dw
                dw = w - width;
            }
        }
        
        // Calculate the new origin (xO1, yO1)
        xO1 = xO + dh * cos(angle - PI/2); // angle minus 90 degrees
        yO1 = yO + dh * sin(angle - PI/2); // angle minus 90 degrees
    }
    
    if(corner == CTR)
    {
        // Find intersection (xn, yn) of two lines
        // bottom of element and perpendicular line going through (xp, yp)
        xn = (mainSlope * xp - sideSlope * xTR - yp + yTR) / (mainSlope - sideSlope);
        yn = mainSlope * (xn - xp) + yp;
        
        
        // Calculate the change in width and height (dw, dh)
        dh = sqrt( (xTR - xn)*(xTR - xn) + (yTR - yn)*(yTR - yn) );
        dw = sqrt( (xp - xn)*(xp - xn) + (yp - yn)*(yp - yn) );
        
        // Retain the direction of the change 
        // Acts opposite if angle is below the x axis
        if(checkRight(xp, yp) < 0)// && angle > 0 && angle < 180 || checkRight(xp, yp) > 0 && angle >180)
            dw = dw * -1;
        if(checkTop(xp, yp) < 0 )//&& angle > 0 && angle < 180)
            dh = dh * -1;
        
        // if width/ height is negative invert the dw/dh
        if(width < 0)
            dw = dw*-1;
        if(height < 0)
            dh = dh*-1;
        
        
        // If the aspect ratio is locked choose the bigger change and scale the other appropriately
        if(locked)
        {
            if(fabs(dw) > fabs(dh))
            {            
                // Use dw, scale height proportionaly to find dh
                double scale = (double)(dw+width)/width;
                double h = height*scale;
                
                // The new dh
                dh = h - height;
            }else
            {
                double scale = (double)(dh+height)/height;
                double w = width*scale;
                
                // The new dw
                dw = w - width;
            }
        }
        
        // Origin remains the same
        xO1 = xO;
        yO1 = yO;
    }
    
    if(corner == CTL)
    {
        // Find intersection (xn, yn) of two lines
        // bottom of element and perpendicular line going through (xp, yp)
        xn = (sideSlope * xTL - mainSlope * xp + yp - yTL) / (sideSlope - mainSlope);
        yn = yp - mainSlope * (xp - xn);
        
        
        // Calculate the change in width and height (dw, dh)
        dh = sqrt( (xn - xTL)*(xn - xTL) + (yn - yTL)*(yn - yTL) );
        dw = sqrt( (xp - xn)*(xp - xn) + (yp - yn)*(yp - yn) );
        
        
        // If the point is inside the box (negative value from checkLeft/Top)
        // The size is getting smaller
        if(checkLeft(xp, yp) < 0)
            dw = dw * -1;
        if(checkTop(xp, yp) < 0)
            dh = dh * -1;
        
        // if width/ height is negative invert the dw/dh
        if(width < 0)
            dw = dw*-1;
        if(height < 0)
            dh = dh*-1;
        
        // If the aspect ratio is locked choose the bigger change and scale the other appropriately
        if(locked)
        {
            if(fabs(dw) > fabs(dh))
            {            
                // Use dw, scale height proportionaly to find dh
                double scale = (double)(dw+width)/width;
                double h = height*scale;
                
                // The new dh
                dh = h - height;
            }else
            {
                double scale = (double)(dh+height)/height;
                double w = width*scale;
                
                // The new dw
                dw = w - width;
            }
        }
        
        // Calculate the new origin (xO1, yO1)
        xO1 = xO + dw * cos(angle + PI); // 180 plus  angle
        yO1 = yO + dw * sin(angle + PI); // 180 plus angle
    }
    
    /// final new origin width and height
    ans[0] = xO1;
    ans[1] = yO1;
    ans[2] = width + dw;
    ans[3] = height + dh;
    
    
}
Ejemplo n.º 10
0
//return how many lifing cels are around a position in field.
int totalAround(uint8_t *field, int position){
  int around = checkUpper(field, position)+checkLower(field, position)+checkLeft(field, position)+checkRight(field, position)+checkUpperLeft(field, position)+checkUpperRight(field, position)+checkLowerLeft(field, position)+checkLowerRight(field, position);
  return around;
}
Ejemplo n.º 11
0
int checkScrollDirection(int prevX, int prevY, int x, int y)
{
        int badmove = 1;
        moveRight = 0, moveLeft = 0, moveDown = 0, moveUp = 0;
        
        /* Check the 8 possible move combinations to ensure correct bounds checking
            If the move is possible call the corresponding direction checks that update scrolling values
            If move is not possible we return badmove and the x and y values are fixed*/
        if(prevX < x && prevY < y) /* move right and down */
        {
            if (screenRight < MAP_WIDTH - 1 && screenBottom < MAP_HEIGHT - 1)
            {
                checkRight();
                checkDown();
            }
            else
            {
                return badmove;
            }
        }
        else if(prevX < x && prevY > y) /* move right and up */
        {
            if (screenRight < MAP_WIDTH - 1 && screenTop > 0)
            {
                checkRight();
                checkUp();
            }
            else
            {
                return badmove;
            }
        }
        else if(prevX > x && prevY < y) /* move left and down */
        {
            if(screenLeft > 0 && screenBottom < MAP_HEIGHT - 1)
            {
                checkLeft();
                checkDown();
            }
            else
            {
                return badmove;
            }
        }
        else if(prevX > x && prevY > y) /* move left and up */
        {
             if (screenTop > 0 && screenLeft > 0)
             {
                 checkLeft();
                 checkUp();
             }
             else
             {
                 return badmove;
             }
        }
        else if(prevX < x) /* move right */
        {
            if (screenRight < MAP_WIDTH - 1)
            {
                checkRight();
            }
            else
            {
                return badmove;
            }
        }
        else if(prevX > x) //moveLeft
        {
           if (screenLeft > 0)
           {
               checkLeft();
           }
           else
           {
               return badmove;
           }
        }
        else if(prevY < y) //moveDown
        {
            if (screenBottom < MAP_HEIGHT - 1)
            {
                checkDown();
            }
            else
            {
                return badmove;
            }
        }
        else if(prevY > y) //moveUp
        {
          if (screenTop > 0)
          {
                checkUp();
          }
          else
          {
                return badmove;
          }
        }
       
       /* copy necessary map rows and/or columns to the background buffer */
        if (moveLeft)
		{
			CopyColumnToBackground(screenLeft, nextColumn, mapTop, mapBottom, starmapscrn_Map, bg0map, MAP_COLUMNS);
		}
		if (moveRight)
		{
			CopyColumnToBackground(screenRight, nextColumn, mapTop, mapBottom, starmapscrn_Map, bg0map, MAP_COLUMNS);
		}
        if (moveUp)
		{
			CopyRowToBackground(screenTop, nextRow, mapLeft, mapRight, starmapscrn_Map, bg0map, MAP_COLUMNS);
		}
		if (moveDown)
		{
			CopyRowToBackground(screenBottom, nextRow, mapLeft, mapRight, starmapscrn_Map, bg0map, MAP_COLUMNS);
		}
		return 0;
}
Ejemplo n.º 12
0
void Cat::autoRun(RMTiledMap* tileMap){
    if(this->getRunCurrent() == 1){
        if(this->checkBelow(tileMap, this->getPosition()) ||
           this->checkUpward(tileMap, this->getPosition())){
            int randNumber = rand() % 4;
            if(!checkRight(tileMap, this->getPosition())){
                randNumber = rand() % 2;
            }
            switch (randNumber) {
                case 3:
                    setRunValue(1);
                    break;
                case 2:
                    setRunValue(1);
                    break;
                case 1:
                    if(checkUpward(tileMap, this->getPosition())){
                        setRunValue(4);
                    }
                    else if (checkBelow(tileMap, this->getPosition())){
                        setRunValue(3);
                    }
                    break;
                case 0:
                    if(this->checkBelow(tileMap, this->getPosition())){
                        setRunValue(4);
                    }
                    else if (checkUpward(tileMap, this->getPosition())){
                        setRunValue(3);
                    }
                    break;
                default:
                    break;
            }
        }
        else if(!checkRight(tileMap, this->getPosition())){
            setRunValue(2);
        }
    }
    else if(this->getRunCurrent() == 2){
        if(this->checkBelow(tileMap, this->getPosition()) ||
           this->checkUpward(tileMap, this->getPosition())){
            int randNumber = rand() % 4;
            if(!checkLeft(tileMap, this->getPosition())){
                randNumber = rand() % 2;
            }
            switch (randNumber) {
                case 3:
                    setRunValue(2);
                    break;
                case 2:
                    setRunValue(2);
                    break;
                case 1:
                    if(checkUpward(tileMap, this->getPosition())){
                        setRunValue(4);
                    }
                    else if (checkBelow(tileMap, this->getPosition())){
                        setRunValue(3);
                    }
                    break;
                case 0:
                    if(this->checkBelow(tileMap, this->getPosition())){
                        setRunValue(4);
                    }
                    else if (checkUpward(tileMap, this->getPosition())){
                        setRunValue(3);
                    }
                    break;
                default:
                    break;
            }
        }
        else if(!checkLeft(tileMap, this->getPosition())){
            setRunValue(1);
        }
    }
    else if(this->getRunCurrent() == 3){
        if(this->checkLeft(tileMap, this->getPosition()) ||
           this->checkRight(tileMap, this->getPosition())){
            int randNumber = rand() % 4;
            if(!checkUpward(tileMap, this->getPosition())){
                randNumber = rand() % 2;
            }
            switch (randNumber) {
                case 3:
                    setRunValue(3);
                    break;
                case 2:
                    setRunValue(3);
                    break;
                case 1:
                    if(checkRight(tileMap, this->getPosition())){
                        setRunValue(1);
                    }
                    else if (checkLeft(tileMap, this->getPosition())){
                        setRunValue(2);
                    }
                    break;
                case 0:
                    if(this->checkLeft(tileMap, this->getPosition())){
                        setRunValue(2);
                    }
                    else if (checkRight(tileMap, this->getPosition())){
                        setRunValue(1);
                    }
                    break;
                default:
                    break;
            }
        }
        else if(!checkUpward(tileMap, this->getPosition())){
            setRunValue(4);
        }
    }
    else if(this->getRunCurrent() == 4){
        if(this->checkLeft(tileMap, this->getPosition()) ||
           this->checkRight(tileMap, this->getPosition())){
            int randNumber = rand() % 4;
            if(!checkBelow(tileMap, this->getPosition())){
                randNumber = rand() % 2;
            }
            switch (randNumber) {
                case 3:
                    setRunValue(4);
                    break;
                case 2:
                    setRunValue(4);
                    break;
                case 1:
                    if(checkRight(tileMap, this->getPosition())){
                        setRunValue(1);
                    }
                    else if (checkLeft(tileMap, this->getPosition())){
                        setRunValue(2);
                    }
                    break;
                case 0:
                    if(this->checkLeft(tileMap, this->getPosition())){
                        setRunValue(2);
                    }
                    else if (checkRight(tileMap, this->getPosition())){
                        setRunValue(1);
                    }
                    break;
                default:
                    break;
            }
        }
        else if(!checkBelow(tileMap, this->getPosition())){
            setRunValue(3);
        }
    }
}
Ejemplo n.º 13
0
void FloorGenerator::assignDown(bool room)
{
	int temp = rand() % 8;
	int posX = start.front().getX();
	int posY = start.front().getY();

	const int ONEU = 0, TWOV = 1, TWOUL= 2, TWOUR = 3, THREEU = 4, THREEL = 5, THREER = 6, FOUR = 7;

	switch(temp)
	{
	case ONEU:
		{
			bool down, left, right;

			if(posX+2 > LIMIT-1)
				down = true;
			else
				down = !checkDown2(posX+2, posY);

			if(posY-1 < 0)
				left = true;
			else
				left = !checkLeft2(posX+1, posY-1);

			if(posY+1 > LIMIT-1)
				right = true;
			else
				right = !checkRight2(posX+1, posY+1);

			if(down && left && right)
			{
				if(room)
					pushRoom(posX+1, posY, roomoneU, room);
				else
					pushCor(posX+1, posY, oneU, room);
			}else
				assignDown(room);
			break;
		}
	case TWOV:
		{
			if(posX + 2 > LIMIT-1)
			{
				assignDown(room);
				break;
			}else
			{
				bool down, left, right;

				if(posX+2 > LIMIT-1)
					down = false;
				else
					down = checkDown(posX+2, posY);

				if(posY-1 < 0)
					left = true;
				else
					left = !checkLeft2(posX+1, posY-1);

				if(posY+1 > LIMIT-1)
					right = true;
				else
					right = !checkRight2(posX+1, posY+1);

				if(down && left && right)
				{
					if(room)
						pushRoom(posX+1, posY, roomtwoV, room);
					else
						pushCor(posX+1, posY, twoV, room);
					break;
				}else
					assignDown(room);
			}
			break;
		}
	case TWOUL:
		{
			if(posY-1 < 0)
			{
				assignDown(room);
				break;
			}else
			{
				bool down, left, right;
				if(posX+2 > LIMIT-1)
					down = true;
				else
					down = !checkDown2(posX+2, posY);

				if(posY-1 < 0)
					left = false;
				else
					left = checkLeft(posX+1, posY-1);

				if(posY+1 > LIMIT-1)
					right = true;
				else
					right = !checkRight2(posX+1, posY+1);

				if(down && left && right)
				{
					if(room)
						pushRoom(posX+1, posY, roomtwoUL, room);
					else
						pushCor(posX+1, posY, twoUL, room);

				}else
					assignDown(room);
			}
			break;
		}
	case TWOUR:
		{
			if(posY+1 > LIMIT-1)
			{
				assignDown(room);
				break;
			}else
			{
				bool down, left, right;

				if(posX+2 > LIMIT-1)
					down = true;
				else
					down = !checkDown2(posX+2, posY);

				if(posY-1 < 0)
					left = true;
				else
					left = !checkLeft2(posX+1, posY-1);

				if(posY+1 > LIMIT-1)
					right = false;
				else
					right = checkRight(posX+1, posY+1);

				if(down && left && right)
				{
					if(room)
						pushRoom(posX+1, posY, roomtwoUR, room);
					else
						pushCor(posX+1, posY, twoUR, room);
				}else
					assignDown(room);
			}
			break;
		}
	case THREEU:
		{
			if(posY-1 < 0)
			{
				assignDown(room);
				break;
			}else if(posY+1 > LIMIT-1)
			{
				assignDown(room);
				break;
			}else
			{
				bool down, left, right;
				if(posX+2 > LIMIT-1)
					down = true;
				else
					down = !checkDown2(posX+2, posY);

				if(posY-1 < 0)
					left = false;
				else
					left = checkLeft(posX+1, posY-1);

				if(posY+1 > LIMIT-1)
					right = false;
				else
					right = checkRight(posX+1, posY+1);

				if(down && left && right)
				{
					if(room)
						pushRoom(posX+1, posY, roomthreeU, room);
					else
						pushCor(posX+1, posY, threeU, room);

				}else
					assignDown(room);

			}
			break;
		}
	case THREEL:
		{
			if(posY-1 < 0)
			{
				assignDown(room);
				break;
			}else if(posX+2 > LIMIT-1)
			{
				assignDown(room);
				break;
			}else
			{
				bool down, left, right;

				if(posX+2 > LIMIT-1)
					down = false;
				else
					down = checkDown(posX+2, posY);

				if(posY-1 < 0)
					left = false;
				else
					left = checkLeft(posX+1, posY-1);

				if(posY+1 > LIMIT-1)
					right = true;
				else
					right = !checkRight2(posX+1, posY+1);

				if(down && left && right)
				{
					if(room)
						pushRoom(posX+1, posY, roomthreeL, room);
					else
						pushCor(posX+1, posY, threeL, room);
				}else
					assignDown(room);
			}
			break;
		}
	case THREER:
		{
			if(posY+1 > LIMIT-1)
			{
				assignDown(room);
				break;
			}else if(posX+2 > LIMIT-1)
			{
				assignDown(room);
				break;
			}else
			{
				bool down, left, right;

				if(posX+2 > LIMIT-1)
					down = false;
				else
					down = checkDown(posX+2, posY);

				if(posY-1 < 0)
					left = true;
				else
					left = !checkLeft2(posX+1, posY-1);

				if(posY+1 > LIMIT-1)
					right = false;
				else
					right = checkRight(posX+1, posY+1);

				if(down && left && right)
				{
					if(room)
						pushRoom(posX+1, posY, roomthreeR, room);
					else
						pushCor(posX+1, posY, threeR, room);
				}else
					assignDown(room);
			}
			break;
		}
	case FOUR:
		{
			if(posY+1 > LIMIT-1)
			{
				assignDown(room);
				break;
			}else if(posY-1 < 0)
			{
				assignDown(room);
				break;
			}else if(posX+2 > LIMIT-1)
			{
				assignDown(room);
				break;
			}else
			{
				bool down, left, right;
				if(posX+2 > LIMIT-1)
					down = false;
				else
					down = checkDown(posX+2, posY);

				if(posY-1 < 0)
					left = false;
				else
					left = checkLeft(posX+1, posY-1);

				if(posY+1 > LIMIT-1)
					right = false;
				else
					right = checkRight(posX+1, posY+1);

				if(down && left && right)
				{
					if(room)
						pushRoom(posX+1, posY, roomfour, room);
					else
						pushCor(posX+1, posY, four, room);
				}else
					assignDown(room);
			}
			break;
		}
	}//end switch

}
Ejemplo n.º 14
0
void FloorGenerator::assignUp(bool room)
{
	//8 different types of Corridors can be assigned
	int temp = rand() % 8;
	int posX = start.front().getX();
	int posY = start.front().getY();

	const int ONED = 0, TWOV = 1, TWODR = 2, TWODL = 3, THREED = 4, THREEL = 5, THREER = 6, FOUR = 7;

	switch(temp)
	{
	case ONED: 
		{
			//create temp variables to store checks
			bool up, left, right;

			//determine whether or not to check for up, left, right due to limits
			if(posX-2 < 0)
				up = true;
			else
				up = !checkUp2(posX-2, posY);

			if(posY-1 < 0)
				left = true;
			else
				left = !checkLeft2(posX-1, posY-1);

			if(posY+1 > LIMIT-1)
				right = true;
			else
				right = !checkRight2(posX-1, posY+1);


			if(up && left && right)					
			{
				if(room)
					pushRoom(posX-1, posY, roomoneD, room);
				else
					pushCor(posX-1, posY, oneD, room);
			}else
				assignUp(room);
			break;
		}
	case TWOV:
		{
			//check for available position above where this piece is placed
			if(posX - 2 < 0)
			{
				//can't push assign a new piece
				assignUp(room);
				break;
			}else
			{
				//create temp variables to store checks
				bool up, left, right;

				//determine whether or not to check for up, left, right due to limits
				if(posX-2 < 0)
					up = false;
				else
					up = checkUp(posX-2, posY);

				if(posY-1 < 0)
					left = true;
				else
					left = !checkLeft2(posX-1, posY-1);

				if(posY+1 > LIMIT-1)
					right = true;
				else
					right = !checkRight2(posX-1, posY+1);


				//check for compatibility
				if(up && left && right)
				{
					//create a twoV corridor to push
					if(room)
						pushRoom(posX-1, posY, roomtwoV, room);
					else
						pushCor(posX-1, posY, twoV, room);
				}else
					assignUp(room);
			}
			break;
		}
	case TWODR:
		{
			//check right for availability
			if((posY+1) > LIMIT-1)
			{
				//can't push right, assign a new piece
				assignUp(room);
				break;
			}else
			{
				//create temp variables to store checks
				bool up, left, right;

				//determine whether or not to check for up, left, right due to limits
				if(posX-2 < 0)
					up = true;
				else
					up = !checkUp2(posX-2, posY);

				if(posY-1 < 0)
					left = true;
				else
					left = !checkLeft2(posX-1, posY-1);

				if(posY+1 > LIMIT-1)
					right = false;
				else
					right = checkRight(posX-1, posY+1);

				//check for existing areas for compatibility
				if(up && left && right)
				{
					if(room)
						pushRoom(posX-1, posY, roomtwoDR, room);
					else
						pushCor(posX-1, posY, twoDR, room);
				}else
					assignUp(room);
			}
			break;
		}
	case TWODL:
		{
			//Check left for availability
			if((posY-1) < 0)
			{
				//can't assign left, assign a new piece
				assignUp(room);
				break;
			}else
			{
				//create temp variables to store checks
				bool up, left, right;

				//determine whether or not to check for up, left, right due to limits
				if(posX-2 < 0)
					up = true;
				else
					up = !checkUp2(posX-2, posY);

				if(posY-1 < 0)
					left = false;
				else
					left = checkLeft(posX-1, posY-1);

				if(posY+1 > LIMIT-1)
					right = true;
				else
					right = !checkRight2(posX-1, posY+1);

				//check existing areas for compatibility
				if(up && left && right)
				{
					//push twoDL corridor to the queue
					if(room)
						pushRoom(posX-1, posY, roomtwoDL, room);
					else
						pushCor(posX-1, posY, twoDL, room);
				}else
					assignUp(room);
			}
			break;
		}
	case THREED:
		{
			//check left and right for edges
			if((posY - 1) < 0)
			{
				//can't assign left, assign a new piece
				assignUp(room);
				break;
			}
			else if(posY +1 > LIMIT)
			{
				//can't assign right, assign a new piece
				assignUp(room);
				break;
			}
			else
			{
				//create temp variables to store checks
				bool up, left, right;

				//determine whether or not to check for up, left, right due to limits
				if(posX-2 < 0)
					up = true;
				else
					up = !checkUp2(posX-2, posY);

				if(posY-1 < 0)
					left = false;
				else
					left = checkLeft(posX-1, posY-1);

				if(posY+1 > LIMIT-1)
					right = false;
				else
					right = checkRight(posX-1, posY+1);

				//check for existing areas for compatibility
				if( up && left && right)
				{
					//push threeD corridor onto the queue
					if(room)
						pushRoom(posX-1, posY, roomthreeD, room);
					else
						pushCor(posX-1, posY, threeD, room);
				}else
					assignUp(room);
			}
			break;
		}
	case THREEL:
		{
			//check left and top
			if((posY-1) < 0)
			{
				//can't assign left, assign a new piece
				assignUp(room);
				break;
			}
			if((posX-2) < 0)
			{
				assignUp(room);
				break;
			}
			else
			{
				//create temp variables to store checks
				bool up, left, right;

				//determine whether or not to check for up, left, right due to limits
				if(posX-2 < 0)
					up = false;
				else
					up = checkUp(posX-2, posY);

				if(posY-1 < 0)
					left = false;
				else
					left = checkLeft(posX-1, posY-1);

				if(posY+1 > LIMIT-1)
					right = true;
				else
					right = !checkRight2(posX-1, posY+1);

				//check existing areas
				if(up && left && right)
				{
					if(room)
						pushRoom(posX-1, posY, roomthreeL, room);
					else
						pushCor(posX-1, posY, threeL, room);
					break;
				}else
					assignUp(room);
			}

			break;
		}
	case THREER:
		{
			//check top and right
			if((posX-2) < 0)
			{
				assignUp(room);
				break;
			}else if(posY + 1 > LIMIT-1)
			{
				assignUp(room);
				break;
			}else
			{

				//create temp variables to store checks
				bool up, left, right;

				//determine whether or not to check for up, left, right due to limits
				if(posX-2 < 0)
					up = false;
				else
					up = checkUp(posX-2, posY);

				if(posY-1 < 0)
					left = true;
				else
					left = !checkLeft2(posX-1, posY-1);

				if(posY+1 > LIMIT-1)
					right = false;
				else
					right = checkRight(posX-1, posY+1);

				//check top and right for compatibility
				if(up && left && right)
				{
					//push threeR corridor onto the queue
					if(room)
						pushRoom(posX-1, posY, roomthreeR, room);
					else
						pushCor(posX-1, posY, threeR, room);
					break;
				}else
					assignUp(room);
			}
			break;
		}
	case FOUR:
		{
			//check up, left and right
			if(posY -1 < 0)
			{
				assignUp(room);
				break;
			}else if(posY+1 > LIMIT-1)
			{
				assignUp(room);
				break;
			}else if(posX-2 < 0)
			{
				assignUp(room);
				break;
			}else
			{
				//create temp variables to store checks
				bool up, left, right;

				//determine whether or not to check for up, left, right due to limits
				if(posX-2 < 0)
					up = false;
				else
					up = checkUp(posX-2, posY);

				if(posY-1 < 0)
					left = false;
				else
					left = checkLeft(posX-1, posY-1);

				if(posY+1 > LIMIT-1)
					right = false;
				else
					right = checkRight(posX-1, posY+1);

				if(up && left && right)
				{
					if(room)
						pushRoom(posX-1, posY, roomfour, room);
					else
						pushCor(posX-1, posY, four, room);
				}else
					assignUp(room);
			}
			break;
		}
	}//end switch
}
Ejemplo n.º 15
0
void FloorGenerator::assignLeft(bool room)
{
	int temp = rand() % 8;
	int posX = start.front().getX();
	int posY = start.front().getY();

	const int ONER = 0, TWOH = 1, TWOUR= 2, TWODR = 3, THREEU = 4, THREED = 5, THREER = 6, FOUR = 7;

	switch(temp)
	{
	case ONER:
		{
			bool up, down, left;

			if(posX-1 < 0)
				up = true;
			else
				up = !checkUp2(posX-1, posY-1);
			if(posX+1 > LIMIT-1)
				down = true;
			else
				down = !checkDown2(posX+1, posY-1);
			if(posY-2 < 0)
				left = true;
			else
				left = !checkLeft2(posX, posY-2);

			if(up && down && left)
			{
				if(room)
					pushRoom(posX, posY-1, roomoneR, room);
				else
					pushCor(posX, posY-1, oneR, room);
			}else
				assignLeft(room);
			break;
		}
	case TWOH:
		{
			if(posY-2 < 0)
			{
				assignLeft(room);
				break;
			}else
			{
				bool up, down, left;

				if(posX-1 < 0)
					up = true;
				else
					up = !checkUp2(posX-1, posY-1);
				if(posX+1 > LIMIT-1)
					down = true;
				else
					down = !checkDown2(posX+1, posY-1);
				if(posY-2 < 0)
					left = false;
				else
					left = checkLeft(posX, posY-2);

				if(up && down && left)
				{
					if(room)
						pushRoom(posX, posY-1, roomtwoH, room);
					else
						pushCor(posX, posY-1, twoH, room);
				}else
					assignLeft(room);
			}
			break;
		}
	case TWOUR:
		{
			if(posX-1 < 0)
			{
				assignLeft(room);
				break;
			}else
			{
				bool up, down, left;

				if(posX-1 < 0)
					up = false;
				else
					up = checkUp(posX-1, posY-1);
				if(posX+1 > LIMIT-1)
					down = true;
				else
					down = !checkDown2(posX+1, posY-1);
				if(posY-2 < 0)
					left = true;
				else
					left = !checkLeft2(posX, posY-2);

				if(up && down && left)
				{
					if(room)
						pushRoom(posX, posY-1, roomtwoUR, room);
					else
						pushCor(posX, posY-1, twoUR, room);
				}else
					assignLeft(room);
			}
			break;
		}
	case TWODR:
		{
			if(posX+1 > LIMIT-1)
			{
				assignLeft(room);
				break;
			}else
			{
				bool up, down, left;

				if(posX-1 < 0)
					up = true;
				else
					up = !checkUp2(posX-1, posY-1);
				if(posX+1 > LIMIT-1)
					down = false;
				else
					down = checkDown(posX+1, posY-1);
				if(posY-2 < 0)
					left = true;
				else
					left = !checkLeft2(posX, posY-2);

				if(up && down && left)
				{
					if(room)
						pushRoom(posX, posY-1, roomtwoDR, room);
					else
						pushCor(posX, posY-1, twoDR, room);
				}else
					assignLeft(room);
			}
			break;
		}
	case THREEU:
		{
			if(posX-1 < 0)
			{
				assignLeft(room);
				break;
			}else if(posY-2 < 0)
			{
				assignLeft(room);
				break;
			}else
			{
				bool up, down, left;

				if(posX-1 < 0)
					up = false;
				else
					up = checkUp(posX-1, posY-1);
				if(posX+1 > LIMIT-1)
					down = true;
				else
					down = !checkDown2(posX+1, posY-1);
				if(posY-2 < 0)
					left = false;
				else
					left = checkLeft(posX, posY-2);

				if(up && down && left)
				{
					if(room)
						pushRoom(posX, posY-1, roomthreeU, room);
					else
						pushCor(posX, posY-1, threeU, room);
				}else
					assignLeft(room);
			}
			break;
		}
	case THREED:
		{
			if(posX+1 > LIMIT-1)
			{
				assignLeft(room);
				break;
			}else if(posY-2 < 0)
			{
				assignLeft(room);
				break;
			}else
			{
				bool up, down, left;

				if(posX-1 < 0)
					up = true;
				else
					up = !checkUp2(posX-1, posY-1);
				if(posX+1 > LIMIT-1)
					down = false;
				else
					down = checkDown(posX+1, posY-1);
				if(posY-2 < 0)
					left = false;
				else
					left = checkLeft(posX, posY-2);

				if(up && down && left)
				{
					if(room)
						pushRoom(posX, posY-1, roomthreeD, room);
					else
						pushCor(posX, posY-1, threeD, room);
				}else
					assignLeft(room);
			}

			break;
		}
	case THREER:
		{
			if(posX+1 > LIMIT-1)
			{
				assignLeft(room);
				break;
			}else if(posX-1 < 0)
			{
				assignLeft(room);
				break;
			}else
			{
				bool up, down, left;

				if(posX-1 < 0)
					up = false;
				else
					up = checkUp(posX-1, posY-1);
				if(posX+1 > LIMIT-1)
					down = false;
				else
					down = checkDown(posX+1, posY-1);
				if(posY-2 < 0)
					left = true;
				else
					left = !checkLeft2(posX, posY-2);

				if(up && down && left)
				{
					if(room)
						pushRoom(posX, posY-1, roomthreeR, room);
					else
						pushCor(posX, posY-1, threeR, room);
				}else
					assignLeft(room);
			}
			break;
		}
	case FOUR:
		{
			if(posX+1 > LIMIT-1)
			{
				assignLeft(room);
				break;
			}else if(posX-1 < 0)
			{
				assignLeft(room);
				break;
			}else if(posY-2 < 0)
			{
				assignLeft(room);
				break;
			}else
			{
				bool up, down, left;

				if(posX-1 < 0)
					up = false;
				else
					up = checkUp(posX-1, posY-1);
				if(posX+1 > LIMIT-1)
					down = false;
				else
					down = checkDown(posX+1, posY-1);
				if(posY-2 < 0)
					left = false;
				else
					left = checkLeft(posX, posY-2);

				if(up && down && left)
				{
					if(room)
						pushRoom(posX, posY-1, roomfour, room);
					else
						pushCor(posX, posY-1, four, room);
				}else
					assignLeft(room);
			}
			break;
		}
	}
}