I want to make an animation to persuade people to get vaccinated for a school project. I want when a “person” that has red head which indicates that he is not vaccinated, gets in touch with the vaccine change his color to green
class Vaccine
{
float x, y, size, speedX, speedY;
PImage imageVaccine;
Vaccine(float xx, float yy, float vs, float spX, float spY)
{
x = xx;
y = yy;
speedX = spX;
speedY =spY;
imageVaccine = loadImage(“vaccine.png”);
size = 50;
}
void display()
{
image(imageVaccine, x, y, size, size);
}
void moveLeft()
{
x = x - speedX;
}
void moveRight()
{
x = x + speedX;
}
void moveUp()
{
y = y - speedY;
}
void moveDown()
{
y = y + speedY;
}
float getX()
{
return x;
}
float getY()
{
return y;
}
float getSize()
{
return size;
}
void setRed(int r)
{
r = 0;
}
void setGreen(int g)
{
g=255;
}
void setBlue(int b)
{
b=0;
}
class People
{
color c;
float xpos;
float ypos;
float size;
boolean vstatus;
int red, green, blue;
People ( boolean vs, float x, float y, int s, int r, int g, int b)
{
vstatus=vs;
xpos = x;
ypos = y;
size = s;
green = g;
red = r;
blue = b;
if (vs==true) {c=color (0,240,0);}
else {c=color (250,0,0);}
xpos=x;
ypos=y;
size=s;
}
void display()
{
fill(red,green,blue);
ellipse(xpos,ypos,size,size);
ellipse(xpos,ypos,size,size);
}
float getX()
{
return xpos;
}
float getY()
{
return ypos;
}
float getSize()
{
return size;
}
}
void setRed(int r)
{
r = 0;
}
void setGreen(int g)
{
g=255;
}
void setBlue(int b)
{
b=0;
}
Vaccine v;
People p1, p2;
void setup()
{
size(800,800);
v= new Vaccine(100,300,400,15,5);
p1 = new People(false,255,200,150,0,240,0);
p2 = new People(true,585,200,150,250,0,0);
}
void draw()
{
background(255);
v.display();
p1.display();
p2.display();
if(dist(v.getX(),v.getY(),p2.getX(),p2.getY()) <= v.getSize()/2+p2.getSize()/2 )
{
p2.setRed(0);
p2.setGreen(255);
p2.setBlue(0);
}
}
void keyPressed()
{
if (key == CODED)
{
if (keyCode == LEFT)
{
v.moveLeft();
}
else if (keyCode == RIGHT)
{
v.moveRight();
}
}
if (key == CODED)
{
if (keyCode == UP)
{
v.moveUp();
}
else if (keyCode == DOWN)
{
v.moveDown();
}
}