Uploaded with ImageShack.us
hi.. from my uploaded images there are buses on 2 route, namely the blue route and the red route.. my task is to move these buses on their respective route and make the bus stop when it is at the end of its route...
my code to make 1 bus move...
public void actionPerformed(ActionEvent e) { if (status == false) { System.out.println("status false"); tm.stop(); } else if (CurI>= i-1)// end of the route { status =false; } else { if(numOfInc[0] == 0) { double BigD = 0; int smallD = 4; // the algorithm for smooth movement but curve not tested BigD = Math.sqrt((xcoord[CurI+1]-xcoord[CurI])*(xcoord[CurI+1]-xcoord[CurI]) + (ycoord[CurI+1]-ycoord[CurI])*(ycoord[CurI+1]-ycoord[CurI])); double numInc = BigD/smallD - 1; numOfInc[0] = (int)numInc; int changeInX = xcoord[CurI+1] - xcoord[CurI]; double incX_double = changeInX/numOfInc[0]; xm[0] = (int)incX_double; int changeInY = ycoord[CurI+1] - ycoord[CurI]; double incY_double = changeInY/numOfInc[0]; ym[0] = (int)incY_double; X1 = xcoord[CurI]; Y1 = ycoord[CurI]; repaint(); } else { X1 += xm[0]; Y1 += ym[0]; numOfInc[0] --; if(numOfInc[0] == 0) CurI++; repaint(); }//end else tm.start(); } }//end actionPerformed() ... at the paint method; g.drawImage(img2,X1-15,Y1-15,null);
need help on editing the codes to work on multiples buses.. the number of buses would be dynamically changing... so the performance has to be considered...
Thanks....