Its a bouncing game, if it hits the bar its get a hit if it doesnt it gets a miss
I wanted to change the ellipse into an alien that i made .. what am i doing wrong??
This is the game
Alien myAlien;
Alien myAlien;
void setup()
{
size (600,400);
}
myAlien = new Alien(200, 100, 50, 50);
float ballX =200;
float ballY = 100;
float speedX =10;
float speedY =0;
int hit = 0;
int miss = 0;
void draw ()
{
if(mousePressed) {hit = 0; miss = 0; }
float paddle = 1000/(hit+10);
if(ballX < 0 || ballX > width) speedX = -speedX ;
if( ballY > height ){
speedY = -speedY;
float distance = abs(mouseX-ballX);
if (distance < paddle) hit += 1;
else miss +=1;
} else speedY += 1;
ballX += speedX;
ballY += speedY;
background (100,200,500);
fill(200,100,50);
// ellipse(ballX,ballY, 50, 50);
myAlien.display();
fill (50,100,200);
rect(mouseX-paddle, height-10, 2*paddle,10);
fill (0);
text ("hit : " + hit, 10 , 20);
text ("miss : " + miss, 10 , 40);
}
{
size (600,400);
}
myAlien = new Alien(200, 100, 50, 50);
float ballX =200;
float ballY = 100;
float speedX =10;
float speedY =0;
int hit = 0;
int miss = 0;
void draw ()
{
if(mousePressed) {hit = 0; miss = 0; }
float paddle = 1000/(hit+10);
if(ballX < 0 || ballX > width) speedX = -speedX ;
if( ballY > height ){
speedY = -speedY;
float distance = abs(mouseX-ballX);
if (distance < paddle) hit += 1;
else miss +=1;
} else speedY += 1;
ballX += speedX;
ballY += speedY;
background (100,200,500);
fill(200,100,50);
// ellipse(ballX,ballY, 50, 50);
myAlien.display();
fill (50,100,200);
rect(mouseX-paddle, height-10, 2*paddle,10);
fill (0);
text ("hit : " + hit, 10 , 20);
text ("miss : " + miss, 10 , 40);
}
_____________________________________________________
this is the ALIEN CLASS
class Alien {
int bodyXloc;
int bodyYloc;
int bodyWidth;
int bodyHeight;
int bodyXloc;
int bodyYloc;
int bodyWidth;
int bodyHeight;
int head1Width;
int head1Height;
int head1Xloc;
int head1Yloc;
int head1Height;
int head1Xloc;
int head1Yloc;
int head2Width;
int head2Height;
int head2Xloc;
int head2Yloc;
int head2Height;
int head2Xloc;
int head2Yloc;
int head3Width;
int head3Height;
int head3Xloc;
int head3Yloc;
int head3Height;
int head3Xloc;
int head3Yloc;
int eye1Width;
int eye1Height;
int eye1Xloc;
int eye1Yloc;
int eye1Height;
int eye1Xloc;
int eye1Yloc;
int eye2Width;
int eye2Height;
int eye2Xloc;
int eye2Yloc;
int eye2Height;
int eye2Xloc;
int eye2Yloc;
int pupil1Width;
int pupil1Height;
int pupil1Xloc;
int pupil1Yloc;
int pupil1Height;
int pupil1Xloc;
int pupil1Yloc;
int pupil2Width;
int pupil2Height;
int pupil2Xloc;
int pupil2Yloc;
int pupil2Height;
int pupil2Xloc;
int pupil2Yloc;
int mouthX1loc;
int mouthY1loc;
int mouthX2loc ;
int mouthY2loc ;
int mouthX3loc ;
int mouthY3loc ;
Alien( int tmpbodyXloc, int tmpbodyYloc, int tmpbodyWidth, int tmpbodyHeight){
bodyXloc = tmpbodyXloc;
bodyYloc = tmpbodyYloc;
bodyWidth = tmpbodyWidth;
bodyHeight = tmpbodyHeight;
bodyYloc = tmpbodyYloc;
bodyWidth = tmpbodyWidth;
bodyHeight = tmpbodyHeight;
} // end constructor
void display() {
// draw head1
fill(165,45,210);
head1Width = bodyWidth /2;
head1Height = bodyWidth /2;
head1Xloc = bodyXloc - bodyWidth;
head1Yloc = bodyYloc - (bodyHeight / 2);
void display() {
// 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);
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);
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);
fill(0);
//left pupil
pupil1Width = bodyWidth / 11 ;
pupil1Height = bodyWidth / 11 ;
pupil1Xloc = eye1Xloc ;
pupil1Yloc = eye1Yloc + (eye1Height/4);
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);
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);
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);
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);
}
}//end class
}//end class
Thanks alot!!
1