Square will not move in grid
in
Programming Questions
•
5 months ago
I am a newbie in processing and I wish to move a square by using the arrow keys. Some of my code is below:
void keyPressed (){
if ((keyPressed == true) && (key == CODED)) {
if (keyCode == RIGHT) {
//if (directionX < 0)
directionX = 1;
directionY = 0;
println ("bush");
}
else if (keyCode == LEFT) {
//if (directionX > 0)
directionX = -1;
directionY = 0;
println ("lenin");
}
else if (keyCode == UP) {
//if (directionY < 0)
directionY = -1;
directionX = 0;
println ("high");
}
else if (keyCode == DOWN) {
//if (directionY < 0)
directionY = 1;
directionX = 0;
println ("low");
}
}
}
Where am I going wrong???
void keyPressed (){
if ((keyPressed == true) && (key == CODED)) {
if (keyCode == RIGHT) {
//if (directionX < 0)
directionX = 1;
directionY = 0;
println ("bush");
}
else if (keyCode == LEFT) {
//if (directionX > 0)
directionX = -1;
directionY = 0;
println ("lenin");
}
else if (keyCode == UP) {
//if (directionY < 0)
directionY = -1;
directionX = 0;
println ("high");
}
else if (keyCode == DOWN) {
//if (directionY < 0)
directionY = 1;
directionX = 0;
println ("low");
}
}
}
Where am I going wrong???
1