I have to make a game for school and it involves a worm that is represented through an arraylist. In my game i will have "powerups" that manipulate the worm for a duration of 5 seconds each. The code i currently have does not work. The error i have now is this, when the worm goes to the power up it freezes. Stops moving for the 5 seconds then it begins to collide with itself. (in other words the first part of the link stays put while the other parts collide with the first one). Thats my guess. Im gonna debug it today but if anyone has ideas or other ways to implement this idea let me know. here is the code.
/** * Act - do whatever the Player1 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { moveWorm(0); PowerUp powerup = (PowerUp)getOneIntersectingObject(PowerUp.class); if( powerup != null) { hitPowerUp = true; } if(hitPowerUp == true) { powerUp(); hitPowerUp = false; } if((index() == 0)) { controls(); bodyCrash(); } else if(acts%1 == 0) { slowDown(); followTheLeader(); } acts++; } public void powerUp() { long t0 = System.currentTimeMillis(); long t1 = 0; speed = true; do{ t1 = System.currentTimeMillis(); moveWorm(1); }while((t1 - t0) < 5000); speed = false; } public void moveWorm(int variable) { switch(variable) { case 1: move(10); break; case 2: move(-1); break; default: move(2); break; } }