Hi, I have a problem. I've been trying do make a snake but I don't know how to make all the tails follow the previous ones and the head. Can someone help me please ? Thx
public SnakeHead() { memorize = true; } public void act() { setDirection(); setRotation(MyWorld.direction); move(MyWorld.speed); eatApple(); wichCoordinate(); } public void wichCoordinate() { if (memorize) { x1 = getX(); y1 = getY(); memorize = false; } else { x2 = getX(); y2 = getY(); memorize = true; } }
public Snake() { setRotation(MyWorld.direction); } public void act() { settingLocation(); checkSnake(); setRotation(MyWorld.direction); move(MyWorld.speed); } /** * Set the Location depending on the value memorized previously */ public void settingLocation() { if(SnakeHead.memorize) { setLocation(SnakeHead.x2, SnakeHead.y2); } else { setLocation(SnakeHead.x1, SnakeHead.y1); } } /** * If the tail is touching itself or the head, game over */ public void checkSnake() { if (isTouching(Snake.class)) { MyWorld world = (MyWorld)getWorld(); world.gameOver(); } else if (isTouching(SnakeHead.class)) { MyWorld world = (MyWorld)getWorld(); world.gameOver(); } }