Ejemplo n.º 1
0
void setPosition(sworld world, int x, int y, int type, int breedingPeriod,
		int starvationPeriod, int worldsize) {
	world[calcPos(x,y,worldsize)].x = x;
	world[calcPos(x,y,worldsize)].y = y;
	world[calcPos(x,y,worldsize)].type = type;
	world[calcPos(x,y,worldsize)].breeding_period = breedingPeriod;
	world[calcPos(x,y,worldsize)].starvation_period = starvationPeriod;
}
Ejemplo n.º 2
0
void cleanPos(sworld world, int x, int y, int worldsize) {
	if (world[calcPos(x,y,worldsize)].type != SONT)
		world[calcPos(x,y,worldsize)].type = EPTY;
	else
		world[calcPos(x,y,worldsize)].type = TREE;

	world[calcPos(x,y,worldsize)].breeding_period = 0;
	world[calcPos(x,y,worldsize)].starvation_period = 0;
}
Ejemplo n.º 3
0
void turnToDirection(int turnDirection) {
	adjustAngle();
	int currentDir;
	currentDir = currentDirection();
	double target = (currentDir + turnDirection) * M_PI / 2;

	while(fabs(currentHeading() - target) > turnThreshold) {
		if(fabs(currentHeading() - target) < slowThreshold) {
			if(currentHeading() > target) {
				set_motors(-5,5);
			}
			if(currentHeading() < target) {
				set_motors(5,-5);
			}
		} else {
			if(currentHeading() > target) {
				set_motors(-15,15);
			}
			if(currentHeading() < target) {
				set_motors(15,-15);
			}
		}
		calcPos();
	}
	set_motors(0,0);
	adjustAngle();
	usleep(10000);
}
Ejemplo n.º 4
0
int isAble(sworld world, int x_pos, int y_pos, int type, int worldX, int worldY) {
	/*0 não se pode mexer
	 1 pode-se mexer
	 */
	/*XXX ver se está dentro do quadrado*/
	int positionType;

	if (x_pos < 0 || y_pos < 0 || x_pos >= worldX || y_pos >= worldY) {
		return 0; /*fora do quadrado*/
	}
	positionType = world[calcPos(x_pos, y_pos, worldY)].type;

	/* check lobos */
	if (type == WOLF || type == WES) {
		if (positionType == SQRL)
			return 2;
		if (positionType == EPTY) { /*empty or squirrel or wolf*/
			return 1;
		}
	} else {/*check esquilos SQRT e SONT*/
		if (positionType != ICE && positionType != WOLF && positionType != WES) { /*if not ice or wolf */
			return 1;
		}
	}
	return 0;
}
Ejemplo n.º 5
0
void enemy::draw()
{
calcPos();

glPushMatrix();
glError();

glTranslatef( pos.x, pos.y, 0 );
glError();

glBegin( GL_LINES );

#define LEN 1.0f
#define line( _pt1,_pt2 ) glVertex3fv( _pt1 );glVertex3fv( _pt2 )
GLfloat v0[] = { -LEN, -LEN, 0.0f };
GLfloat v1[] = { -LEN,  LEN, 0.0f };
GLfloat v2[] = {  LEN,  LEN, 0.0f };
GLfloat v3[] = {  LEN, -LEN, 0.0f };

line( v0, v1 );
line( v1, v2 );
line( v2, v3 );
line( v3, v0 );

glEnd();
glError();

glPopMatrix();
glError();
}
Ejemplo n.º 6
0
void turn90()
{
	while( fabs(currentHeading() - (M_PI/2.0)) > turnThreshold)
	{
		if(fabs(currentHeading() - (M_PI/2.0)) < slowThreshold)
		{
			if(currentHeading() > (M_PI/2.0))
			{
				set_motors(-1,1);
			}

			if(currentHeading() < (M_PI/2.0))
			{
				set_motors(1,-1);
			}
		}

		else
		{
			if(currentHeading() > (M_PI/2.0))
			{
				set_motors(-15,15);
			}

			if(currentHeading() < (M_PI/2.0))
			{
				set_motors(15,-15);
			}
		}
		
		calcPos();
	}
	set_motors(0,0);
	printf("Target : %f\n", M_PI/2.0);
}
Ejemplo n.º 7
0
void moveRobot(){
	updateRobot();
	updateRobotNew();
	calcPos();
	calcPosNew();
	PIDcontrolNew();
	if(Robot.newCom){
		Stop(&motorL, &motorR);
		Robot.errSumL = 0;
		Robot.errSumR = 0;
		counter++;
	}
	else{
		if((Robot.dirL == STOP && Robot.dirR == STOP)){	//|| (time > Robot.time)
			Stop(&motorR,&motorL);
		}
		if(Robot.dirR == FORWARD){
			MoveRF(&motorR);
		}
		else if(Robot.dirR == BACKWARD){
			MoveRB(&motorR);
		}
		if(Robot.dirL == FORWARD){
			MoveLF(&motorL);
		}
		else if(Robot.dirL == BACKWARD){
			MoveLB(&motorL);
		}
	}
	if(counter > 2){
		Robot.newCom = false;
		counter = 0;
	}
}
Ejemplo n.º 8
0
void enemy::calcBbox()
{
calcPos();
box.nec.x = pos.x + WIDTH;
box.nec.y = pos.y + HEIGHT;
box.swc.x = pos.x - WIDTH;
box.swc.y = pos.y - HEIGHT;
}
Ejemplo n.º 9
0
LRESULT ListCtrl::onVScroll( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
{
	if (calcPos(SB_VERT))
	{
		calcCellRect();
	}
	invalidWid();
	return 1;
}
Ejemplo n.º 10
0
LRESULT ListCtrl::onHScroll( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
{
	if (calcPos(SB_HORZ))
	{
		calcCellRect();
		m_pHeadCtrl->calcCellRect();
	}
	invalidWid();
	return 1;
}
Ejemplo n.º 11
0
void ship::draw()
{
calcPos();
calcTail();
const position * last_pos = &pos;

for( std::list<position>::iterator it = tail.begin(); it != tail.end(); it++)
//for( int i = -1; i < (int)/*hack*/tail.size(); ++i )
	{
	glPushMatrix();
	glError();

	glTranslatef( last_pos->x, last_pos->y, 0 );
	glError();

	glBegin( GL_LINES );

	#define line( _pt1,_pt2 ) glVertex3fv( _pt1 );glVertex3fv( _pt2 )

	//triangle
	GLfloat v0[] = {      0,     HEIGHT, 0.0f };
	GLfloat v1[] = {   -WIDTH,       0, 0.0f };
	GLfloat v2[] = {    WIDTH,       0, 0.0f };

	//barrel
	GLfloat v3[] = {      0, 2 * HEIGHT, 0.0f };

	//suppressor
	GLfloat v4[] = { -WIDTH/3, 2 * HEIGHT - HEIGHT/3, 0.0f };
	GLfloat v5[] = {  WIDTH/3, 2 * HEIGHT - HEIGHT/3, 0.0f };

	line( v0, v1 );
	line( v1, v2 );
	line( v2, v0 );

	line( v0, v3 );

	line( v3, v4 );
	line( v4, v5 );
	line( v5, v3 );

	glEnd();
	glError();

	glPopMatrix();
	glError();

	last_pos = &*it;
	}
}
Ejemplo n.º 12
0
void adjustStart()
{
	turnToDirection(ABOUT_TURN);
	int backDistFromWall = get_us_dist();
	int targetDistSide = 27;
	while(fabs(backDistFromWall - 27) > 1)
	{
		printf("%d\n",backDistFromWall);
		if(backDistFromWall > 27)
		{
			set_motors(5,5);
		}
		else
		{
			set_motors(-5,-5);
		}
		backDistFromWall = get_us_dist();
		calcPos();
	}
	turnToDirection(LEFT_TURN);
	int sideDistFromWall = get_us_dist();
	while(fabs(sideDistFromWall - targetDistSide) > 1)
	{
		printf("%d\n",sideDistFromWall);
		if(sideDistFromWall > targetDistSide)
		{
			set_motors(5,5);
		}
		else
		{
			set_motors(-5,-5);
		}
		sideDistFromWall = get_us_dist();
		calcPos();
	}
	turnToDirection(LEFT_TURN);
}
Ejemplo n.º 13
0
void dibPunto::drawCode()
{
    double incx, incy, newx, newy;
    DPI::VAlign va;
    DPI::HAlign ha;
    calcPos(&va, &ha, ptcode->getSeparation(),
                 &incx, &incy, ptcode->getPosition());

    currDoc->setLayer(ptcode->getLayer());
    QString sty = ptcode->getStyleStr();
    for (int i = 0; i < dataList.size(); ++i) {
        pointData *pd = dataList.at(i);
        if (!pd->x.isEmpty() && !pd->y.isEmpty() && !pd->code.isEmpty()){
            newx = pd->x.toDouble() + incx;
            newy = pd->y.toDouble() + incy;
            QPointF pt(newx,newy);
            currDoc->addText(pd->code, sty, &pt, ptcode->getHeightStr().toDouble(), 0.0, ha, va);
        }
    }
}
Ejemplo n.º 14
0
void SceneGraphDeviceContext::DrawMusicText(const std::wstring &text, int x, int y, bool)
{
    Q_ASSERT(m_fontStack.top());

    QFont font(QString::fromStdString(m_fontStack.top()->GetFaceName()));

    // Note: Verovio calls it point size but it is actually pixel size. Qt can only handle pixel size in int, thus it
    // would be better to use point size.
    int pixelSize = static_cast<int>(translate(m_fontStack.top()->GetPointSize()));
    font.setPixelSize(pixelSize);

    // Memory management is handled by m_quickItem (set in AddQuickItem)
    auto musicTextQuickItem = new TextQuickItem();

    musicTextQuickItem->appendText(QString::fromStdWString(text), font);

    musicTextQuickItem->setX(static_cast<double>(translateX(x)));
    musicTextQuickItem->setY(static_cast<double>(translateY(y)));
    musicTextQuickItem->calcPos();

    AddQuickItem(musicTextQuickItem);
}
Ejemplo n.º 15
0
void    Canvas::DrawSnakeHead(QPainter &painter)
{
  QColor	yellow(qRgb(254, 231, 0));
  QColor	black(qRgb(0, 0, 0));
  uint		u = _unit;

  painter.setBrush(yellow);
  painter.drawEllipse((_head.x() * u) - u, (_head.y() * u) - u, u * 3, u * 3);
  painter.setBrush(QBrush(black));
  if (_dir == RIGHT || _dir == LEFT)
    {
      uint posX = calcPos(_head.x(), u, _dir == LEFT);
      painter.drawEllipse(posX, calcPos(_head.y(), u, 1), u / 2, u / 2);
      painter.drawEllipse(posX, calcPos(_head.y(), u, 0), u / 2, u / 2);
    }
  else if (_dir == BOTTOM || _dir == TOP)
    {
      uint posY = calcPos(_head.y(), u, _dir == TOP);
      painter.drawEllipse(calcPos(_head.x(), u, 1), posY, u / 2, u / 2);
      painter.drawEllipse(calcPos(_head.x(), u, 0), posY, u / 2, u / 2);
    }
}
Ejemplo n.º 16
0
const position & enemy::getPos()
{
calcPos();
return pos;
}
Ejemplo n.º 17
0
/**
 * The function seems to have problems, if the position is near 0° W/E.
 */
QString WGSPoint::printPos( int coord, bool isLat, int format )
{
  QString pos, posDeg, posMin, posSec;
  int degree, min, sec;
  double decDegree, decMin;
  QChar degreeChar = Qt::Key_degree;

  if ( format == WGSPoint::DMS )
    {
      // default is always degrees, minutes, seconds
      calcPos (coord, degree, min, sec);

      if (isLat)
        {
          // posDeg.sprintf("%02d\260 ", (degree < 0)  ? -degree : degree);
          posDeg = QString("%1%2 ")
                      .arg( ((degree < 0)  ? -degree : degree), 2, 10, QChar('0') )
                      .arg( degreeChar );
        }
      else
        {
          // posDeg.sprintf("%03d\260 ", (degree < 0)  ? -degree : degree);
          posDeg = QString("%1%2 ")
                      .arg( ((degree < 0)  ? -degree : degree), 3, 10, QChar('0') )
                      .arg( degreeChar );
        }

      min = abs(min);
      // posMin.sprintf("%02d'", min);
      posMin = QString("%1'").arg( min, 2, 10, QChar('0') );

      sec = abs(sec);
      // posSec.sprintf(" %02d\"", sec);
      posSec = QString(" %1\"").arg( sec, 2, 10, QChar('0') );
    }
  else if ( format == WGSPoint::DDM )
    {
      // degrees and decimal minutes
      calcPos (coord, degree, decMin);

      if (isLat)
        {
          // posDeg.sprintf("%02d\260 ", (degree < 0)  ? -degree : degree);
          posDeg = QString("%1%2 ")
                      .arg( ((degree < 0)  ? -degree : degree), 2, 10, QChar('0') )
                      .arg( degreeChar );
        }
      else
        {
          // posDeg.sprintf("%03d\260 ", (degree < 0)  ? -degree : degree);
          posDeg = QString("%1%2 ")
                      .arg( ((degree < 0)  ? -degree : degree), 3, 10, QChar('0') )
                      .arg( degreeChar );
        }

      decMin = fabs(decMin);

      // posMin.sprintf("%.3f'", decMin);
      posMin = QString("%1'").arg( decMin, 0, 'f', 3 );

      // Unfortunately sprintf does not support leading zero in float
      // formating. So we must do it alone.
      if ( decMin < 10.0 )
        {
          posMin.insert(0, "0");
        }
    }
  else if ( format == WGSPoint::DDD )
    {
      // decimal degrees
      calcPos (coord, decDegree);

      // posDeg.sprintf("%.5f\260", (decDegree < 0)  ? -decDegree : decDegree);
      posDeg = QString("%1%2")
                  .arg( ((decDegree < 0)  ? -decDegree : decDegree), 0, 'f', 5 )
                  .arg( degreeChar );


      // Unfortunately sprintf does not support leading zero in float
      // formating. So we must do it alone.
      if (isLat)
        {
          if ( decDegree < 10.0 )
            {
              posDeg.insert(0, "0");
            }
        }
      else
        {
          if ( decDegree < 10.0 )
            {
              posDeg.insert(0, "00");
            }
          else if ( decDegree < 100.0 )
            {
              posDeg.insert(0, "0");
            }
        }
    }

  pos = posDeg + posMin + posSec;

  if (isLat)
    {
      if (coord < 0)
        {
          pos += " S";
        }
      else
        {
          pos += " N";
        }
    }
  else
    {
      if (coord < 0)
        {
          pos += " W";
        }
      else
        {
          pos += " E";
        }
    }

  // qDebug( "Pos=%s", pos.toLatin1().data() );

  return pos;
}
Ejemplo n.º 18
0
void setPositionBreeding(sworld world, int x, int y, int breedingPeriod, int worldsize) {
	world[calcPos(x,y,worldsize)].breeding_period = breedingPeriod;
}
Ejemplo n.º 19
0
void setPositionStarvation(sworld world, int x, int y, int starvationPeriod, int worldsize) {
	world[calcPos(x,y,worldsize)].starvation_period = starvationPeriod;
}
Ejemplo n.º 20
0
	int calcMovePos(sworld world, int x, int y, int type, int worldX, int worldY) { /*calc the Next pos*/
		/* trees and ice don't move
		 • Number the possible choices starting from 0, clockwise starting from the 12:00
		 position (i.e. up, right, down, left). Note that only cells that are unoccupied (for
		 moves) or occupied by squirrels (for wolves to eat), should be numbered. Call the
		 number of possible cells p.
		 • Compute the grid cell number of the cell being evaluated. If the cell is at position
		 (i,j) in the world grid with (0,0) the grid origin, and the grid is of size MxN, the grid
		 cell number is C = i x N + j .
		 • The cell to select is then determined by C mod p. For example, if there are 3 possible
		 cells to choose from, say up, down and left, then if C mod p is 0 the selected cell is
		 up from the current cell, if it is 1 then select down, and if it is 2 then select left.
		 */

		/* numerar posições*/
		int i, nPos;
		int numbPossible = 0;
		int theChoosenOne;
		int vec[POSSIBLE_POS] = { -1, -1, -1, -1 };
		int vecWolf[POSSIBLE_POS] = { -1, -1, -1, -1 };
		int ret = 0;
		int numbPossibleWolf = 0;
		/*Pos Left 0*/
		/*x y-1*/

		if (isAble(world, x, y - 1, type,worldX ,worldY)) {
			numbPossible++;
			vec[0] = calcPos(x,y-1,worldY);
		}
		/*Pos Up 0*/
		/*(x-1)*worldsize y*/
		if (isAble(world, (x + 1), y, type, worldX ,worldY)) {
			numbPossible++;
			vec[1] = calcPos((x+1) ,y,worldY);
		}
		/*Pos Rigth 0*/
		/*x y+1*/

		if (isAble(world, x, y + 1, type, worldX ,worldY)) {
			numbPossible++;
			vec[2] = calcPos(x,y+1,worldY);
		}
		/*Pos Down 0*/
		/*(x+1)*worldsize y*/
		if (isAble(world, (x - 1), y, type, worldX ,worldY)) {

			numbPossible++;

			vec[3] = calcPos((x-1),y,worldY);
		}

		if (type == WOLF || type == WES) {
			if (isAble(world, x, y - 1, type, worldX ,worldY)) {
				if (isAble(world, x, y - 1, type,worldX ,worldY) == 2) {
					numbPossibleWolf++;
				}
				numbPossible++;
				vec[0] = calcPos(x,y-1,worldY);
				vecWolf[0] = calcPos(x,y-1,worldY);
			}
			/*Pos Up 0*/
			/*(x-1)*worldsize y*/
			if (isAble(world, (x + 1), y, type, worldX ,worldY)) {
				if (isAble(world, (x + 1), y, type, worldX ,worldY) == 2) {
					numbPossibleWolf++;

				}
				numbPossible++;
				vec[1] = calcPos((x+1) ,y,worldY);
				vecWolf[1] = calcPos((x+1) ,y,worldY);
			}
			/*Pos Rigth 0*/
			/*x y+1*/

			if (isAble(world, x, y + 1, type, worldX ,worldY)) {
				if (isAble(world, x, y + 1, type, worldX ,worldY) == 2) {
					numbPossibleWolf++;
				}
				numbPossible++;
				vec[2] = calcPos(x,y+1,worldY);
				vecWolf[2] = calcPos(x,y+1,worldY);
			}
			/*Pos Down 0*/
			/*(x+1)*worldsize y*/
			if (isAble(world, (x - 1), y, type, worldX ,worldY)) {
				if (isAble(world, (x - 1), y, type, worldX ,worldY) == 2) {
					numbPossibleWolf++;

				}
				numbPossible++;

				vec[3] = calcPos((x-1),y,worldY);
				vecWolf[3] = calcPos((x-1),y,worldY);
			}
		}

		/* Matrix do rafael
		 UP
		 if(isAble(world, x-1,y, type)){
		 numbPossible++;
		 vec[0]=calcPos(x-1,y,worldsize);
		 }
		 Rigth

		 if(isAble(world, x, y+1, type)){
		 numbPossible++;
		 vec[1]=calcPos(x ,y+1,worldsize);
		 }
		 Down

		 if(isAble(world, x+1,y, type)){
		 numbPossible++;
		 vec[2]=calcPos(x+1,y,worldsize);
		 }
		 Left

		 if(isAble(world, x,y-1, type)){
		 numbPossible++;
		 vec[3]=calcPos(x,y-1,worldsize);
		 }

		 */

		/*calculating C MOD numbPossible pag 2 enum*/
		if (numbPossible == 0)
			return -1;
		nPos = calcPos(x,y,worldY);
		theChoosenOne = nPos % numbPossible;
		/*printf("\n\ntheChoosenOne: %d calcPos:%d  numbPossible: %d calcPos(x,y,worldsize)MODnumbPossible: %d \n\n",theChoosenOne,calcPos(x,y,worldsize),numbPossible, calcPos(x,y,worldsize)%numbPossible);
		 printf("[%d , %d , %d , %d]\n\n",vec[0],vec[1],vec[2],vec[3]);*/
		if (type == WOLF || type == WES)
			if (numbPossibleWolf > 0) {
				for (i = 0; i < POSSIBLE_POS; i++) {
					if (vecWolf[i] != -1) {
						if (theChoosenOne == 0) {
							ret = vecWolf[i];
							return ret;
						} else {
							theChoosenOne--;
						}
					}
				}
			} else {
				for (i = 0; i < POSSIBLE_POS; i++) {
					if (vec[i] != -1) {
						if (theChoosenOne == 0) {
							ret = vec[i];
							return ret;
						} else {
							theChoosenOne--;
						}
					}
				}
			}
		else {
			for (i = 0; i < POSSIBLE_POS; i++) {
				if (vec[i] != -1) {
					if (theChoosenOne == 0) {
						ret = vec[i];
						return ret;
					} else {
						theChoosenOne--;
					}
				}
			}
		}

		return ret;
	}
Ejemplo n.º 21
0
void setPositionType(sworld world, int x, int y, int type, int worldsize) {
	world[calcPos(x,y,worldsize)].type = type;
}
Ejemplo n.º 22
0
//----------------------------------------------------------------------------
// Callback method called when system is idle.
// This is called at the start of every new "frame" (qualitatively)
void Window::idleCallback()
{
    //Set up a static time delta for update calls
    Globals::updateData.dt = 1.0/60.0;// 60 fps
    
    if (time1 >= 1.0){
        time1 = 0.0;
    }
    
    if (time2 >= 1.0){
        time2 = 0.0;
    }
    
    if (time3 >= 1.0){
        time3 = 0.0;
    }
    
    
    camera_pos = Globals::camera_c->move(time1);
    if (flag == true){
        Globals::camera->e = camera_pos;
        Globals::camera->update();
    }
    
    Vector3 pos = Globals::explosive_c->move(time1);
    Matrix4 newpos_matrix;
    newpos_matrix.makeTranslate(pos[0], pos[1], pos[2]);
    trans_exp->setMatrix(newpos_matrix);
    
    
    if (!explodeMars) {
        calcPos(Globals::mars_c->move(time2), trans_m, Globals::mars);
    }
    if (!explodeSaturn) {
        calcPos(Globals::saturn_c->move(time1), trans_sa, Globals::saturn);
    }
    if (!explodeSun) {
        calcPos(Globals::sun_c->move(time3), trans_s, Globals::sun);
    }
    
    if (collision_switch) {
        calcPos(Globals::mars_ac->move(time2), trans_mr, Globals::asteriod_mars);
        calcPos(Globals::saturn_ac->move(time1), trans_sar, Globals::asteriod_saturn);
        calcPos(Globals::sun_ac->move(time3), trans_sr, Globals::asteriod_sun);
        
        
        if (Globals::mars->getBbox().detectCollision(Globals::mars->getBbox(), Globals::asteriod_mars->getBbox())){
            explodeMars = true;
            trans_m->addChild(Globals::marsSystem);
            trans_m->removeChild(Globals::mars);
            trans_mr->removeChild(Globals::asteriod_mars);
        }
        
        if (Globals::sun->getBbox().detectCollision(Globals::sun->getBbox(), Globals::asteriod_sun->getBbox())){
            explodeSun = true;
            trans_s->addChild(Globals::sunSystem);
            trans_s->removeChild(Globals::sun);
            trans_sr->removeChild(Globals::asteriod_sun);
        }
        
        if (Globals::saturn->getBbox().detectCollision(Globals::saturn->getBbox(), Globals::asteriod_saturn->getBbox())){
            explodeSaturn = true;
            trans_sa->addChild(Globals::saturnSystem);
            trans_sa->removeChild(Globals::saturn);
            trans_sar->removeChild(Globals::asteriod_saturn);
            
        }
        
    }
    
    
    
    
    
    
    
    time1 += 0.005;
    time2 += 0.004;
    time3 += 0.003;

    
    Globals::camera->update();
    
    //Call the display routine to draw the cube
    displayCallback();
}
Ejemplo n.º 23
0
int getPositionType(sworld world, int x, int y, int worldsize) {
	return world[calcPos(x,y,worldsize)].type;
}
Ejemplo n.º 24
0
void Straight()
{
	adjustAngle();
	// Going Up

	int i;
	int motorSpeed;

	for (i = 0; i < 11; i++) {
		set_motors(3 * i, 3 * i);
		usleep(100000);
	}

	if(currentDirection() == 0 || currentDirection() == 4) {
		idealY += 60;
		printf("UP TargetY: %f\n",idealY);

		while(fabs(currentY()-idealY) > 1) {
			if(fabs(currentY()-idealY) < 10) {
				if(currentY() < idealY) {
					correctToStraight(2 * fabs(currentY()-idealY));
					// set_motors(motorSpeed, motorSpeed);
				} else {
					correctToStraight(-2 * fabs(currentY()-idealY));
					// set_motors(-5 -2 * fabs(currentY()-idealY),-5 -2 * fabs(currentY()-idealY));
				}
			} else if(currentY() < idealY) {
				set_motors(40,40);
			} else if(currentY() > idealY) {
				set_motors(-40,-40);
			}
			calcPos();
			//printf("X:%f Y:%f\n", currentX(),currentY());
		}
		set_motors(0,0);
		bCoord.y += 1;
	}

	// Going Down
	if(currentDirection() == 2) {
		idealY -= 60;
		printf("DOWN TargetY: %f\n",idealY);

		while(fabs(currentY()-idealY) > 1) {
			if(fabs(currentY()-idealY) < 10) {
				if(currentY() > idealY) {
					correctToStraight(2 * fabs(currentY()-idealY));
					// set_motors(5 + 2 * fabs(currentY()-idealY), 5 + 2 * fabs(currentY()-idealY));
				} else {
					correctToStraight(-2 * fabs(currentY()-idealY));
					// set_motors(-5 -2 * fabs(currentY()-idealY),-5 -2 * fabs(currentY()-idealY));
				}
			} else if(currentY() < idealY) {
				set_motors(-40,-40);
			} else if(currentY() > idealY) {
				set_motors(40,40);
			}
			calcPos();
			//printf("X:%f Y:%f\n", currentX(),currentY());
		}
		set_motors(0,0);
		bCoord.y -= 1;
	}

	// Going Right
	if(currentDirection() == 1) {
		idealX += 60;
		printf("RIGHT TargetX: %f\n",idealX);

		while(fabs(currentX()-idealX) > 1) {
			if(fabs(currentX()-idealX) < 10) {
				if(currentX() < idealX) {
					correctToStraight(2 * fabs(currentX()-idealX));
					// set_motors(5 + 2 * fabs(currentX()-idealX),5 + 2 * fabs(currentX()-idealX));
				} else {
					correctToStraight(-2 * fabs(currentX()-idealX));
					// set_motors(-5 -2 * fabs(currentX()-idealX),-5 -2 * fabs(currentX()-idealX));
				}
			} else if(currentX() < idealX) {
				set_motors(40,40);
			} else if(currentX() > idealX) {
				set_motors(-40,-40);
			}

			calcPos();
			//printf("X:%f Y:%f\n", currentX(),currentY());
		}
		set_motors(0,0);
		bCoord.x += 1;
	}

	// Going Left
	if(currentDirection() == 3) {
		idealX -= 60;
		printf("LEFT TargetX: %f\n",idealX);

		while(fabs(currentX()-idealX) > 1) {
			if(fabs(currentX()-idealX) < 10) {
				if(currentX() > idealX) {
					correctToStraight(2 * fabs(currentX()-idealX));
					// set_motors(5 + 2 * fabs(currentX()-idealX),5 + 2 * fabs(currentX()-idealX));
				} else {
					correctToStraight(-2 * fabs(currentX()-idealX));
					// set_motors(-5 -2 * fabs(currentX()-idealX),-5 -2 * fabs(currentX()-idealX));
				}
			} else if(currentX() < idealX) {
				set_motors(-40,-40);
			} else if(currentX() > idealX) {
				set_motors(40,40);
			}
			calcPos();
			//printf("X:%f Y:%f\n", currentX(),currentY());
		}
		set_motors(0,0);
		bCoord.x -= 1;
	}
}
Ejemplo n.º 25
0
int getPositionStarvationPeriod(sworld world, int x, int y, int worldsize) {
	return world[calcPos(x,y,worldsize)].starvation_period;
}
Ejemplo n.º 26
0
int getPositionBreedingPeriod(sworld world, int x, int y, int worldsize) {
	return world[calcPos(x,y,worldsize)].breeding_period;
}
Ejemplo n.º 27
0
sworld getPositionStructure(sworld world, int x, int y, int worldsize) {
	return &world[calcPos(x,y,worldsize)];
}
Ejemplo n.º 28
0
const position & ship::getPos()
{
calcPos();
return pos;
}