rooooomba! app
in
Programming Questions
•
1 years ago
so this is a simple roomba vaccuum app my lab partner and i have created. just trying to add one more action, a button press/mouse press that will add more of the mess squares when toggled. i am able to add more with these commands, but the background(); in draw keeps overlaying it, and they never show for more than a second. how do i add duplicates of the mess squares so they stay put after the press?
tried recalling draw();, tried making a new function drawMess which gets called later, but by doing this nothing happens, plain and simple.
int vacuumX = 300;
int vacuumY = 300;
int vacuum2X = vacuumX;
int vacuum2Y = vacuumY;
int vacSize = 55;
float mess1X = random(0, 400);
float mess1Y = random(0, 400);
int messSize = 20;
float mess2X = random(0, 400);
float mess2Y = random(0, 400);
float mess3X = random(0, 400);
float mess3Y = random(0, 400);
float mess4X = random(0, 400);
float mess4Y = random(0, 400);
float mess5X = random(0, 400);
float mess5Y = random(0, 400);
float mess6X = random(0, 400);
float mess6Y = random(0, 400);
float rotateMess = random(0,120);
int rugHeight = 300;
int rugWidth= 200;
int rugPos = 200;
float r;
float g;
float b;
int value = 0;
void setup() {
size(400, 400);
ellipseMode(CENTER);
rectMode(CENTER);
}
void draw() {
println(mouseX+ "'" +mouseY);
smooth();
background(144, 116, 60); //Draw floor color
int panels = 15;
int x = 0;
int endX = 400;
while (x < endX) { //Draw hardwood floor panels
line(x, 0, x, height);
x = x + panels;
}
int frillX = 100;
int frillEnd = 300;
int frillaY = 50;
int frillbY = 350;
int frillSpace = 2;
while (frillX<frillEnd) { //Draw rug frills
stroke(255);
line(frillX, frillaY, frillX, frillaY-3);
line(frillX, frillbY, frillX, frillbY+3);
frillX = frillX + frillSpace;
}
stroke(0);
fill(90, 7, 7);
rect(rugPos, rugPos, rugWidth, rugHeight); //Draw rug
r = random(0, 255); //Mess Colors
g = random(0, 255);
b = random(0, 255);
fill(r, g, b);
rect(mess1X, mess1Y, messSize, messSize); //Make Mess
if (abs(vacuumX-mess1X) <= messSize/2 && abs(vacuumY-mess1Y) <= messSize/2) {
mess1X = -100;
mess1Y = -100;
}
rect(mess2X, mess2Y, messSize, messSize); //Make Mess
if (abs(vacuumX-mess2X) <= messSize && abs(vacuumY-mess2Y) <= messSize) {
mess2X = -100;
mess2Y = -100;
}
rect(mess3X, mess3Y, messSize, messSize); //Make mess
if (abs(vacuumX-mess3X) <= messSize && abs(vacuumY-mess3Y) <= messSize) {
mess3X = -200;
mess3Y = -200;
}
rect(mess4X, mess4Y, messSize, messSize); //Make mess
if (abs(vacuumX-mess4X) <= messSize && abs(vacuumY-mess4Y) <= messSize) {
mess4X = -200;
mess4Y = -200;
}
fill(0);
ellipse(vacuumX, vacuumY, vacSize, vacSize); //Draw Roomba
fill(128);
ellipse(vacuum2X, vacuum2Y+4, vacSize, vacSize); //Draw Roomba "bumper"
fill(0);
text("ROOMBA", vacuumX-26, vacuumY+13); //Make insignia
}
void keyPressed() { //Make Roomba move
if (key == CODED) {
}
if (keyCode == DOWN) { //Make Roomba move down
vacuumY = vacuumY + 6;
vacuum2Y = vacuum2Y + 6;
vacuumY = constrain(vacuumY, 20, 380);
vacuum2Y = constrain(vacuum2Y, 20, 380);
}
else if (keyCode == UP) { //Make Roomba move up
vacuumY = vacuumY - 6;
vacuum2Y = vacuum2Y - 6;
vacuumY = constrain(vacuumY, 20, 380);
vacuum2Y = constrain(vacuum2Y, 20, 380);
}
if (keyCode == LEFT) { // Make Roomba move left
vacuumX = vacuumX - 6;
vacuum2X = vacuum2X - 6;
vacuumX = constrain(vacuumX, 20, 380);
vacuum2X = constrain(vacuum2X, 20, 380);
}
else if ( keyCode == RIGHT) { //Make Roomba move right
vacuumX = vacuumX + 6;
vacuum2X = vacuum2X + 6;
vacuumX = constrain(vacuumX, 20, 380);
vacuum2X = constrain(vacuum2X, 20, 380);
}
}
1