please format code with </> button * homework policy * asking questions
My current code, when I press another keycode in the middle of a jump, it changes the direction of the jump, instead of waiting for a jump to end before starting a new jump. My code is here. It looks like a jumpFly game
final int CLOCK_LONG=200;
final int CLOCK_SHORT=150;
final int DOTS_SIZE=20;
final int BETWEEN_DOTS=200;
float angleLong=0;
float angleShort=0;
final int FLY_SIZE=30;
int flyX=width/2-BETWEEN_DOTS/2;
int flyY=height/2-BETWEEN_DOTS/2;
int jumpSpeed=10;
void setup() {
size(500, 500);
}
void draw() {
background(#24B41D);
strokeWeight(6);
stroke(#FC8412);
drawHand();
moveHand();
drawDots();
drawFly();
jumping();
}
void drawHand() {
float longX=cos(angleLong)* CLOCK_LONG;
float longY=sin(angleLong)* CLOCK_LONG;
float shortX=cos(angleShort)*CLOCK_SHORT;
float shortY=sin(angleShort)*CLOCK_SHORT;
line(width/2, height/2, width/2+longX, height/2+longY);
line(width/2, height/2, width/2+shortX, height/2+shortY);
}
void drawDots() {
noStroke();
strokeWeight(1);
fill(0, 0, 255);
ellipse(width/2-BETWEEN_DOTS/2, height/2-BETWEEN_DOTS/2, DOTS_SIZE, DOTS_SIZE);
ellipse(width/2+BETWEEN_DOTS/2, height/2-BETWEEN_DOTS/2, DOTS_SIZE, DOTS_SIZE);
ellipse(width/2-BETWEEN_DOTS/2, height/2+BETWEEN_DOTS/2, DOTS_SIZE, DOTS_SIZE);
ellipse(width/2+BETWEEN_DOTS/2, height/2+BETWEEN_DOTS/2, DOTS_SIZE, DOTS_SIZE);
}
void moveHand() {
angleLong=(angleLong+0.02)%TWO_PI;
angleShort=(angleShort+0.01)%TWO_PI;
}
void drawFly() {
fill(255);
circle(flyX,flyY,FLY_SIZE);
}
void jumping() {
if (keyCode==UP&&flyY<=height/2+BETWEEN_DOTS/2) {
flyY=flyY-jumpSpeed;
flyY=max(flyY, height/2-BETWEEN_DOTS/2);
} else
if (keyCode==DOWN&&flyY>=height/2-BETWEEN_DOTS/2) {
flyY=flyY+jumpSpeed;
flyY=min(height/2+BETWEEN_DOTS/2, flyY);
} else
if (keyCode==LEFT&&flyX<=width/2+BETWEEN_DOTS/2) {
flyX=flyX-jumpSpeed;
flyX=max(flyX, width/2-BETWEEN_DOTS/2);
} else
if (keyCode==RIGHT&&flyX>=width/2-BETWEEN_DOTS/2) {
flyX=flyX+jumpSpeed;
flyX=min(flyX, width/2+BETWEEN_DOTS/2);
}
}