I understand how arraylists work and how they are used. (most of them are lists but i will convert all of them to arraylist afterwards.)
This is my question in my program my worm which is an arraylist will move faster when it hits a powerup. But only the front link moves faster the rest of the link stays still. Ill show you the code used to make my worm move and ive tried many solutions and got 0 results.
the powerup() method is same thing as powerup= !powerup;
Some of these things will be changed later and some wont so i just need to know whats wrong here. Why isnt my act method working for all links of my array list. Btw if i start at high speed it follows appropriately it only problem when i change speeds.
public void act() { if( powerup == true) { powerUp(1); }else{ move(2); PowerUp powerUp = (PowerUp)getOneIntersectingObject(PowerUp.class); if(powerUp != null) { powerup(); t0 = System.currentTimeMillis(); } } if((index() == 0)) { controls(); bodyCrash(); } else if(acts%1 == 0) { slowDown(); followTheLeader(); } acts++; } public void powerUp(int variable) { if( System.currentTimeMillis() < (t0 + 5000)) { switch(variable) { case 1: move(5); break; case 2: move(-1); break; default: move(2); break; } }else{ powerup(); } } public boolean detectFront() { int x = 1*(int)Math.cos(getRotation()); int y = -1*(int)Math.sin(getRotation()); if((getOneObjectAtOffset(x, y, Worm.class)) != null) { return true; }else{ return false; } } public void followTheLeader() { List<Worm> wormList = getWorld().getObjects(Worm.class); int x = wormList.get(index()-1).getX() - getX(); int y = (wormList.get(index()-1).getY() - getY()); setRotation((int) (180 * Math.atan2(y, x) / Math.PI)); }