View unanswered posts | View active topics It is currently Sun Oct 26, 2014 5:38 am






Reply to topic  [ 2 posts ] 
What does each line of code mean in the program? 
Author Message
Rookie

Joined: Tue Dec 03, 2013 10:24 am
Posts: 1
Post What does each line of code mean in the program?
Code:
#pragma config(Sensor,S4,startgame,sensorTouch)
#pragma config(Motor,motorA,GAUCHE,tmotorNormal,PIDControl,encoder)
int paddlelength=9; //Length of the paddle.
int ball=2.5; // size of the ball.
int paddlewidth=1; // paddle width.
int XLpaddle = paddlewidth;
int yG_Raquette;
int xBalle,yBalle;
int bDirection;
bool bPerdu;
task Balle(){
int mxBalle;
int myBalle;
mxBalle = xBalle;
myBalle = yBalle;
bDirection = 1;
while(!SensorValue[startgame]){
}
while(true){
  switch(bDirection){
  case 0:
    xBalle++;
    yBalle++;
    if (yBalle > 63 - ball ){
      yBalle--;
      yBalle--;
      bDirection = 1;
    }
    if (xBalle > 99 - ball ){
      xBalle--;
      xBalle--;
      bDirection = 3;
    }
  break;
  case 1:
    xBalle++;
    yBalle--;
    if (xBalle > 99 - ball ){
      xBalle--;
      xBalle--;
      bDirection = 2;
    }
    if (yBalle < 0 ){
      yBalle++;
      yBalle++;
      bDirection = 0;
    }
   break;
   case 2:
    xBalle--;
    yBalle--;
    if (yBalle < 0 ){
      yBalle++;
      yBalle++;
      bDirection = 3;
    }
    if (xBalle < 1 + ball + paddlewidth){
       if((yBalle >= yG_Raquette - paddlelength) & (yBalle <= yG_Raquette + paddlelength)){
          xBalle++;
         xBalle++;
        bDirection = 1;
      }else{
      bPerdu = true;
      StopTask (Balle);
      }
    }
   break;
   case 3:
    xBalle--;
    yBalle++;
    if (xBalle < 1 + ball + paddlewidth ){
       if((yBalle >= yG_Raquette - paddlelength) & (yBalle <= yG_Raquette + paddlelength)){
        xBalle++;
        xBalle++;
        bDirection = 0;
      }else{
      bPerdu = true;
      StopTask (Balle);
      }
    }
    if (yBalle > 63 - ball ){
      yBalle--;
      yBalle--;
      bDirection = 2;
    }
   break;
  }
  wait10Msec(3);
  if ((mxBalle != xBalle) | (myBalle != yBalle)){

    nxtEraseRect( mxBalle, myBalle, mxBalle + ball, myBalle + ball);
    nxtDrawRect( xBalle, yBalle, xBalle + ball, yBalle + ball);
    mxBalle = xBalle;
    myBalle = yBalle;
  }
}
return;
}
task Gauche_Raquette(){
int yGm;
int mCodeur;
mCodeur =0;
  yGm = 31;
  nMotorEncoder[GAUCHE] = 0;
  nxtDrawRect(XLpaddle - paddlewidth, yGm + paddlelength,XLpaddle + paddlewidth  , yGm - paddlelength);
  while(true){
    mCodeur = nMotorEncoder[GAUCHE]/2 + 31;
    if (mCodeur > 63 - paddlelength){
      yG_Raquette = 63 - paddlelength;
    }
    else{
      if (mCodeur < paddlelength){
        yG_Raquette = paddlelength;
      }
      else {
        yG_Raquette = mCodeur;
      }
    }
    if (yG_Raquette != yGm){
      nxtEraseRect(XLpaddle - paddlewidth, yGm + paddlelength,XLpaddle + paddlewidth  , yGm - paddlelength);
      nxtDrawRect(XLpaddle - paddlewidth, yG_Raquette + paddlelength,XLpaddle + paddlewidth  , yG_Raquette - paddlelength);
      yGm = yG_Raquette;
    }
 }
  return;

}
task main(){
eraseDisplay();
xBalle = XLpaddle+paddlewidth+1;
yBalle =random(63-ball)+ball;
nxtDrawRect( xBalle, yBalle, xBalle + ball, yBalle + ball);
StartTask(Gauche_Raquette);
StartTask(Balle);
while(true){
   if (bPerdu){
      StopTask(Gauche_Raquette);
    nxtDisplayTextLine(3, "BIG DADDY LOSER");
   }
}
return;
}


Tue Dec 03, 2013 10:28 am
Profile
Expert
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 140
Post Re: What does each line of code mean in the program?
Yikes! I think you might have more success asking specific questions about things in the code you don't understand. Also, if you're completely new to ROBOTC and are trying to find out how to code in it, you might take a look at the education curriculum at http://www.education.rec.ri.cmu.edu/previews/robot_c_products/teaching_rc_tetrix_preview/index.html.

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://cof7468.weebly.com/.


Wed Dec 04, 2013 3:41 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.