Exemple #1
0
main ()
{
  int direction;
  direction = 90;
  while (1)
    {
      if (speed () == 0)
	drive (direction, 100);
      if ((direction == 90 && loc_y () > 575)
	  || (direction == 270 && loc_y () < 425)
	  || (direction == 180 && loc_x () < 150)
	  || (direction == 0 && loc_x () > 850))
	{
	  drive (direction, 0);
	  direction = (direction + 90) % 360;
	}
      else
	{
	  int range;
	  if (range = scan (0, 10)) cannon (0, range);
	  else if (range = scan (30, 10)) cannon (30, range);
	  else if (range = scan (60, 10)) cannon (60, range);
	  else if (range = scan (90, 10)) cannon (90, range);
	  else if (range = scan (120, 10)) cannon (120, range);
	  else if (range = scan (150, 10)) cannon (150, range);
	  else if (range = scan (180, 10)) cannon (180, range);
	  else if (range = scan (210, 10)) cannon (210, range);
	  else if (range = scan (240, 10)) cannon (240, range);
	  else if (range = scan (270, 10)) cannon (270, range);
	  else if (range = scan (300, 10)) cannon (300, range);
	  else if (range = scan (330, 10)) cannon (330, range);
	}
    }
}
Exemple #2
0
/* reach destination x, y; uses atan() trig function */
int
plot_course (int xx, int yy)
{
  int x, y;
  x = xx - loc_x ();
  y = yy - loc_y ();
  return atan2 (y, x) * 180 / M_PI;
}
Exemple #3
0
void
go (int x, int y)
{
  /* find the heading we need to get to the desired corner */
  int angle = plot_course (x, y);

  /* start drive train, full speed */
  drive (angle, 100);

  /* keep traveling until we are within 100 meters */
  /* speed is checked in case we run into wall, other robot */
  /* not terribly great, since we are doing nothing while moving */
  while (distance (loc_x (), loc_y (), x, y) > 100 && speed () > 0)
    cycle ();

  /* cut speed, and creep the rest of the way */
  drive (angle, 20);
  while (distance (loc_x (), loc_y (), x, y) > 10 && speed () > 0)
    cycle ();

  /* stop drive, should coast in the rest of the way */
  drive (angle, 0);
}
void console_widget_t::calc_area(int x, int y)
{
	/* calculate selection area */

	if(mouse_drag_type)
	{
		/* copy rect */
		/* calculate selection start location and selection width and height */

		mouse_sx = i_min(loc_x(mouse_start_x), loc_x(x));
		mouse_wx = i_abs(loc_x(x)-loc_x(mouse_start_x));
		mouse_sy = i_min(loc_y(mouse_start_y), loc_y(y));
		mouse_wy = i_abs(loc_y(y)-loc_y(mouse_start_y));

		/* no point if mouse selection is empty */
		mouse_wx = (mouse_wx == 0) ? 1 : mouse_wx;
		mouse_wy = (mouse_wy == 0) ? 1 : mouse_wy;

		/* clip selection to the size of the console */
		mouse_wx = (mouse_sx+mouse_wx > console->config.x) ?
			console->config.x - mouse_sx : mouse_wx;

		mouse_wy = (mouse_sy+mouse_wy > console->config.y) ?
			console->config.y : mouse_wy;
	}
	else
	{
		/* copy lines */

		/* calculate start and end of selection */
		loc_start = loc_x(mouse_start_x) + loc_y(mouse_start_y) * console->config.x;
		loc_end = loc_x(x) + loc_y(y) * console->config.x;

		/* swap start and end as needed */
		if(loc_start>loc_end)
		{
			int temp = loc_start;
			loc_start = loc_end;
			loc_end = temp;
		}
	}

	return;
}