I'm trying to make an Agar.io copy

I am new in programming and I wanted to try to make Agar.io copy, but I do not know how to create food.

My code

Problem n 1: You dont n++, and this makes the game draw infinite food(but dont do this, do what I say next)
Problem n 2, you should store the coordinates of the generated food, or the game will draw random food every cicle. i suggest to initialize an array food with random positions and when one food is eaten, you find the eaten food in the array and replace it with another coordinates, color…

Thanks, but I do not know how to do it, I tried it and I did not succeed, and when I add n ++ food does not create

when the while() finishes, you set n = 0, but as I said, you dont store any food coordinates, and this makes the food position will change everytime

Can you help me, I’m new to programming. Please

New to coding :confused:
I cant help much bc I dont use java,
but take a look to array
and do a while() for the array where you fill it with PVectors()
in draw you do another while where you draw food and check wth dist() if its eaten. If its eaten, you replace the coordinates with new random ones, if not, you draw the food.
If you are very new to programming in Java, you should first learn the basis in another IDE, because PDE is not the best way to start learning a new progr language. What you need for a generating food is:
Working with arrays(Loop through array, accesing with the index,)
when you got confortable with arrays, you can start using a class for food
I cant give you more help than this
Good luck

1 Like
float l1;
float l2;
float n;
float x; 
float y;
float easing = 0.05;
float cr;
float cf;
PVector[] food= new PVector [50];

void setup() {
n = 0;
cr = 50;
for(int i = 0;i < 50;i++){
  food[i] = new PVector(random(0,width),random(0,height));


void draw() {
  cf = random(16,24);

l1 = 0;
l2 = 0;
while (l1 < width) {
l1 = l1 + 30;

while (l2 < height) {
l2 = l2 + 30;
float targetX = mouseX;
  float dx = targetX - x;
  x += dx * easing;
  float targetY = mouseY;
  float dy = targetY - y;
  y += dy * easing;
  ellipse(x, y, cr, cr);

for(int i = 0;i < 50;i++){


I just delay(60000) from studying and looked at java arrays and made you this simple example.
You can add an int [] r = new [50] for the radi of every food and do a variable like array_dim = 50 and replace every fifty with this dim so when you can change this value to add more space in the array
(You cant modify arrays space while the program is running, except for a special kind of arrays that idk how are they called)
I suggest you to read about pointers,

This tutorial might help: