multiple key presses issue.
in
Programming Questions
•
5 months ago
Hello,
could some one please help me i'm not sure if what i'm trying to do is possible, but i have created a rubiks cube consisting of 9 rows of 3 blocks, i have targeted each row with a colour when inputing a key press however once pressed a certain corresponding key, the colour changes when another key has been pushed. Is it possible that if i push a key the colour will appear and when i push another key this colour will remain and a new colour will appear on another row of blocks. i have included my code please could someone be able to explain to me if what i want to do is do able as I'm stuck.
thanks.
void setup(){
size(1000,800,P3D);
frameRate(30);
}
void draw(){
background(0);
lights();
String s = "Input one of the following on your keyboard: A B C D E F G H I";
fill(255);
text(s,10,10,100,100); // Text wraps within text box
float xpos = -110;
float ypos = 0;
float zpos =0;
translate(width/2,height/2,0);
rotateY(radians(mouseX));
rotateX(radians(mouseY));
for(int i= 0; i < 3; i++){
//do whatever is in here 3 times
pushMatrix();
fill(255);
translate(xpos,ypos, 0);
if (keyPressed == true) {
fill(3,0,252);//blue
xpos = 210;
ypos = 260;
zpos = 89;
box(150);
} else {
fill(255);
}
if (key == 'a' || key == 'A') { //target the key with a specific letter
fill(3,0,252);//blue
} else {
fill(255);
}
box(100);
popMatrix();
xpos = xpos + 110;
}
ypos = -110;
xpos = -110;
for(int i= 0; i < 3; i++){
//do whatever is in here 10 times
pushMatrix();
fill(255);
translate(xpos,ypos, 0);
if (keyPressed == true) {
fill(252,0,0);//red
xpos = 100;
ypos = -230;
zpos = -200;
} else {
fill(255);
}
if (key == 'b' || key == 'B') {
fill(252,0,0);//red
} else {
fill(255);
}
box(100);
popMatrix();
xpos = xpos + 110;
}
ypos = -220;
xpos = -110;
for(int i= 0; i < 3; i++){
//do whatever is in here 10 times
pushMatrix();
fill(255);
translate(xpos,ypos, 0);
if (keyPressed == true) {
fill(248, 252, 3);//yellow
xpos = 300;
ypos = -300;
zpos = -250;
} else {
fill(255);
}
if (key == 'c' || key == 'C') {
fill(248, 252, 3);//yellow
} else {
fill(255);
}
box(100);
popMatrix();
xpos = xpos + 110;
}
ypos = -110;
xpos = -110;
zpos = -110;
for(int i= 0; i < 3; i++){
//do whatever is in here 10 times
pushMatrix();
fill(255);
translate(xpos,ypos, zpos);
if (keyPressed == true) {
fill(3,0,252);//blue
xpos = -210;
ypos = 300;
zpos = -130;
} else {
fill(255);
}
if (key == 'd' || key == 'D') {
fill(3,0,252);//blue
} else {
fill(255);
}
box(100);
popMatrix();
xpos = xpos + 110;
}
ypos = -220;
xpos = -110;
zpos = -110;
for(int i= 0; i < 3; i++){
//do whatever is in here 10 times
pushMatrix();
fill(255);
translate(xpos,ypos, zpos);
if (keyPressed == true) {
fill(252,0,0);//red
xpos = -310;
ypos = 400;
zpos = -300;
} else {
fill(255);
}
if (key == 'e' || key == 'E') {
fill(252,0,0);//red
} else {
fill(255);
}
box(100);
popMatrix();
xpos = xpos + 110;
}
ypos = -220;
xpos = -110;
zpos = -220;
for(int i= 0; i < 3; i++){
// do whatever is in here 10 times
pushMatrix();
fill(255);
translate(xpos,ypos, zpos);
if (keyPressed == true) {
fill(255,128,8);//green
xpos = -110;
ypos = -110;
zpos = 100;
box(200);
} else {
fill(255);
}
if (key == 'f' || key == 'F') {
fill(255,128,8);//green
box(100);
} else {
fill(255);
}
box(100);
popMatrix();
xpos = xpos + 110;
}
ypos = -110;
xpos = -110;
zpos = -220;
for(int i= 0; i < 3; i++){
// do whatever is in here 10 times
pushMatrix();
fill(255);
translate(xpos,ypos, zpos);
if (keyPressed == true) {
fill(29,106,0);//green
xpos = 400;
ypos = 0;
zpos = 300;
} else {
fill(255);
}
if (key == 'g' || key == 'G') {
fill(29,106,0);//green
} else {
fill(255);
}
box(100);
popMatrix();
xpos = xpos + 110;
}
ypos = 0;
xpos = -110;
zpos = -220;
for(int i= 0; i < 3; i++){
// do whatever is in here 10 times
pushMatrix();
fill(255);
translate(xpos,ypos, zpos);
if (keyPressed == true) {
fill(248, 252, 3);//yellow
xpos = 310;
ypos = -420;
zpos = 220;
box(150);
} else {
fill(255);
}
if (key == 'h' || key == 'H') {
fill(248, 252, 3);//yellow
box(100);
} else {
fill(255);
}
box(100);
popMatrix();
xpos = xpos + 110;
}
ypos = 0;
xpos = -110;
zpos = -110;
for(int i= 0; i < 3; i++){
// do whatever is in here 10 times
pushMatrix();
fill(255);
translate(xpos,ypos, zpos);
if (keyPressed == true) {
fill(255, 128, 8);//orange
xpos = -320;
ypos = -320;
zpos = -200;
} else {
fill(255);
}
if (key == 'i' || key == 'I') {
fill(255, 128, 8);//orange
} else {
fill(255);
}
box(100);
popMatrix();
xpos = xpos + 110;
}
}
void keyPressed () {
println ("key pressed");
if (key == '2') {
println ("key pressed");
} else{
}
}
1