# Help with my own Game

**URL:** <https://discourse.processing.org/t/help-with-my-own-game/26320>\
**Category:** Processing for Android\
**Created:** [December 16, 2020, 10:55pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320 "2020-12-16T22:55:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [December 16, 2020, 10:55pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/1 "2020-12-16T22:55:58Z")

</div>

How can i fix it?

Code:

```auto
float xg;
float rx = 500;
float ry = 1300;
float rw = 100;
float rh = 100;
float linksX = 100;
float linksY = 1300;
float linksW = 100;
float linksH = 100;
void setup() {
  xg = 325;
  orientation(PORTRAIT);
  fullScreen();
  background(0);
  stroke(0);
  noFill();
}
void draw() {
  fill(#FFFFFF);
  rect(xg, 1200, 50, 50, 2);
  rect(rx, ry, rw, rh, 5);
  rect(linksX, linksY, linksW, linksH, 5);
  fill(255);
  
  if (mousePressed) {
    if (mouseX>rx && mouseX <rx+rw && mouseY>ry && mouseY <ry+rh) {
      if(xg < 650) {
         xg = xg + 3;
      }
    }
    if (mouseX>linksX && mouseX <linksX+linksW && mouseY>linksY && mouseY <linksY+linksH) {
      if (xg > 5) {
          xg = xg - 3;
      }
    }
  }
}

```

 ![Screenshot_20201216-235255_APDE Sketch Preview](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8681e31a8e2d9fb7983fe9e5b93049d4662fd089.jpeg)

---

<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:** [December 16, 2020, 10:57pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/2 "2020-12-16T22:57:49Z")

</div>

Can you please describe what happens falsely now and what you want to happen instead?

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [December 16, 2020, 11:47pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/3 "2020-12-16T23:47:04Z")

</div>

Look my Screenshot 😂

I Like only a rect

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 17, 2020, 7:56am UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/4 "2020-12-17T07:56:19Z")

</div>

it’s difficult to find out what’s wrong. If you tell us what you tried to do and what will be the game we could help you by either showing you the issue or resolving it by changing the code.

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [December 17, 2020, 12:51pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/5 "2020-12-17T12:51:40Z")

</div>

I want to do a 2D jump and run game I need: run right & left and a jump

```auto
float spieler_x;
float spieler_y = 200;
float rx = 200;
float ry = 500;
float rw = 100;
float rh = 100;
float linksX = 50;
float linksY = 500;
float linksW = 100;
float linksH = 100;
float jumpX = 1250;
float jumpY = 500;
float jumpW = 100;
float jumpH = 100;
void setup() {
  orientation(LANDSCAPE);
  background(0);
  stroke(0);
  noFill();
}
void draw() {
  fill(#FFFFFF);
  rect(spieler_x, spieler_y, 50, 50, 2);
  rect(rx, ry, rw, rh, 5);
  rect(jumpX, jumpY, jumpW, jumpH, 5);
  rect(linksX, linksY, linksW, linksH, 5);
  fill(255);
  if (mousePressed) {
    if(mouseX>rx && mouseX <rx+rw && mouseY>ry && mouseY <ry+rh) {
      fill(#818181);
      rect(rx, ry, rw, rh, 5);
        if (spieler_x < 1400) {
          spieler_x++;
      }
    }
    if (mouseX>linksX && mouseX <linksX+linksW && mouseY>linksY && mouseY <linksY+linksH) {
      fill(#818181);
      rect(linksX, linksY, linksW, linksH, 5);
      if (spieler_x > 5) {
        spieler_x--;
      }
    }
    if(mouseX>jumpX && mouseX <jumpX+jumpW && mouseY>jumpY && mouseY <jumpY+jumpH) {
      fill(#818181);
      rect(jumpX, jumpY, jumpW, jumpH, 5);
      redraw();
      spieler_y--;
    }
  }
  fullScreen();
}

```

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 17, 2020, 12:53pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/6 "2020-12-17T12:53:25Z")

</div>

so a 2D platformer? Its the name for what you are describing

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [December 17, 2020, 12:56pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/7 "2020-12-17T12:56:48Z")

</div>

Yes sorry my english is so Bad 😕

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 17, 2020, 12:58pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/8 "2020-12-17T12:58:51Z")

</div>

no problem. Mine used to be bad too. Well, I continued learning it and here I am with an ok understanding of it.

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [December 17, 2020, 1:00pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/9 "2020-12-17T13:00:19Z")

</div>

Can you Help me? Please😂

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 17, 2020, 1:21pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/10 "2020-12-17T13:21:00Z")

</div>

I’ll try : P I’ll share my progress and feel free to take over : )

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 17, 2020, 1:33pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/11 "2020-12-17T13:33:14Z")

</div>

Maybe you could try box2D its a library meant for that (2D physics). I’ll try to make it in normal processing for now

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 17, 2020, 1:47pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/12 "2020-12-17T13:47:19Z")

</div>

my progress:

