# Hello. I am just a beginner. I want to know how to complete a jump

**URL:** <https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [October 20, 2020, 5:09pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754 "2020-10-20T17:09:19Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mengtong](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mengtong](https://discourse.processing.org/u/mengtong)\
**Post date:** [October 20, 2020, 5:09pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/1 "2020-10-20T17:09:19Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)  
> 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);  
}  
}

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 20, 2020, 5:39pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/2 "2020-10-20T17:39:34Z")

</div>

Hello and a warm welcome to the forum!

Nice to have you here!

I don’t understand

your sketch shows a clock.

Where do you want a jump? Where you move the ball with cursor?

Do you mean the ball doesn’t fly direct `----` but in a curve? Like `/\` ?

Warm regards,

Chrisir

---

<div class="post-metadata">

**Author:** ![mengtong](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mengtong](https://discourse.processing.org/u/mengtong)\
**Post date:** [October 20, 2020, 5:51pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/3 "2020-10-20T17:51:40Z")

</div>

do you know fly o’clock, this game?The fly is the white circle, and there has four dots, I want to jump between them. Now , if I press key-DOWN, the white circle will go down ,but when the white ball is moving down, if I press key-LEFT, the ball won’t go where I need it to get.  
When I press-DOWN, no matter I press any other button, the whole program will not run until the white ball completes this movement. After this movement completes, if I press another keycode, it will jump or move again, but during jumping or moving time, no matter I press any other button, the whole program will not run . This is what I want to achieve.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 20, 2020, 5:54pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/4 "2020-10-20T17:54:49Z")

</div>

here is an example, where the dot doesn’t go directly from a to b BUT  
in a curve (like in a jump).

see [https://www.processing.org/reference/curvePoint\_.html](https://www.processing.org/reference/curvePoint_.html)

I will read your answer in a second…

Warm regards, Chrisir

```auto

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;

float t;

void setup() {

  size(500, 500);
}

void draw() {
  background(#24B41D);
  strokeWeight(6);
  stroke(#FC8412);

  drawHand();
  moveHand();
  drawDots();
  drawFly();
  jumping();

  fly1 () ;
}

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);
  ellipse(flyX, flyY, FLY_SIZE, 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);

      //
      fly1();
    } 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);
        }
}

void fly1 () {

  noFill();
  // curve(5, 26, 5, 26, 73, 24, 73, 61);
  // curve(5, 26, 73, 24, 73, 61, 15, 65);
  stroke(255, 0, 0); 
  curve(
    width/2+310, height/2-BETWEEN_DOTS/2, 
    width/2-BETWEEN_DOTS/2, height/2-BETWEEN_DOTS/2, 
    width/2-BETWEEN_DOTS/2, height/2+BETWEEN_DOTS/2, 
    width/2+310, height/2+BETWEEN_DOTS/2
    );  

  fill(255);
  ellipseMode(CENTER);
  int steps = 6;
  // for (int i = 0; i <= steps; i++) {
  // float t = i / float(steps);
  float x;// = curvePoint(5, 5, 73, 73, t);
  float y;// = curvePoint(26, 26, 24, 61, t);

  x = curvePoint( width/2+310, width/2-BETWEEN_DOTS/2, width/2-BETWEEN_DOTS/2, width/2+310, t);
  y = curvePoint( height/2-BETWEEN_DOTS/2, height/2-BETWEEN_DOTS/2, height/2+BETWEEN_DOTS/2, height/2+BETWEEN_DOTS/2, t);
  ellipse(x, y, 5, 5);

  t+=0.01;
  if (t>=1) t=0.0;
}

```

---

<div class="post-metadata">

**Author:** ![mengtong](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mengtong](https://discourse.processing.org/u/mengtong)\
**Post date:** [October 20, 2020, 5:59pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/5 "2020-10-20T17:59:02Z")

</div>

Sorry, not like this. I want it move straight, not a curve. You can run my code. When you press one keycode, immediately press another keycode, you’ll see that the ball isn’t on the four blue dots.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 20, 2020, 5:59pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/6 "2020-10-20T17:59:21Z")

</div>

I don’t know the game.

What you wrote:

> [@mengtong](#):
>
> When I press-DOWN, no matter I press any other button, the whole program will not run until the white ball completes this movement. After this movement completes, if I press another keycode, it will jump or move again, but during jumping or moving time, no matter I press any other button, the whole program will not run . This is what I want to achieve.

**Is this what you want to achieve or what happens now?**

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 20, 2020, 6:01pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/7 "2020-10-20T18:01:32Z")

</div>

I understand now.

You can set a variable boolean isMoving to true as long as you are moving.

When the white ball reaches its target say `isMoving = false;`

When `isMoving == false` don’t accept any new key input!!!

So before setup() say `boolean isMoving = false;`

EDIT: Not sure how to do this…

Chrisir

---

<div class="post-metadata">

**Author:** ![mengtong](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mengtong](https://discourse.processing.org/u/mengtong)\
**Post date:** [October 20, 2020, 6:06pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/8 "2020-10-20T18:06:20Z")

</div>

Sorry, I can understand what you are talking about. But I don’t know how to use it. Where should I add this boolean? I am very confused  
EDIT:Thank you very much. I will try it . Also, I have one more question, how to add Z coordinate, to make this jump looks like a real jump. The white ball size will get bigger in the first half of jump, and the ball will get smaller in the second half of jump. I have formula but don’t know how to use.  
the first half of jump:𝑓𝑙𝑦𝑍 = 2 ∗ (𝑀𝐴𝑋\_𝑍/𝑆𝑃𝐴𝐶𝐼𝑁𝐺) ∗ 𝑗𝑢𝑚𝑝𝑂𝑓𝑓𝑠𝑒t  
the second half of jump:𝑓𝑙𝑦𝑍 = 2 ∗ 𝑀𝐴𝑋\_𝑍 (1 −𝑗𝑢𝑚𝑝𝑂𝑓𝑓𝑠𝑒𝑡/𝑆𝑃𝐴𝐶𝐼𝑁𝐺 )

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 20, 2020, 7:09pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/9 "2020-10-20T19:09:38Z")

</div>

> [@mengtong](#):
>
> Thank you very much. I will try it .

It’s more complicate than I thought it would be.

I guess you need a separate function where you read the key and one function, where you do the movement. Then you can skip the key function when a movement is still happening:

```auto
if(isMoving)
    return;

