Exemple #1
0
void ofTurtle::draw(int _x, int _y)
{
  int ppi=pixPerInch;
  ofPoint wheel(.25*ppi,(2+3/8)*ppi);
  ofPoint rWheel(1.125*ppi,1.875*ppi);
  ofRectangle body(-3.25*ppi/2,-wheel.y/2,ppi*3.25,ppi*4.5);
  //int body=w-whlWid*2;
  //int leng=h;
  ofEnableSmoothing();
  for (unsigned int i=0; i<lines.size()-1&&lines.size()>1; i++) {
    ofSetLineWidth(2);
    ofLine(lines[i].x, lines[i].y, lines[i+1].x, lines[i+1].y);
  }
  ofDisableSmoothing();
  ofPushMatrix();
  ofTranslate(pos.x, pos.y, 0);
  ofRotate(360-bearing.absoluteAngle());
  
  ofEnableSmoothing();
  ofSetColor(black.opacity(128));
  ofRect(body.x,body.y,body.width,body.height);
  ofSetColor(white);
  ofNoFill();
  ofRect(body.x,body.y,body.width,body.height);
  ofFill();
  ofSetColor(black);
  ofRect(body.x-ppi*3/8, body.y, wheel.x, wheel.y);
  ofRect(body.x+body.width+ppi*3/32, body.y, wheel.x, wheel.y);
  /*ofSetColor(white*.8);
  ofRect(body.x+(body.width-ppi*1.375)/2, body.y+body.height, 1.375*ppi, .25*ppi);
  ofRect(body.x+(body.width-ppi*1.375)/2+1.125*ppi, body.y+body.height, .25*ppi,1.375*ppi);
  ofSetColor(white*.5);
  ofRect(body.x+(body.width-ppi*1.375)/2+.125*ppi, body.y+body.height+.5*ppi, .875*ppi, 1.5*ppi);
  ofSetColor(orange);
  ofRect(body.x+(body.width-ppi*1.375)/2+.125*ppi, body.y+body.height+.50625*ppi, .375*ppi, .4375*ppi);
  ofRect(body.x+(body.width-ppi*1.375)/2+.125*ppi, body.y+body.height+(2.-.4375)*ppi, .375*ppi, .4375*ppi);
  ofRect(body.x+(body.width-ppi*1.375)/2+(1-.375)*ppi, body.y+body.height+(.5+(1.5-.4375)/2)*ppi, .375*ppi, .4375*ppi);*/
  ofPopMatrix();
  ofDisableSmoothing();
  
  if(!frontIsClear(frontCheckDist)) ofSetColor(255, 0, 0);
  else ofSetColor(0, 255, 0);
  ofPoint ps = pointAlongBearing(frontCheckDist+wheel.y/2);
  ofCircle(ps.x, ps.y, 5);
  
  if(!leftIsClear(leftCheckDist)) ofSetColor(255, 0, 0);
  else ofSetColor(0, 255, 0);
  ps = pos+bearing.ortho().unit()*w/2-bearing.unit()*w/2+bearing.unit().rotate(270)*leftCheckDist;
  ofCircle(ps.x, ps.y, 5);
  
  for (unsigned int i=0; i<bdy.size(); i++) {
    ofSetColor(yellow);
    ofVector t=bdy[i];
    ofLine(pos, pos+t.rotate(360-bearing.absoluteAngle()));
  }
}
Exemple #2
0
/**
 * @brief Funkcia posunie karla o 1 poziciu dopredu posla smeru otocenia
 */
void movek(void) {
    if (frontIsClear()) {
        switch (karel.direction) {
            case EAST:
                karel.x += 1;
                break;
            case NORTH:
                karel.y += 1;
                break;
            case WEST:
                karel.x -= 1;
                break;
            case SOUTH:
                karel.y -= 1;
                break;            
        }    
    }
    else
        die("Karol nemoze ist vpred!");
    
    draw();
}
Exemple #3
0
/**
 * @brief Funkcia zistuje ci je pred karlom stena alebo koniec sveta.
 * @return Vracia TRUE ak je pred karlom stena alebo koniec sveta. FALSE ak je pred karlom prazdno alebo znacka.
 */
int frontIsBlocked(void) {
    return !frontIsClear();
}
Exemple #4
0
bool ofTurtle::frontIsClear(int distance)
{
  return frontIsClear(distance,map);
}