thank you so much my problem is getting the snake to increase in size after it eats food my formula is not working
int growth = 3;
final int X_SPEED = 1;
final int Y_SPEED = 1;
final int SNAKE_SIZE=15;
final int SNAKE_LENGTH=SNAKE_SIZE*growth;
int x = width/2;
int y =height/2;
float foodX = random(0, 500);
float foodY = random(0, 500);
int foodSize = 15;
boolean hit = false; //controls hit detection logic for when the snake hits the food
int totalHits = 0; //the game will start at 0 points and in increase by 1 with each food catpure
final int MAX_HITS =5;
//final int SNAKE_LENGTH=3;
// ---------------------------------------------------------------------------
void setup() {
size(500, 500);
background(220);
y=250;
}
//ellipse(250,290,SNAKE_SIZE,SNAKE_SIZE);
void draw() {
background(220);
if (x >= 500 || x <= 0) {
background(0);
}
if (y >= 500 || y <= 0) {
background(0);
}
moveSnake();
checkIfKeyPressed();
drawTarget();
checkIfHitTarget();
}
void moveSnake() {
//int y2=0;
fill(#FFFFFF);
for (int iY=0; iY<SNAKE_LENGTH; iY++) {
if(key == 'w'){
ellipse(x, y-iY*SNAKE_SIZE, SNAKE_SIZE, SNAKE_SIZE);
}
else if(key == 's'){
ellipse(x, y+iY*SNAKE_SIZE, SNAKE_SIZE, SNAKE_SIZE);
}
for (int iX=0; iX<SNAKE_LENGTH; iX++) {
if(key == 'd'){
ellipse(x - iX*SNAKE_SIZE, y, SNAKE_SIZE, SNAKE_SIZE);
}
else if(key == 'a'){
ellipse(x + iX*SNAKE_SIZE, y, SNAKE_SIZE, SNAKE_SIZE);
}
//y2+=20;
}
}
}
void checkIfKeyPressed() {
if (key=='w') {
moveSnake();
y -= Y_SPEED;
}
else if (key=='s') {
moveSnake();
y += Y_SPEED;
}
else if (key=='a') {
moveSnake();
x -= X_SPEED;
}
else if (key=='d') {
moveSnake();
x += X_SPEED;
}
}
void drawTarget(){
fill(0);
rect(foodX,foodY, foodSize,foodSize);
}
void checkIfHitTarget(){
if (dist(x, y, foodX, foodY)<=foodSize-5)
{
foodX = random(0+foodSize/2, 500-foodSize/2);
foodY = random(0+foodSize/2, 500-foodSize/2);
hit = true;
}
if (hit)
{
totalHits += 1;
hit=!hit;
growth++;
}
}paste code here