```

> [@mengtong](#):
>
> how to add Z coordinate, to make this jump looks like a real jump.

I already showed you a way with a curved way for the movement using curvePoints.

A example in 3D, where you need another size() command

There is a nice tutorial about P3D

```auto

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;

float t;

void setup() {

  size(500, 500, P3D);
}

void draw() {
  background(#24B41D);
  strokeWeight(6);
  stroke(#FC8412);
  lights(); 

  drawHand();
  moveHand();
  drawDots();
  drawFly();
  jumping();

  fly1 () ;
}

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);
  ellipse(flyX, flyY, FLY_SIZE, 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);

      //
      fly1();
    } 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);
        }
}

void fly1 () {

  noFill();
  // curve(5, 26, 5, 26, 73, 24, 73, 61);
  // curve(5, 26, 73, 24, 73, 61, 15, 65);
  stroke(255, 0, 0); 
  float height1 = -2220; 
  curve(
    width/2+310, height/2+BETWEEN_DOTS/2, height1, // control 1
    width/2+BETWEEN_DOTS/2, height/2-BETWEEN_DOTS/2, 0, // real point 1
    width/2+BETWEEN_DOTS/2, height/2+BETWEEN_DOTS/2, 0, // real point 2
    width/2+310, height/2+BETWEEN_DOTS/2, height1 // control 2
    );  

  fill(255);
  ellipseMode(CENTER);

  float x;// 
  float y;// 
  float z;

  x = curvePoint( width/2+310, width/2+BETWEEN_DOTS/2, width/2+BETWEEN_DOTS/2, width/2+310, t);
  y = curvePoint( height/2-BETWEEN_DOTS/2, height/2-BETWEEN_DOTS/2, height/2+BETWEEN_DOTS/2, height/2+BETWEEN_DOTS/2, t);
  z = curvePoint( height1, 0, 0, height1, t);

  pushMatrix(); 
  translate( x, y, z);
  noStroke(); 
  sphere (12); 
  popMatrix();

  t+=0.01;
  if (t>=1) 
    t=0.0;
}

```

Chrisir

---

<div class="post-metadata">

**Author:** ![mengtong](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mengtong](https://discourse.processing.org/u/mengtong)\
**Post date:** [October 20, 2020, 11:38pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/10 "2020-10-20T23:38:21Z")

</div>

For the isMoving, could you give me some advice on this? I have been puzzled by this question since I asked it before.I have already tried almost 2 days on this.Now I have created a Boolean isMoving=false, but I really don’t know how to use it. Can you write a simple code to explain it? You don’t need to use my code.For example, draw a circle and make it move left and RIGHT. When it is moving left, if I press RIGHT button, it won’t work.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 21, 2020, 1:16pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/11 "2020-10-21T13:16:12Z")

</div>

**Remark 1**

width and height don’t work before the size command in setup

so these

```auto
  flyX=width/2-BETWEEN_DOTS/2;
  flyY=height/2-BETWEEN_DOTS/2;

```

must be **in setup** after size.

(you had it before setup, so no use. That’s why the code lines didn’t work and the player didn’t appear at the start)

Before setup() only have this:

```auto
int flyX;
int flyY;

