public void updatePosition(SnakeGame parent) { Vector2 prevPos = positions[0]; Vector2 newPos; switch (currDir) { case dir.UP: positions[0] = new Vector2(positions[0].X, positions[0].Y - parent.getIncr()); if (positions[0].Y < parent.getIncr()) { int fixedPos = parent.getWindowHeight() - parent.getIncr(); fixedPos -= fixedPos % parent.getIncr(); positions[0] = new Vector2(positions[0].X, fixedPos); } break; case dir.DOWN: positions[0] = new Vector2(positions[0].X, positions[0].Y + parent.getIncr()); if (positions[0].Y > parent.getWindowHeight() - parent.getIncr()) { int fixedPos = parent.getIncr(); positions[0] = new Vector2(positions[0].X, fixedPos); } break; case dir.LEFT: positions[0] = new Vector2(positions[0].X - parent.getIncr(), positions[0].Y); if (positions[0].X < parent.getIncr()) { int fixedPos = parent.getWindowWidth() - parent.getIncr(); fixedPos -= fixedPos % parent.getIncr(); positions[0] = new Vector2(fixedPos, positions[0].Y); } break; case dir.RIGHT: positions[0] = new Vector2(positions[0].X + parent.getIncr(), positions[0].Y); if (positions[0].X > parent.getWindowWidth() - parent.getIncr()) { int fixedPos = parent.getIncr(); positions[0] = new Vector2(fixedPos, positions[0].Y); } break; } for (int i = 1; i < positions.Count; i++) { newPos = prevPos; prevPos = positions[i]; positions[i] = newPos; } }