Help Moving object with arrows
in
Programming Questions
•
1 month ago
Modify Program 1 so that the Zoog can be moved up, down, left, and right by pressing the corresponding arrrow keys. In addition, detect a least one other key depression by the user which acts like a toggle. The first key depression activating a visual change to the zogg and the second depression of the same key turning off the visual effect.
original:
size(200,200);
background(0);
ellipseMode(CENTER);
rectMode(CENTER);
//Zoog's body
stroke(39,242,29);
fill(255);
triangle(100,75,130,150,70,150);
//Zoog's head
fill(39,242,29);
ellipse(100,70,60,60);
stroke(127);
line(90,90,110,90);
//Zoog's eyes
fill(0);
ellipse(81,70,16,25);
ellipse(119,70,16,25);
//Zoog's Legs
stroke(255);
line(90,150,80,170);
line(80,170,90,120);
line(110,150,120,170);
line(120,170,110,120);
what I have:
float topY= 30;
float bottomY= 100;
float leftX= 30;
float rightX= 170;
void setup(){
size(200,200);
}
void draw(){
background(0);//Draw a black background
}
void keyPressed(){
if(keyCode==CODED){
if(keyCode==UP){
topY < Y-1;
} else if (keyCode==DOWN){
bottomY> Y+1;
} else if (keyCode==RIGHT){
rightX> X-1;
}else if (keyCode==LEFT){
leftX< X+1;
}
}
//Set ellipses and triangles to CENTER
ellipseMode(CENTER);
rectMode(CENTER);
//Zoog's body
stroke(39,242,29);
fill(255);
triangle(X,Y,X+30,Y+80,X-30,Y+80);
//Zoog's head
fill(39,242,29);
ellipse(X+0,Y+5,60,60);
stroke(127);
line(X+10,Y+20,X-10,Y+20);
//Zoog's eyes
fill(mouseX,0,mouseY);
ellipse(X-19,Y+0,16,25);
ellipse(X+19,Y+0,16,25);
//Zoog's Legs
stroke(255);
line(X-10,Y+80,X-20,Y+100);
line(X-20,Y+100,X-10,Y+60);
line(X+10,Y+80,X+20,Y+100);
line(X+20,Y+100,X+10,Y+50);
}
1