Hey guys,
Its a bacteria game so it should eat the smallest ones first and grow bigger so he can eat the bigger ones untill the end of the game. i manages to make it so it moves with the mouse but its not eating them anymore!!
Could you please help??!!
Its a bacteria game so it should eat the smallest ones first and grow bigger so he can eat the bigger ones untill the end of the game. i manages to make it so it moves with the mouse but its not eating them anymore!!
Could you please help??!!
Here is the game;
float x;
float y;
float easing = 0.02;
int r = 8;
int gameCase = 1;
int num = 10;
Alien myAlien;
float[] bugx = new float [num];
float[] bugy = new float [num];
int[] bugr = new int [num];
float[] speedx = new float [num];
float[] speedy = new float [num];
float a = 0.05;
//int Alienx = 150;
//int Alieny = 50;
int Aliensize = 20;
float x;
float y;
float easing = 0.02;
int r = 8;
int gameCase = 1;
int num = 10;
Alien myAlien;
float[] bugx = new float [num];
float[] bugy = new float [num];
int[] bugr = new int [num];
float[] speedx = new float [num];
float[] speedy = new float [num];
float a = 0.05;
//int Alienx = 150;
//int Alieny = 50;
int Aliensize = 20;
void setup() {
size (800, 600);
smooth();
ellipseMode (CENTER);
myAlien = new Alien( Aliensize, Aliensize);
for (int i=0; i<num; i++) {
bugx[i] = random (0, width);
bugy[i] = random (0, height);
bugr[i] = int (random (0, 30));
}
x = random (0, width);
y = random (0, height);
}
void draw() {
background (150, 60, 60);
noStroke();
fill (0);
for (int i=0; i<num; i++) {
ellipse (bugx[i], bugy[i], bugr[i]*2, bugr[i]*2);
}
myAlien.display();
for (int i=0; i<num; i++) {
float z=(bugx[i]-x)*(bugx[i]-x)+(bugy[i]-y)*(bugy[i]-y)-(bugr[i]+r)*(bugr[i]+r);
if (z<0 && bugr[i]>r) {
gameCase = 0;
}
}
if (gameCase == 0) {
gameover();
} else {
float targetX = mouseX;
float targetY = mouseY;
// Alienx += (targetX - Alienx) * easing;
// Alieny += (targetY - Alieny) * easing;
for (int i=0; i<num; i++) {
move (i);
}
}
for (int i=0; i<num; i++) {
if ((bugx[i]-x)*(bugx[i]-x)+(bugy[i]-y)*(bugy[i]-y)-(bugr[i]+r)*(bugr[i]+r)<0 && bugr[i]<r) {
r = int (sqrt (r*r + bugr[i]*bugr[i]));
bugr[i] = 0;
}
}
int sum = 100;
for (int i=0; i<num; i++) {
sum += bugr[i];
}
if (sum == 100) {
win();
}
}
void move(int i) {
speedx[i] += random (-a, a);
speedy[i] += random (-a, a);
bugx[i] += speedx[i];
bugy[i] += speedy[i];
if (bugx[i]<-10) {
bugx[i] += width;
}
if (bugx[i] > width+10) {
bugx[i] -= width;
}
if (bugy[i] < -10) {
bugy[i] += height;
}
if (bugy[i] > height+10) {
bugy[i] -= height;
}
}
void gameover() {
fill (240, 40, 40);
textSize (65);
textAlign(CENTER);
text ("Game Over", width/2, height/2);
}
void win() {
fill (255);
textSize (65);
textAlign(CENTER);
text ("Congratulations!", width/2, height/2);
textSize (30);
text ("Bacterial Cleared!", width/2, height/2+50);
}
_________________________________________________________
Here is the Alien Class
class Alien {
int bodyXloc;
int bodyYloc;
int bodyWidth;
int bodyHeight;
int head1Width;
int head1Height;
int head1Xloc;
int head1Yloc;
int head2Width;
int head2Height;
int head2Xloc;
int head2Yloc;
int head3Width;
int head3Height;
int head3Xloc;
int head3Yloc;
int eye1Width;
int eye1Height;
int eye1Xloc;
int eye1Yloc;
int eye2Width;
int eye2Height;
int eye2Xloc;
int eye2Yloc;
int pupil1Width;
int pupil1Height;
int pupil1Xloc;
int pupil1Yloc;
int pupil2Width;
int pupil2Height;
int pupil2Xloc;
int pupil2Yloc;
int mouthX1loc;
int mouthY1loc;
int mouthX2loc ;
int mouthY2loc ;
int mouthX3loc ;
int mouthY3loc ;
Alien( int tmpbodyWidth, int tmpbodyHeight){
bodyXloc = mouseX;
bodyYloc = mouseY;
bodyWidth = tmpbodyWidth;
bodyHeight = tmpbodyHeight;
} // end constructor
void display() {
bodyXloc = mouseX;
bodyYloc = mouseY;
// draw head1
fill(165,45,210);
head1Width = bodyWidth /2;
head1Height = bodyWidth /2;
head1Xloc = bodyXloc - bodyWidth;
head1Yloc = bodyYloc - (bodyHeight / 2);
ellipse(head1Xloc,head1Yloc,head1Width,head1Height);
fill(255,0,134);
//Mouth
mouthX1loc = head1Xloc ;
mouthY1loc = head1Yloc ;
mouthX2loc = head1Xloc - (head1Width / 2) ;
mouthY2loc = head1Yloc ;
mouthX3loc = head1Xloc ;
mouthY3loc = head1Yloc +(head1Height / 2);
triangle(mouthX1loc,mouthY1loc,mouthX2loc,mouthY2loc,mouthX3loc,mouthY3loc);
//right eye
fill(12,203,243);
eye2Width = head1Width / 4 ;
eye2Height = bodyWidth / 4;
eye2Xloc = head1Xloc +(head1Width / 4);
eye2Yloc = head1Yloc - (head1Height/2);
//Left Eye
eye1Width = head1Width / 4 ;
eye1Height = bodyWidth / 4;
eye1Xloc = head1Xloc - (head1Width / 4);
eye1Yloc = head1Yloc - (head1Height/2);
ellipse (eye1Xloc,eye1Yloc,eye1Width,eye1Height);
ellipse (eye2Xloc,eye2Yloc,eye2Width,eye2Height);
fill(0);
//left pupil
pupil1Width = bodyWidth / 11 ;
pupil1Height = bodyWidth / 11 ;
pupil1Xloc = eye1Xloc ;
pupil1Yloc = eye1Yloc + (eye1Height/4);
ellipse(pupil1Xloc,pupil1Yloc,pupil1Width,pupil1Height);
//right pupil
pupil2Width = bodyWidth / 11 ;
pupil2Height = bodyWidth / 11 ;
pupil2Xloc = eye2Xloc ;
pupil2Yloc = eye2Yloc + (eye2Height/4);
ellipse(pupil2Xloc,pupil2Yloc,pupil2Width,pupil2Height);
fill(165,45,210);
// draw head2
head2Width = head1Width ;
head2Height = head1Height ;
head2Xloc = head1Xloc + (head1Width / 2);
head2Yloc = head1Yloc + (head1Height / 2);
ellipse(head2Xloc,head2Yloc,head2Width,head2Height);
//head 3
head3Width = head2Width;
head3Height = head2Height;
head3Xloc = head2Xloc + (head2Width / 2);
head3Yloc = head2Yloc + (head2Width / 2) ;
ellipse(head3Xloc, head3Yloc, head3Width, head3Height);
fill(165,45,210);
//body
ellipse(bodyXloc,bodyYloc,bodyWidth,bodyHeight);
}}
THANKS!!!!!!!!!
1