Fixed the code that detects when you've "eaten" a pellet (Thanks, PT_!). I also added viruses (created the image myself using Gravit Designer). The code so far:
//import libraries
import processing.net.*;
import processing.sound.*;
PImage Virus;
PFont Righteous;
SoundFile mainLoop;
int lineChoice, bgChoice, k, textChoice, massBool, massRegrowChance, pMass;
int gridLine[] = {224, 32};
int bg[] = {254, 0};
int textColor[] = {0, 255};
float xPos, yPos, x, y, speed, transitionColor, vX, vY, rand1, rand2, rand3;
//create arrays
ArrayList<Integer> xList;
ArrayList<Integer> yList;
ArrayList<Integer> colorList;
ArrayList<Integer> virusXPos;
ArrayList<Integer> virusYPos;
color mainColor, mainOutline;
void setup()
{
colorMode(HSB, 100);
surface.setResizable(true);
size(800, 600);
x = width/2;
y = height/2;
speed = 8;
pMass = 40;
massRegrowChance = 50;
Righteous = createFont("Righteous.otf", 20);
textFont(Righteous);
Virus = loadImage("Agar.png");
imageMode(CENTER);
mainLoop = new SoundFile(this, "Fluid Dynamics.mp3");
xList = new ArrayList<Integer>();
yList = new ArrayList<Integer>();
colorList = new ArrayList<Integer>();
virusXPos = new ArrayList<Integer>();
virusYPos = new ArrayList<Integer>();
colorMode(RGB, 255);
for (int i=0; i < 100; i++)
{
xList.add(int(random(-600, width + 600)));
yList.add(int(random(-300, height + 300)));
colorList.add(color(random(25, 100), random(25, 100), random(25, 100)));
}
colorMode(HSB, 100);
for (int i=0; i < 50; i++)
{
virusXPos.add(int(random(-500, width + 500)));
virusYPos.add(int(random(-200, height + 200)));
}
loadingScreen();
mainLoop.loop();
rand1 = random(0, 359);
rand2 = random(0, 100);
rand3 = random(0, 100);
mainColor = color(rand1, rand2, rand3);
mainOutline = color(rand1, rand2, rand3 - 10);
colorMode(RGB, 255);
}
void draw()
{
environment();
massMovement();
//debug();
}
void massMovement()
{
xPos = mouseX;
yPos = mouseY;
xPos = map(xPos, 0, width, -speed, speed);
yPos = map(yPos, 0, height, -speed, speed);
for (int i=0; i < 50; i++)
{
x = xList.set(i, int(xPos) + xList.get(i));
y = yList.set(i, int(yPos) + yList.get(i));
vX = virusXPos.set(i, int(xPos) + virusXPos.get(i));
vY = virusYPos.set(i, int(yPos) + virusYPos.get(i));
fill(colorList.get(i));
if (xList.get(i) > width + 500 || xList.get(i) < -500 || yList.get(i) > height + 200|| yList.get(i) < -200)
{
massBool = int(random(-massRegrowChance, massRegrowChance));
if (massBool == int(random(-massRegrowChance, massRegrowChance)))
{
xList.set(i, int(random(0, width)));
yList.set(i, int(random(0, height)));
}
}
ellipse(x, y, 10, 10);
massGrow();
}
for (int i=0; i < 10; i++)
{
xPos = mouseX;
yPos = mouseY;
xPos = map(xPos, 200, 600, -speed, speed);
yPos = map(yPos, 100, 300, -speed, speed);
vX = virusXPos.set(i, int(xPos) + virusXPos.get(i));
vY = virusYPos.set(i, int(yPos) + virusYPos.get(i));
image(Virus, vX, vY);
}
for (int i=0; i < 10; i++)
{
image(Virus, virusXPos.get(i), virusYPos.get(i), 100, 100);
}
fill(mainColor);
strokeWeight(6);
stroke(mainOutline);
ellipse(width/2, height/2, pMass, pMass);
fill(textColor[textChoice]);
text("Agar.io+", (width/4) - 200, 60);
colorMode(RGB, 255);
}
void environment()
{
if (key == '1')
{
lineChoice = 0;
bgChoice = 0;
k = 2;
textChoice = 0;
} else if (key == '2')
{
lineChoice = 1;
bgChoice = 1;
k = 1;
textChoice = 1;
}
background(bg[bgChoice]);
for (int i=0; i < width; i++)
{
strokeWeight(3);
stroke(gridLine[lineChoice]);
line(25*i, 0, 25*i, height);
line(0, 25*i, width, 25*i);
}
}
void transition()
{
for (int i=5; i < width; i++)
{
transitionColor = color(random(40, 255), random(40, 255), random(40, 255));
fill(transitionColor);
ellipse(400, 300, i, i);
}
}
void massGrow()
{
for (int i=0; i < 50; i++)
{
//credits to PT_ for helping me on the "eating mass" line
if ((pow((width/2 - xList.get(i)), 2) + pow((height/2 - yList.get(i)), 2)) < pow((pMass/2 + 2), 2))
{
xList.set(i, int(random(0, width)));
yList.set(i, int(random(0, height)));
pMass++;
}
}
}
void debug()
{
stroke(252, 0, 0);
line(400, 300, width/2 + pMass/2, 300);
line(width/2, height/2, xList.get(4), yList.get(4));
line(width/2, height/2, (width/2) + (pMass/2), height/2);
fill(textColor[textChoice]);
text(pMass/2, 700, 50);
text(int(dist(400, 300, width/2 + pMass/2, pMass/2)), 0, 550);
text(int(dist(width/2, height/2, xList.get(4), yList.get(4))), 0, 600);
noFill();
ellipse(xList.get(4), yList.get(4), 10, 10);
}
void titleScreen()
{
for (int i=0; i < 300; i++)
{
ellipse(width/2, height/2, i, i);
}
text("Agar.io+", 300, 380);
}
void loadingScreen()
{
strokeWeight(6);
stroke(int(random(0, 255)), int(random(0, 255)), int(random(0, 255)));
for (float n=1; n < 500; n = n + 0.1)
{
ellipse(width/2, height/2, int(n) * 0.05, int(n) * 0.05);
}
}