```auto
float x=300,y=100,w=50,h=50, xs = 0, ys = 0, g = 0.5, speed = 0.5, friction = 0.9;
float ox1 = 200, oy1 = 500, ow1 = 200, oh1 = 20;

void setup() {
  size(600,600);
}

void draw() {
  background(0);
  rect(x,y,w,h);
  rect(ox1,oy1,ow1,oh1);
  
  ys += g;
  y += ys;
  xs *= friction;
  x += xs;
  if(y + h > oy1) {
    ys = 0;
    y = oy1 - h;
  }
  
  if(keyPressed) {
    if(key == 'w') {
      if(ys == 0) {
        ys -= 10;
      }
    }
    if(key == 'a') {
      xs -= speed;
    }
    if(key == 'd') {
      xs += speed;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [December 17, 2020, 1:53pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/13 "2020-12-17T13:53:23Z")

</div>

I programming for Android

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 17, 2020, 2:06pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/14 "2020-12-17T14:06:40Z")

</div>

I know but as I said before I suck at it : P

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [December 18, 2020, 12:19pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/15 "2020-12-18T12:19:50Z")

</div>

@noel can you Help me?

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 18, 2020, 4:53pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/16 "2020-12-18T16:53:31Z")

</div>

I’ve adapted @CodeMasterX’s code a bit. As you can see I take every point/measurement in relation to width and height. That is necessary for Android because you want to use fullscreen, and there exist an enormous variety of screen sizes. This code has a fixed canvas size and you need to change it. The idea is to use three fingers to steer. The ring finger for moving to the right, the index finger for moving to the left, and the middle finger to jump by tapping above the buttons. To jump and move simuataniously you need the Android’s buildin touches array. But the sketch is too small on my phone to test it. So change it to fullscreen and we’ll see.

```auto
float x = 300, y = 100, w = 50, h = 50, xs = 0; 
float ys = 0, g = 0.5, speed = 0.5, ox1 = 200; 
float oy1 = 500, ow1 = 200, oh1 = 20, friction = 0.97; 
int cv; 
boolean jump = true; 

void setup() { 
  size(600, 600); 
  textSize(30); 
  cv = height-height/12; 
  fill(0, 220, 220); 
  rect(0, cv, width, height/12); 
  fill(0); 
  line(width/2, cv, width/2, height); 
  fill(100); 
  textSize(20); 
  text("Left", width/5, height- height/30); 
  text("Right", 11*width/16, height-height/30);
} 

void draw() { 
  fill(0); 
  rect(0, 0, width, cv); 
  fill(255); 
  rect(x, y, w, h); 
  rect(ox1, oy1, ow1, oh1); 
  if (jump) { 
    ys += g; 
    y += ys; 
    xs *= friction; 
    x += xs; 
    if (y+h > oy1) { 
      ys = 0; 
      y = oy1-h; 
      jump = false;
    }
  } 
  if (mousePressed) { 
    if (mouseY > cv) { 
      if (mouseX > width/2) x += 5; 
      if (mouseX < width/2) x -= 5;
    } else { 
      jump = true; 
      if (ys == 0) { 
        ys -= 10;
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [December 19, 2020, 2:28pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/17 "2020-12-19T14:28:11Z")

</div>

I need to create this

 ![Screenshot_20201219-152628_DinoScape](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/384ed128f405aefff150055be3730a0475e1dcba.jpeg)

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 19, 2020, 2:48pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/18 "2020-12-19T14:48:55Z")

</div>

As the image is a landscape use that orientation. You’ll have to take the image to GIMP or similar and cut out the dinosaur-rider and save it as a transparent png image. Then correct the hole in the background image with appropriate colors. Load the image into the sketch and use it in the background. You need to search the button positions relative to width and height. (To make it work on every phone) Post it here (!!formatted in a code-block!!), then I’ll help you further.  
Edit: Where is the jump button? Or has it to jump when you shake your phone?

---

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [December 19, 2020, 7:46pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/19 "2020-12-19T19:46:29Z")

</div>

I have so far…

```auto
float spieler_x;
float spieler_y = 200;
float rx = 200;
float ry = 500;
float rw = 100;
float rh = 100;
float linksX = 50;
float linksY = 500;
float linksW = 100;
float linksH = 100;
float jumpX = 1250;
float jumpY = 500;
float jumpW = 100;
float jumpH = 100;
void setup() {
  orientation(LANDSCAPE);
  background(0);
  stroke(0);
  noFill();
}
void draw() {
  fill(#FFFFFF);
  rect(spieler_x, spieler_y, 50, 50, 2);
  rect(rx, ry, rw, rh, 5);
  rect(jumpX, jumpY, jumpW, jumpH, 5);
  rect(linksX, linksY, linksW, linksH, 5);
  fill(255);
  if (mousePressed) {
    if(mouseX>rx && mouseX <rx+rw && mouseY>ry && mouseY <ry+rh) {
      fill(#818181);
      rect(rx, ry, rw, rh, 5);
        if (spieler_x < 1400) {
          spieler_x++;
      }
    }
    if (mouseX>linksX && mouseX <linksX+linksW && mouseY>linksY && mouseY <linksY+linksH) {
      fill(#818181);
      rect(linksX, linksY, linksW, linksH, 5);
      if (spieler_x > 5) {
        spieler_x--;
      }
    }
    if(mouseX>jumpX && mouseX <jumpX+jumpW && mouseY>jumpY && mouseY <jumpY+jumpH) {
      fill(#818181);
      rect(jumpX, jumpY, jumpW, jumpH, 5);
      redraw();
      spieler_y--;
    }
  }
  fullScreen();
}

```

now do i have to adjust it to the cell phone size?

Edit: the player is still a little too slow for me and the jump is a little flawed

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 19, 2020, 7:57pm UTC](https://discourse.processing.org/t/help-with-my-own-game/26320/20 "2020-12-19T19:57:36Z")

</div>

> [@Rogo](#):
>
> do i have to adjust it to the cell phone size

Yes for example instead of writing rx = 200; you write something like rx = width/4;  
Then if it works on your phone screen resolution, it will also work on other sizes.

[Next page](https://discourse.processing.org/t/help-with-my-own-game/26320.md?page=2)
