| name | fxgl-snake |
| description | Build a Snake game in FXGL — move on a discrete grid by timer steps, store the body as a deque of grid cells, grow when food is eaten, buffer direction changes, detect self-collision and wall rules, increase speed as the snake grows, and support multiple food types or wrap mode.
|
| triggers | ["snake","grid movement","deque body","food spawn","no 180 turn","wrap mode","self collision","step timer"] |
| compatibility | Java 17+, FXGL 21.x.
|
| category | fxgl/game-types |
| tags | ["fxgl","java","javafx","game-types","snake"] |
| metadata | {"author":"fxgl-skills","version":"1.0","fxgl-version":"21.1"} |
| allowed-tools | ["Read","Write","Edit","Bash"] |
FXGL Snake
Grid Model
private static final int COLS = 20;
private static final int ROWS = 20;
private static final int CELL = 32;
private final Deque<Point2D> body = new ArrayDeque<>();
private final Queue<Direction> directionQueue = new ArrayDeque<>();
private Direction currentDirection = Direction.RIGHT;
private Point2D foodCell = new Point2D(10, 10);
private boolean growNextStep = false;
Game Start
private void resetSnake() {
body.clear();
body.addFirst(new Point2D(5, ));
body.addLast( (, ));
body.addLast( (, ));
currentDirection = Direction.RIGHT;
directionQueue.clear();
growNextStep = ;
spawnFood();
}