Esempio n. 1
0
void RoboMiner::move(int cy, int cx)
{

	Ground *gr = frame->getGround();
	int maxCell_x = gr->getCols();
	int maxCell_y = gr->getRows();

	if(cx<0 || cx>=maxCell_x)
		return;

	if(cy<0 || cy>=maxCell_y)
		return;

/*	std::cout << "Moving from (" << cell_y << "," << cell_x << ")"
		  << " Cell(" << cell->getY() << "," << cell->getX() << ")"
		  << " to (" << cy << "," << cx << ") with max_y: "
		  <<  maxCell_y << " max_x: " << maxCell_x << std::endl;
*/
	Cell *destcell = &(gr->getCell(cy, cx));
	if(!destcell->isDrilled())
		drill(cy, cx);

	if(destcell->isDrilled()){
		cell->clearMiner();
		cell = destcell;
		cell->hasMiner(this);
		cell_y = cy;
		cell_x = cx;
		energy -= 1;
	}
}
void MapToolDriller::canvasReleaseEvent(QMouseEvent * e)
{

  QgsPoint myPoint = mCanvas->getCoordinateTransform()->toMapCoordinates(e->x(), e->y());
  QHash <QString,double> myHash;
  myHash = drill(myPoint);
  emit drilled(myHash);
}
Esempio n. 3
0
void RoboMiner::action()
{

//	if(rand() % 512 < 48)
//		scan();

//	std::cout << "E: " << energy << std::endl;

	if(ascending){
		ascend();
		return;
	}

	if(drillCell){
		--energy;
		drill(drillCell->getY(), drillCell->getX());
		return;
	}

	if(cell->mineralCount() > 0 && !isFull()){
		--energy;
		mine();
		return;
	}

	if(!destCell || exploring){
		energy -= 2;
		scan();
	}

	if(destCell){
		navigate();
	}else{
		int offset_x=0, offset_y=0;
		int roll = rand() % 512;

		if(roll >= 255){
			offset_y = (roll % 2) ? 1 : -1;
		}else{
			offset_x = (roll % 2) ? 1 : -1;
		}

/*		std::cout << "[action] off_x: " << offset_x << "  off_y: "
			  << offset_y << "  from roll: " << roll
			  << std::endl;
*/
		move(cell_y + offset_y, cell_x + offset_x);
	}

	
}
Esempio n. 4
0
void GCodeExport::doDrill(FILE *fl, bool changeToDrill, DrillReader *drillReader, double drillZSafe, bool sameDiameter, bool isProbe, int drillingSpeed, \
             int drillingLiftSpeed, int drillingSpindleSpeed, double drillDepth, double zsafe)
{
    char lineBuffer[1024];
    // drilling
    if(drillReader) {
        if(drillReader->firstDrill()) {
            toolNumber = 1;
            if(changeToDrill)
                changeTool(fl, drillReader->firstDrill()->diameter, zsafe, drillZSafe, sameDiameter, isProbe, (char*)"Drill",true);
            else if(isProbe)
                probe(fl, drillZSafe);
            sprintf(lineBuffer, "M03S%d\nG04P%d\n", drillingSpindleSpeed, drillingSpindleSpeed/5); // start spindle and wait
            fputs(lineBuffer, fl);
            Drill *nextDrill = drillReader->firstDrill();
            if(sameDiameter || !changeToDrill) {
                sprintf(lineBuffer,"(Drill %f)\n", nextDrill->diameter);
                fputs(lineBuffer, fl);
            }
            while(nextDrill) {
                GPoint *next = nextDrill->firstPoint;
                while(next) {
                    next->used = false;
                    next = next->next;
                }
                while(true) {
                    GPoint *closestPoint = 0;
                    double closestDistance = FLT_MAX;
                    next = nextDrill->firstPoint;
                    double tmp;
                    while(next) {
                        if(!next->used){
                            if( (tmp=next->distance(headPosition))<closestDistance) {
                                closestDistance = tmp;
                                closestPoint = next;
                            }
                        }
                        next = next->next;
                    }
                    if(closestPoint) {
                        drill(fl, *closestPoint, drillDepth, drillingSpeed, drillingLiftSpeed, drillZSafe);
                        closestPoint->used = true;
                    } else {
                        break; // goto from while
                    }
                }

                nextDrill = nextDrill->next;
                if(nextDrill) {
                    if(!sameDiameter) {
                        fputs("M5\n", fl);
                        changeTool(fl, nextDrill->diameter, drillZSafe, drillZSafe, sameDiameter, isProbe, (char*)"Drill", true);
                        sprintf(lineBuffer, "M03S%d\nG04P%d\n", drillingSpindleSpeed, drillingSpindleSpeed/5); // start spindle and wait
                        fputs(lineBuffer, fl);
                    } else {
                        sprintf(lineBuffer,"(Drill %f)\n", nextDrill->diameter);
                        fputs(lineBuffer, fl);
                    }
                }
            }
            fputs("M5\n", fl);
        }
    }
}
Esempio n. 5
0
int main()
{
  unsigned char x,corner;
  unsigned char frames;
  unsigned int joypad;
  unsigned char player_x, player_y;
  unsigned char exit_x=0, exit_y=0;
  unsigned int z=0;
  int ay,ax,j; 

   SetFontTable(fonts);  // this tells Print___() commands what font to use
   ClearVram();          // clears out display memory (like a 'clear screen')

  //DDRD &= 0xF7; // These are used by the "power" switch and LED on the "Gamer" baseboard that 
  //PORTD|= 0x08; // is paired with the AVCore.  The 'power' button is used to switch mazes for now.
  
  



new_maze:
  for(ay=0; ay<Y_SIZE; ay++) 
  { 
    for(ax=0; ax<X_SIZE; ax++) 
      if(ax>0 && ay>0 && ax<X_SIZE-1 && ay<Y_SIZE-1) // fills the maze with walls, that are then 'drilled' out
        maze[ay][ax]=WALL; 
      else 
        maze[ay][ax]=BLANK; 
  } 

  ay=2; // 2,2 is the top left corner of the maze
  ax=2; 
  maze[ay][ax]=4; // starting state for the maze generator
  
  do 
  { 
    while(drill(&ay,&ax,(int)(rand()&0x03))) {}  // start drilling things out (using random)
    j=maze[ay][ax];                              // note that the first time the game runs, the maze will always be 
    maze[ay][ax]=BLANK;                          // the same because of the random number generator always starting
    if(j<4)                                      // in the same state.  (Normally I will 'sum' the contents of RAM
    {                                            // on power-up to make a random seed, but I don't know how to mess
      /* back-track */                           // with WinAVR's C-startup yet.)
      ax=ax-2*dx[j]; 
      ay=ay-2*dy[j]; 
    } 
  } while(j<4); 
 
 do{                                             // This generates a random position inside the maze to start the
 	do player_x=rand();                          // player.  Seems more interesting than a corner.
	while ((player_x>=X_SIZE-1)||(player_x<=1));
	do player_y=rand();
	while ((player_y>=Y_SIZE-1)||(player_y<=1));
	}	
 while (maze[player_y][player_x]==WALL);         // (repeats until it picks a random spot that's not a wall)
 
 maze[player_y][player_x]=PLAYER;                // place the player in the maze

 do                                              // here we choose a random number from 0-3, representing one of the
 	{                                            // four corners of the maze.
 	corner=rand()&0x03;
 	switch (corner)                              
 		{
	 	case 0:
			exit_x=2; exit_y=2; break;
		case 1:
			exit_x=X_SIZE-3; exit_y=2; break;
		case 2:
			exit_x=X_SIZE-3; exit_y=Y_SIZE-3;break;
		case 3:
			exit_x=2; exit_y=Y_SIZE-3; break;
 		}
	}
 while (abs(player_x-exit_x)<16);                // we compare the distance from the player to the exit (horizontally)
                                                 // and only accept the corner if it's relatively far away from the player
	                                             // (could use both x and y distance for better effect)
	maze[exit_y][exit_x]=EXIT;                   // place the exit in the maze
	
	redraw();                                    // draw the screen for the player

 
 // This is what happens when you turn a static demo into a 'game'
 // For a real game, you probably don't want to do this, but it works here and is simple...
 
 //while(PIND&0x04)       // if the button on the Gamer Baseboard isn't pressed
 while(ReadPowerSwitch()==0) // if the button on the Gamer Baseboard isn't pressed
 {z++;                  // the z counter is used later on for a seed for the random number generator (user interaction = randomness)
 joypad=ReadJoypad(0);  // get the joypad state

 WaitVsync(1);          // this waits a frame and essentially slows the gameplay down
 frames++;              // frame counter can be used for animations (later)
 if (joypad&0xff)       // if the D-pad has a bit or more pressed
 	{
 	maze[player_y][player_x]=BLANK;            // erase the old player position
 	if (joypad&BTN_DOWN)                           // down?
 		if (maze[player_y+1][player_x]!=WALL)  // don't move if a wall is blocking your path
			player_y++;                        // you could 'switch/case' these with breaks to easily disable diagonal moves...
	if (joypad&BTN_UP)                           // up?
	 	if (maze[player_y-1][player_x]!=WALL)
			player_y--;
 	if (joypad&BTN_LEFT)                           // left?
 		if (maze[player_y][player_x-1]!=WALL)
			player_x--;
	if (joypad&BTN_RIGHT)                           // right
 		if (maze[player_y][player_x+1]!=WALL)
			player_x++;
	if (maze[player_y][player_x]==EXIT)        // if the new position is the EXIT, you just won
		{
		maze[exit_y][exit_x]=PLAYER;           // place the player on top of the exit
		redraw();                              // draw the screen for the user
		Print(14,25,strWin);                   // prints the "YOU ESCAPED!" message
		WaitVsync(30);                         // and waits for a while.
		for (x=14;x<26;x++)                    // this loops over the "YOU ESCAPED!" message
			SetTile(x,25,11);                  // and erases it.
		break;                                 // this breaks out of the while(PIND...) loop, causing a new maze to be generated 
		}
	
	maze[player_y][player_x]=PLAYER;           // after the movement calculations, put the player in the new spot
 	}
 else
 	{
	// check for idle time                     // use the frame counter to make the player graphic change if you wait around. ;-)
	}

	srand(z);    // our player-influenced 'z' value is now used to reseed the random number generator, resulting in a 'new' maze
 
	redraw();    // redraw the screen to update new player position
 }

 goto new_maze;  // this is just a hack to go do everything over again.  Before anyone lectures me about using GOTO, think about
                 // why every CPU has a 'jump/goto' instruction in its assembly language and uses it-- frequently. :-) 
}