I need help with my snake game

but with 16 by 8 blocks window size, where yellow is for banana(+10 points), red is for apple(+5 points) and green block is for cameleon(-5 points). The problem I’m facing is that my fruits are never in the same coordinates as my snake’s head. So I’m unable to eat or score any point. Please help is anyone can. I have shared my code

int xbuttons = 60;
int textLocX= 242;
int num=4;
int buttonsY [] = new int[num];
int textLocY [] = new int[num];
int index=0;
int pagesize=0;
int positi [] = new int[num];

int blocks=30;

int buttonC =#FFFF00;
int buttonW = 400;
int buttonH=50;

int numbx=16;
int numby=8;

int angle=0;
int snakesize=5;
int time=0;
int[] headx= new int[2500];
int[] heady= new int[2500];
int applex=int(random(1,numbx))*width/numbx;
int appley=int(random(1,numby))*width/numby;
int bananax=(round(random(48))+1)*8;
int bananay=(round(random(48))+1)*8;

int cameleonx=(round(random(48))+1)*8;
int cameleony=(round(random(48))+1)*8;
boolean redo=true;
boolean stopgame=false;
int a=49;
int bc=0;
int score=0;

int blocksx=30;
int blocksy=60;

void setup() {
size(496, 496);
background(0);
mouseClicked();
restart();

textAlign(CENTER);
background(255);

for ( int i=1; i<4; i++)
{
buttonsY[index]=50;
buttonsY [index + i] +=buttonsY[index +i -1] +100;

positi[i]=buttonsY[i];

textLocY[index]=80;
textLocY [index + i] += textLocY[index +i -1] +100;

}
}

void draw() {
if (pagesize==0){
Button1();
Button2();
Button3();
Button4();
headx[1]=8;
heady[1]=9;

}

if (pagesize==1){

if (stopgame)
{
//do nothing because of game over (stop playing)
}
else
{

//draw stationary stuff

time+=2;
stroke(255);
fill(255,0,0);
stroke(255);
rect(applex,appley,blocksx,blocksy);

fill(255,251,0);
stroke(255);
rect(bananax,bananay,blocksx,blocksy);

fill(0,255,0);
stroke(255);
rect(cameleonx,cameleony,blocksx,blocksy);

fill(0);
stroke(0);
rect(0,0,width,8);
rect(0,height-8,width,8);
rect(0,0,8,height);
rect(width-8,0,8,height);

//my modulating time by 5, we create artificial frames each 5 frames
//(otherwise the game would go WAY too fast!)
if ((time % 50)==0)
{
travel();
display();
checkdead();
score();
}
}
}
}

void mouseClicked() {
if(mouseX>=xbuttons && mouseX<=buttonW && mouseY>=buttonsY[3] && mouseY>=buttonH) {
println(“Mouse Clicked”);
pagesize=1;
background(255);
stroke(0);
for ( int i=8; i<=width; i+=30){
line(i,0,i,height);
}

for ( int i=8; i<=width; i+=60){
line(0,i,width,i);
}
}
}

void display()
{
if (pagesize==1){

if (headx[1]==cameleonx && heady[1]==cameleony)
{

snakesize--;
score-=5;
redo=true;
while(redo)
{
  
  
  for(int i=1;i<snakesize;i++)
  {
    
    if (cameleonx==headx[i] && cameleony==heady[i])
    {
      redo=true;
      
    }
    else
    {
      redo=false;
      i=1000;
    }
  }
}

}

if (headx[1]==applex && heady[1]==appley)
{

snakesize+=round(random(1)+1);
score+=5;
redo=true;
while(redo)
{
  applex=int(random(1,numbx))*width/numbx;
  appley=int(random(1,numby))*width/numby;
  
  for(int i=1;i<snakesize;i++)
  {
    
    if (applex==headx[i] && appley==heady[i])
    {
      redo=true;
      
    }
    else
    {
      redo=false;
      i=1000;
    }
  }
}

}

if (headx[1]==bananax && heady[1]==bananay)
{
snakesize+=round(random(1)+1);
score+=10;
redo=true;

  while(redo)
{
  for ( int inc=1; inc<=20; inc++){
  bananax=round(random(a)+1)*8;
  bananay=round(random(a)+1)*8;
  
  for ( int i=1; i<snakesize; i++)
  {
    if (headx[1]==bananax && heady[1]==bananay)
    {
      redo=true;
      i++;
      
    }
    else {
      redo=false;
    }
  }
}
}
}

//draw the new head of the snake…
stroke(255);
fill(0);
rect(headx[1],heady[1],blocksx,blocksy);
//…then erase the back end of the snake.
fill(255);
rect(headx[snakesize],heady[snakesize],blocksx,blocksy);
}
}

