finishing touches help please
in
Programming Questions
•
1 year ago
i have finished this piece of coursework for my uni class but i would like to give it a few touch ups.
1. add a background to the program
2. make it so the fill colour is random each time
how would i accomplish this.
here is my 2 pieces of code (save the first one as Alien to work and second one as DemoAlien):
class Alien {
int bodyXLoc;
int bodyYLoc;
int bodyWidth;
int bodyHeight;
int eyeWidth;
int eyeHeight;
int eyeXLoc;
int eyeYLoc;
int eyeballWidth;
int eyeballHeight;
int eyeballXloc;
int eyeballYloc;
int earleftWidth;
int earleftHeight;
int earleftXloc;
int earleftYloc;
int earrightWidth;
int earrightHeight;
int earrightXloc;
int earrightYloc;
int mouthXloc;
int mouthYloc;
int mouthHeight;
int mouthWidth;
int noseXloc;
int noseYloc;
int noseHeight;
int noseWidth;
int eyebrowXloc;
int eyebrowYloc;
int eyebrowHeight;
int eyebrowWidth;
int speedXLoc;
int speedYLoc;
Alien(int tempX, int tempY, int tempWidth, int tempHeight, int tempXSpeed, int tempYSpeed) {
bodyXLoc = tempX;
bodyYLoc = tempY;
bodyWidth = tempWidth;
bodyHeight = tempHeight;
speedXLoc = tempXSpeed;
speedYLoc = tempYSpeed;
}
void drawleftear() {
fill(116,250,8);
earleftXloc = bodyXLoc - 50;
earleftYloc = bodyYLoc - 50;
earleftWidth = bodyWidth / 5;
earleftHeight = bodyHeight - 50;
ellipse(earleftXloc,earleftYloc,earleftWidth,earleftHeight);
}
void drawrightear() {
earrightWidth = bodyWidth / 4;
earrightHeight = bodyHeight - 50;
earrightXloc = bodyXLoc + 50;
earrightYloc = bodyYLoc - 50;
ellipse(earrightXloc,earrightYloc,earrightWidth,earrightHeight);
}
void drawbody() {
fill(255);
ellipse(bodyXLoc,bodyYLoc,bodyWidth,bodyHeight);
}
void draweye() {
int offSet = bodyWidth / 10;
eyeXLoc = bodyXLoc - offSet;
eyeYLoc = bodyYLoc - (bodyHeight / 4);
eyeWidth = bodyHeight / 5;
eyeHeight = bodyWidth / 5;
ellipse(eyeXLoc,eyeYLoc,eyeWidth,eyeHeight);
}
void draweyebrow() {
fill(0);
eyebrowXloc = bodyXLoc - 70;
eyebrowYloc = bodyYLoc - 85;
eyebrowWidth = bodyWidth - 150;
eyebrowHeight = bodyHeight / 25;
rect(eyebrowXloc,eyebrowYloc,eyebrowWidth,eyebrowHeight);
}
void draweyeball() {
fill(0);
int eyeballoffset = bodyWidth / 10;
eyeballXloc = bodyXLoc - eyeballoffset;
eyeballXloc = bodyXLoc - 25;
eyeballYloc = bodyYLoc - 50;
eyeballWidth = bodyHeight / 10;
eyeballHeight = bodyWidth / 10;
ellipse(eyeballXloc,eyeballYloc,eyeballWidth,eyeballHeight);
}
void drawmouth() {
fill(0);
mouthXloc = bodyXLoc;
mouthYloc = bodyYLoc + 75;
mouthWidth = bodyWidth - 100;
mouthHeight = bodyHeight - 150;
ellipse(mouthXloc,mouthYloc,mouthWidth,mouthHeight);
}
void drawnose() {
fill(255,3,3);
noseXloc = bodyXLoc - 50;
noseYloc = bodyYLoc + 50;
noseWidth = bodyWidth - 100;
noseHeight = bodyHeight - 100;
ellipse(noseXloc,noseYloc,noseWidth,noseHeight);
}
void move() {
bodyXLoc = bodyXLoc + speedXLoc;
bodyYLoc = bodyYLoc + speedYLoc;
}
void checkForBounce() {
if(bodyXLoc > width - (bodyWidth / 2 )) {
speedXLoc = speedXLoc * -1;
}
if(bodyXLoc < 0 + (bodyWidth / 2 )) {
speedXLoc = speedXLoc * -1;
}
if(bodyYLoc > height - (bodyHeight / 2 )) {
speedYLoc = speedYLoc * -1;
}
if(bodyYLoc < 0 + (bodyHeight / 2 )) {
speedYLoc = speedYLoc * -1;
}
}
}//endclass
2nd piece:
Alien myAlien;
void setup(){
size(700,700);
myAlien = new Alien(300,175,250,250,3,6);
}
void draw(){
background(75);
stroke(0);
myAlien.drawleftear();
myAlien.drawrightear();
myAlien.drawbody();
myAlien.draweye();
myAlien.draweyebrow();
myAlien.draweyeball();
myAlien.drawmouth();
myAlien.drawnose();
myAlien.move();
myAlien.checkForBounce();
}
1