Hello, I’m trying to make a game where random food items will fall from the top of the screen and a mouth on the bottom will catch them. I found an existing game with this concept and edited to add my own food pictures. the only problem is i can only replace the ones in the existing code. When i add another line to add one more food item, it doesn’t work. Can anyone help please. im posting my code below.
PFont fontA;
PFont fontB;
PImage ship;
PImage ground;
PImage eship;
PImage food;
PImage boss1;
PImage enda;
boolean lost=false;
int sphereDiameter = 25;
int endaDiameter = 25;
boolean shoot = false;
float speed=1;
float stop=0;
int hitcount=0;
int score;
float Espeed=6;
int[] sphereXCoords = {randx(), randx(), randx(), randx(), randx()};
float[] sphereYCoords = {0, 0, 0, 0, 0};
int[] ender= {1, 1, 1, 1, 1};
int[] ender2= {2, 1, 1, 1, 1};
int randx()
{
return int(random(20, 580));
}
void setup()
{
size(600, 620);
fontA = loadFont("font1.vlw");
fontB = loadFont("font2.vlw");
textFont(fontA);
ship=loadImage("face.png");
ground=loadImage("Backround.png");
eship=loadImage("Coke.png");
food=loadImage("Donuts.png");
boss1=loadImage("Boss1.png");
enda=loadImage("EggToast.png");
}
void draw()
{
background(0);
image(ground, 0, 0);
fill(color(255, 0, 0));
textFont(fontA);
text("POINTSa: " + score, 5, 610);
text("What Will You Choose?", 130, 30);
text("What Will You Choose?", 130, 30);
textFont(fontB);
text("Highscora:38304", 445, 25);
text("The Star Masta:JSRa", 435, 40);
{
if (keyPressed == true)
{
background(0);
textFont(fontA);
text("PAUSED", 250, 250);
textFont(fontA);
text("POINTSa: " + score, 5, 610);
text("Star Destroya", 214, 30);
text("Star Destroya", 214, 30);
textFont(fontB);
text("The Firsta Clasha", 240, 45);
stroke(225);
fill(0, 0, 255);
for (int i=0; i<5; i++)
{
image(ground, sphereXCoords[i]-11, sphereYCoords[i]-=speed,
sphereDiameter, sphereDiameter);
if (keyPressed == true) image(ground, sphereXCoords[i]-11, sphereYCoords[i]+=stop,
sphereDiameter, sphereDiameter);
}
}
{
fill(255);
}
rect(-50, -50, 50, 50);
}
fill(color(190, 190, 255));
stroke(color(00, 250, 100));
fill(color(0, 0, 255));
stroke(color(100, 250, 255));
image(ship, mouseX-17, 555);
fill(color(255, 0, 0));
stroke(color(255, 0, 0));
if (shoot==true)
{
sphereKiller(mouseX);
shoot = false;
}
sphereDropper();
gameEnder();
}
void mousePressed()
{
shoot = true;
if (lost==true)
{
restart();
}
}
void sphereDropper()
{
stroke(225);
fill(0, 0, 255);
for (int i=0; i<5; i++)
{
if (i==0)
{
image(food, sphereXCoords[i]-11, sphereYCoords[i]+=speed*ender2[i],
sphereDiameter, sphereDiameter);
if (keyPressed == true) image(enda, sphereXCoords[i]-11, sphereYCoords[i]+=stop,
sphereDiameter, sphereDiameter);
}
else {
image(enda, sphereXCoords[i]-11, sphereYCoords[i]+=speed*ender2[i],
sphereDiameter, sphereDiameter);
if (keyPressed == true) image(eship, sphereXCoords[i]-11, sphereYCoords[i]+=stop,
sphereDiameter, sphereDiameter);
}
}
}
void sphereKiller(int shotX)
{
fill(255, 0, 0);
boolean hit = false;
for (int i = 0; i < 5; i++)
{
if ((shotX >= (sphereXCoords[i]-sphereDiameter/2)) &&
(shotX <= (sphereXCoords[i]+sphereDiameter/2)))
{
hit = true;
score = score +152;
line(mouseX, 565, mouseX, sphereYCoords[i]);
ellipse(sphereXCoords[i], sphereYCoords[i],
sphereDiameter+10, sphereDiameter+10);
sphereXCoords[i] = randx();
sphereYCoords[i] = 0;
hitcount++;
if (hitcount>4)
{
hitcount=0;
speed=speed*1.02;
{
hit = true;
score = score +152;
line(mouseX, 565, mouseX, sphereYCoords[i]);
ellipse(sphereXCoords[i], sphereYCoords[i],
sphereDiameter+10, sphereDiameter+10);
sphereXCoords[i] = randx();
sphereYCoords[i] = 0;
hitcount++;
if (hitcount>7)
{
hitcount=0;
ender=ender2;
{
image(enda, sphereXCoords[i]-11, sphereYCoords[i]+=Espeed,
sphereDiameter, sphereDiameter);
if (keyPressed == true) image(enda, sphereXCoords[i]-11, sphereYCoords[i]+=stop,
sphereDiameter, sphereDiameter);
}
}
}
}
}
}
if (hit == false)
{
line(mouseX, 565, mouseX, 0);
}
}
void gameEnder()
{
for (int i=0; i< 5; i++)
{
if (sphereYCoords[i]>600)
{
fill(color(255, 255, 0));
lost=true;
fill(color(255, 0, 0));
textFont(fontA);
text("Click to Restart",width/2-100, height/2);
noLoop();
}
}
}
void restart()
{
lost=false;
shoot = false;
speed=1;
stop=0;
hitcount=0;
score=0;
Espeed=6;
for (int i=0; i<5; i++)
{
sphereXCoords [i] = randx();
sphereYCoords [i]= 0;
ender [i]= 1;
ender2 [i]= 1;
}
ender2[0]=2;
loop();
delay(1000);
}