void keyPressed()
{
if (key == CODED)
{

if (keyCode == UP && angle!=270 && (heady[1]-8)!=heady[2])
{
  angle=90;
}
if (keyCode == DOWN && angle!=90 && (heady[1]+8)!=heady[2])
{
  angle=270;
}if (keyCode == LEFT && angle!=0 && (headx[1]-8)!=headx[2])
{
  angle=180;
}if (keyCode == RIGHT && angle!=180 && (headx[1]+8)!=headx[2])
{
  angle=0;
}
if (keyCode == SHIFT)
{
  //restart the game by pressing shift
  restart();
}

}
}

void travel()
{
if (pagesize==1) {
for(int i=snakesize;i>0;i–)
{
if (i!=1)
{
//shift all the coordinates back one array
headx[i]=headx[i-1];
heady[i]=heady[i-1];
}
else
{
//move the new spot for the head of the snake, which is
//always at headx[1] and heady[1].
switch(angle)
{
case 0:
headx[1]+=blocksx;
break;
case 90:
heady[1]-=blocksy;
break;
case 180:
headx[1]-=blocksx;
break;
case 270:
heady[1]+=blocksy;
break;
}
}
}
}
}

void restart()
{
if (pagesize==1){
//by pressing shift, all of the main variables reset to their defaults.
background(255);
headx[1]=8;
heady[1]=9;
for(int i=2;i<1000;i++)
{
headx[i]=0;
heady[i]=0;
}
stopgame=false;
applex=int(random(1,numbx))*width/numbx;
appley=int(random(1,numby))*width/numby;

bananax=int(random(1,numbx))*width/numbx;
bananay=int(random(1,numby))*width/numby;

for(int i=8; i<width; i+=30)
{
cameleonx=int(random(i));
}

for (int i=8; i<height; i+=60)
{
cameleony=int(random(i));
}

stroke(0);
for ( int i=8; i<=width; i+=30){
line(i,0,i,height);
}

for ( int i=8; i<=width; i+=60){
line(0,i,width,i);
}

snakesize=5;
time=0;
angle=0;
redo=true;
score=0;

}
}
float sinecolor(float percent)
{
float slime=(sin(radians((((time +(255*percent)) % 255)/255)*360)))*255;
return slime;
}

void score(){
if (pagesize==1){

noStroke();
fill(255);
textSize(12);
rect(width-80,height-20,70,12);
fill(0);
text("Score= " +score, width-40,height-10);
}
}

void checkdead()
{
if (pagesize==1){
for(int i=2;i<=snakesize;i++)
{
//is the head of the snake occupying the same spot as any of the snake chunks?
if (headx[1]==headx[i] && heady[1]==heady[i])
{
fill(0);
rect(80,125,300,120);
fill(255);
text(“GAME OVER”,230,150);
text(“To restart, press Shift.”,230,200);
stopgame=true;

  text("score=" +score, 230,225);
}
//is the head of the snake hitting the walls?
if (headx[1]>=(width-8) || heady[1]>=(height-8) || headx[1]<=0 || heady[1]<=8)
{
  fill(0);
  rect(80,125,300,120);
  fill(255);
  text("GAME OVER",230,150);
  text("To restart, press Shift.",230,200);
  
  stopgame=true;
  text("score=" +score, 230,225);
}

}
}
}

void Button1(){
stroke(255);
fill (buttonC);
rect(xbuttons, buttonsY[0], buttonW, buttonH );
fill(0);
textSize(24);
text(“Number of Players”, textLocX, textLocY[0] );

}

void Button2(){
stroke(255);
fill (buttonC);
rect(xbuttons, buttonsY[1], buttonW, buttonH );
fill(0);
textSize(24);
text("Number of Bananas 20 " , textLocX, textLocY[1] );
}

void Button3(){
stroke(255);
fill (buttonC);
rect(xbuttons, buttonsY[2], buttonW, buttonH );
fill(0);
text("Page Size ", textLocX, textLocY[2] );

}

void Button4(){
fill (buttonC);
rect(xbuttons, buttonsY[3], buttonW, buttonH );
fill(0);
textSize(24);
text(“Start Game!” , textLocX+20, textLocY[3] );
}

Please edit your post with the small pencil.
Write three backticks or cop these ```
and paste them one line above, and one below your code.
Delete the ones within the code.
This way the code can easily be copied.
Thanks.

this is a duplicate imho

I answered in the other discussion

Chrisir