void edgeFollow(bool& running){ sweeps = 0; if(direction == LEFT) { motor[left] = -SPEED; motor[right] = SPEED; } else { motor[left] = SPEED; motor[right] = -SPEED; } bool wasDark = isDark(); do{ //Find border point if(wasDark != isDark()) { wasDark = isDark(); wait10Msec(3); if(direction == LEFT) { direction = RIGHT; motor[left] = SPEED; motor[right] = 0; } else if( direction == RIGHT) { direction = LEFT; motor[right] = SPEED; motor[left] = 0; } sweeps++; abortTimeslice(); } }while(running); }
/** * Turns around until black is found */ void turnToLine(void) { spinInDirection(); while(!isDark()) { abortTimeslice(); } int startDir = currentDirection(); while(isDark()) { abortTimeslice(); } motor[left] = 0; motor[right] = 0; int centre = startDir + (angleDifference(currentDirection(), startDir)/2); nxtDisplayCenteredTextLine(6, "cen: %i", centre); turnToAngle(centre, 0); }
task FollowEdge(){ if(!isDark()){ panic("Not on an edge!"); wait10Msec(1000); StopAllTasks(); } followingEdge = true; edgeFollow(followingEdge); }
bool checkIsLeaf(void) { int direction = currentDirection(); while(!isDark()) { if( abs(angleDifference(currentDirection(), direction)) > 170) { return true; } } return false; }
void weather::printData() { fprintf(stdout,"Sunset time: %i:%.2i\n",sunset->tm_hour,sunset->tm_min); fprintf(stdout,"Sunrise time: %i:%.2i\n",sunrise->tm_hour,sunrise->tm_min); if(isDark()) { fprintf(stdout,"It is dark\n"); } else { fprintf(stdout,"It is not dark\n"); } if(isLight()) { fprintf(stdout, "It is Light\n"); } else { fprintf(stdout, "It is not light\n"); } fprintf(stdout,"It is %.1fF degrees outside\n",temp); fprintf(stdout,"There is %.1fmph of wind outside\n",wind_mph); fprintf(stdout,"The weather outside is %s\n",observedWeather.c_str()); }
void GameBoard::paint( AbstractPainter *painter ) { // copy thing characters out to entities ThingList::iterator iter; for( iter = d->thingList.begin(); iter != d->thingList.end(); ++iter ) { ZZTThing::AbstractThing *thing = *iter; thing->updateEntity(); } ZZTThing::Player *plyr = player(); const int px = plyr->xPos(); const int py = plyr->yPos(); // paint all entities for ( int i = 0; i<FIELD_SIZE; i++ ) { const int x = (i%60); const int y = (i/60); if ( d->world->transitionTile(x, y) ) { // don't paint over transition tiles continue; } ZZTEntity &entity = d->field[i]; if ( isDark() && !entity.isVisibleInDarkness() && ( world()->currentTorchCycles() == 0 || beyondVisible( x, y, px, py ) ) ) { painter->paintChar( x, y, 0xb0, 0x07 ); continue; } entity.paint( painter, x, y ); } d->drawMessageLine( painter ); }