We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Individual values for a class object
Page Index Toggle Pages: 1
Individual values for a class object (Read 150 times)
Individual values for a class object
Oct 23rd, 2008, 9:21pm
 
Hows it going, Im very new to processing to forgive any stupid mistakes i might be making. Im simulating a queue for college and im doing well so far. Clicking on a button will make a new customer enter. The problem is that the customers are all going to the same location (there is no collision detection). Here is a snippet of the code:

int lineBuffer= 20;
Customer[] customers = new Customer[100];

int customerCount=0;
...
void draw()
{
..
for (i = 0; i < customerCount; i++)
{
   customers[i].waitLine();
   customers[i].moveLine(customerCount);
   
}
}
void mouseReleased()
{
 
 
 if (mouseX > 300 && mouseX < 300+80 && mouseY > 550 && mouseY < 550+40) {    
 customers[customerCount] = new Customer();
 customerCount++;    
 }
}

//and the customer class
public class Customer
{
 color c;
 float xpos;
 float ypos;
 float xspeed;
 float distX;
 float lineBuffer;
 int customerCount;
 Customer() { // A constructor.
   
   c = color(175);
   xpos = 10;
   ypos = 0;
   xspeed = 5;
   
 }


void waitLine()
{
 
 step = 0.01;
 distX = 30;
 distY = 215;
 rectMode(CENTER);
   stroke(0);
   fill(c);
 
   if (xpos <= 60 && ypos <= 215)
   {
   
   ypos = ypos + (step * distY);
   xpos  = xpos + (step * distX);
   
   }
   rect(xpos,ypos,20,10);

}
void moveLine(int customerCount)
{
 step = 0.01;
 if (ypos >= 214)
 {
 distX = 400;

 rectMode(CENTER);
   stroke(0);
   fill(c);
    if (xpos < (300 - (lineBuffer * customerCount) ))
    {
     
      xpos  = xpos + (step * distX);
    }    
 }
 
}

}

the problem is in the moveLine class I think. I tried using taers physics but I have no idea how to implement or use it and I don't know if it will be any use to me.

Any suggestions would be a big help, thanks




Page Index Toggle Pages: 1