Trying to combine these two projects...
in
Programming Questions
•
1 year ago
Both of these codes work fine seperately but I wanna make it so that I have the burgers flying in the background AND have the guy opening and closing his mouth in the bottom right hand corner.
To see the first code in action visit:
http://www.openprocessing.org/user/21091 and click on "project 4 (in progress)
thanks much!
int numFrames = 3; //The Number of frames in the animation
To see the first code in action visit:
http://www.openprocessing.org/user/21091 and click on "project 4 (in progress)
thanks much!
int numFrames = 3; //The Number of frames in the animation
int frame = 0;
PImage[] images = new PImage[numFrames];
void setup()
{
size(800,600);
frameRate(10);
images[0] = loadImage("Bob1.png");
images[1] = loadImage("Bob2.png");
images[2] = loadImage("Bob3.png");
}
void draw()
{
PImage img;
img = loadImage("burger.JPG");
background(img);
frame = frame +1;
if (frame>=numFrames){
frame=0;
}
//frame= (frame+1) % numFrames; // use % to cycle through frames
image(images[frame],50,50);
}
void mousePressed() {
PImage img;
img = loadImage("Cheeseburger.png");
image(img, 550, 450);
image(img, 450,400);
image(img,0,0);
image(img,650,0);
image(img,0,450);
}
and then:
Burger[] Burger = new Burger[12];
void setup() {
size(800,600);
for (int i = 0; i < Burger.length; i++ ) {
Burger[i] = new Burger(random(width), random(height), random(1,3));
}
}
void draw() {
PImage img;
img = loadImage("burger.JPG");
background(img);
if (mousePressed == true)
for (int i = 0; i < Burger.length; i++ ) {
Burger[i].swimfast();
Burger[i].killerfish();
Burger[i].display();
} else {
for (int i = 0; i < Burger.length; i++ ) {
Burger[i].swim();
Burger[i].display();
}
}
}
class Burger {
float xpos;
float ypos;
float xspeed;
Burger(float tempx, float tempy, float tempspeed) {
println("a Burger has been created");
xpos = tempx;
ypos = tempy;
xspeed = tempspeed;
}
void display() {
PImage Burger;
Burger = loadImage("Cheeseburger.png");
image(Burger, xpos, ypos);
}
void swim() {
xpos = xpos + xspeed;
if (xpos > width) {
xpos = 0;
}
}
void swimfast() {
xpos = xpos + 10*xspeed;
if (xpos > width) {
xpos = 0;
}
}
void killerfish() {
PImage killerfish;
imageMode(CENTER);
if ((xpos < mouseX + 70) && (xpos > mouseX - 70)) {
if ((ypos < mouseY + 70) && (ypos > mouseY - 70)) {
xpos+=70;
ypos+=70;
if ((xpos > 600) && (ypos > 600)) {
xpos=random(0, 300);
ypos = random(0, 300);
}
}
}
}
}
1