```

**Remark 2**

```auto
if (keyCode==RIGHT&&flyX>=width/2-BETWEEN_DOTS/2) {
   flyX=flyX+jumpSpeed;
   flyX=min(flyX, width/2+BETWEEN_DOTS/2);

```

You are going right here and flyX gets bigger, so this `flyX>=width/2-BETWEEN_DOTS/2` is wrong,  
we must have `flyX<=width/2+BETWEEN_DOTS/2` (so with \<= AND with `+` instead of `-`)

(It worked only because you had an (otherwise unnecessary) ` flyX=min(flyX, width/2+BETWEEN_DOTS/2);` here.)

This is often the case in the other 3 code blocks!

**My example**

I repaired it so that the cursor key _right and left_ work and that **isMoving is used**.

You can go left and right now with the player, but you can’t press DOWN in-between. That’s because of `isMoving`.

You have to repair DOWN and UP.

Chrisir

```auto

// Clock 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;
int flyY;
final int jumpSpeed=4;

boolean isMoving=false; // prevent new key from executing during the player moves !!!!!!!!!!!!!!!!!!!!!!!! 
int keyIndicator = -1; // store the key

// ------------------------------------------------------------------------

void setup() {
  size(500, 500);

  flyX=width/2-BETWEEN_DOTS/2;
  flyY=height/2-BETWEEN_DOTS/2;
}

void draw() {
  background(#24B41D);
  strokeWeight(6);
  stroke(#FC8412);

  drawHand();
  moveHand();
  drawDots();
  drawFly();
  jumping();

  // ????? debug 
  if (key==' ')
    isMoving=false;//reset
}

// ------------------------------------------------------------------------

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);
  ellipse(flyX, flyY, 
    FLY_SIZE, FLY_SIZE);
}

void keyPressed() {
  if (isMoving) // when it's true 
    return; // leave !!!!!!

  // when these lines are excuted, isMoving is false!!!!!

  // when we are NOT moving, check the key
  if (keyCode==UP) 
    keyIndicator = 0; 
  else if (keyCode==DOWN)
    keyIndicator = 1;
  else if (keyCode==LEFT)
    keyIndicator = 2;
  else if (keyCode==RIGHT) 
    keyIndicator = 3;
  else return; // leave

  // we set it to true
  isMoving=true;
}

void jumping() {
  if (! isMoving) // when it's false (The ! sign means NOT)  
    return; // leave !!!!!!

  if (keyIndicator==0) { 
    if (flyY<=height/2+BETWEEN_DOTS/2) {
      flyY=flyY-jumpSpeed;
      // flyY=max(flyY, height/2-BETWEEN_DOTS/2);
    } else {
      // movement has ended, so movement is allowed again, set isMoving to false
      isMoving=false;
    }
  } else if (keyIndicator==1) {
    if (flyY>=height/2-BETWEEN_DOTS/2) {
      flyY=flyY+jumpSpeed;
      // flyY=min(height/2+BETWEEN_DOTS/2, flyY);
    } else {
      // movement has ended, so movement is allowed again, set isMoving to false
      isMoving=false;
    }
  } else if (keyIndicator==2) {
    // LEFT 
    if (flyX>=width/2-BETWEEN_DOTS/2) {
      flyX=flyX-jumpSpeed; // decrease 
      //flyX=max(flyX, width/2-BETWEEN_DOTS/2);
    } else {
      // movement has ended, so movement is allowed again, set isMoving to false 
      isMoving=false;
    }
  } else if (keyIndicator==3) {
    // RIGHT 
    if (flyX<=width/2+BETWEEN_DOTS/2) {
      flyX=flyX+jumpSpeed; // increase
      //flyX=min(flyX, width/2+BETWEEN_DOTS/2);
    } else { 
      // movement has ended, so movement is allowed again, set isMoving to false
      isMoving=false;
    }
  }// if
  //
}//func 
//

```

---

<div class="post-metadata">

**Author:** ![mengtong](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mengtong](https://discourse.processing.org/u/mengtong)\
**Post date:** [October 21, 2020, 2:55pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/12 "2020-10-21T14:55:25Z")

</div>

Thank you very much. This helps me a lot. I will try to finish it. Thanks again.

---

<div class="post-metadata">

**Author:** ![mengtong](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mengtong](https://discourse.processing.org/u/mengtong)\
**Post date:** [October 24, 2020, 2:05am UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/13 "2020-10-24T02:05:33Z")

</div>

Can I ask you one more question? Now I finish everything, and I want to calculate when I press the keycode, the number of jumping will add one. But I dont know how to add only one if I only press keycode one time.My code is:  
void printScore() {  
textSize(height/20);  
fill(0);  
String message = "Number of jumps: " + numJumps;  
text(message, (width-textWidth(message))/2, textAscent()+10);  
if (keyCode == UP||keyCode == DOWN||keyCode == RIGHT||keyCode == LEFT) {  
numJumps++;  
}  
}

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 25, 2020, 6:45pm UTC](https://discourse.processing.org/t/hello-i-am-just-a-beginner-i-want-to-know-how-to-complete-a-jump/24754/14 "2020-10-25T18:45:49Z")

</div>

> [@mengtong](#):
>
> void printScore() {

I like your function.

But you can also leave this part out of it:

> [@mengtong](#):
>
> if (keyCode == UP||keyCode == DOWN||keyCode == RIGHT||keyCode == LEFT) {  
> numJumps++;  
> }

Instead say numJumps++;

somewhere else in your code.

Where’s best?
