# Can you Help me dir my Game

**URL:** https://discourse.processing.org/t/can-you-help-me-dir-my-game/23705
**Category:** Processing for Android
**Created:** [September 6, 2020, 8:03am UTC](https://discourse.processing.org/t/can-you-help-me-dir-my-game/23705 "2020-09-06T08:03:12Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Magical](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/magical/32/11068_2.png) [@Magical](https://discourse.processing.org/u/Magical)
#### Post date: [September 6, 2020, 8:03am UTC](https://discourse.processing.org/t/can-you-help-me-dir-my-game/23705/1 "2020-09-06T08:03:12Z")

</div>

```auto
bird b = new bird();
pillar[] p = new pillar[3];
boolean end=false;
boolean intro=true;
int score=0;
void setup() {
  size(displayWidth, displayHeight);
  for (int i = 0; i<3; i++) {
    p[i]=new pillar(i);
  }
}
void draw() {
  background(#101D25);
  if (end) {
    b.move();
  }
  b.drawBird();
  if (end) {
    b.drag();
  }
  b.checkCollisions();
  for (int i = 0; i<3; i++) {
    p[i].drawPillar();
    p[i].checkPosition();
  }
  fill(0);
  stroke(255);
  textSize(32);
  if (end) {
    rect(20, 20, 100, 50);
    fill(255);
    text(score, 30, 58);
  } else {
    rect(150, 100, 200, 50);
    rect(150, 200, 200, 50);
    fill(255);
    if (intro) {
      text("Flappy Code", 155, 140);
      text("Click to Play", 155, 240);
    } else {
      text("game over", 170, 140);
      text("score", 180, 240);
      text(score, 280, 240);
    }
  }
}
class bird {
  float xPos, yPos, ySpeed;
  bird() {
    xPos = 250;
    yPos = 400;
  }
  void drawBird() {
    stroke(255);
    strokeWeight(2);
    ellipse(xPos, yPos, 20, 20);
  }
  void jump() {
    ySpeed=-10;
  }
  void drag() {
    ySpeed+=0.4;
  }
  void move() {
    yPos+=ySpeed; 
    for (int i = 0; i<3; i++) {
      p[i].xPos-=3;
    }
  }
  void checkCollisions() {
    if (yPos>800) {
      end=false;
    }
    for (int i = 0; i<3; i++) {
      if ((xPos<p[i].xPos+10&&xPos>p[i].xPos-10)&&(yPos<p[i].opening-100||yPos>p[i].opening+100)) {
        end=false;
      }
    }
  }
}
class pillar {
  float xPos, opening;
  boolean cashed = false;
  pillar(int i) {
    xPos = 100+(i*200);
    opening = random(600)+100;
  }
  void drawPillar() {
    line(xPos, 0, xPos, opening-100);  
    line(xPos, opening+100, xPos, height);
  }
  void checkPosition() {
    if (xPos<0) {
      xPos+=(200*3);
      opening = random(600)+100;
      cashed=false;
    } 
    if (xPos<250&&cashed==false) {
      cashed=true;
      score++;
    }
  }
}
void reset() {
  end=true;
  score=0;
  b.yPos=400;
  for (int i = 0; i<3; i++) {
    p[i].xPos+=550;
    p[i].cashed = false;
  }
}
void mousePressed() {
  b.jump();
  intro=false;
  if (end==false) {
    reset();
  }
}
void keyPressed() {
  b.jump(); 
  intro=false;
  if (end==false) {
    reset();
  }
}

```

I want to do it with you so that the game automatically adapts to the cell phones, can someone 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: [September 6, 2020, 3:54pm UTC](https://discourse.processing.org/t/can-you-help-me-dir-my-game/23705/2 "2020-09-06T15:54:38Z")

</div>

Hi.  
To get the mode you can try this:

```auto
void setup () {
  size(displayWidth, displayHeight);
  println(getMode());
  println (width+" "+height);
  fill (0);
  textSize(40);
  textAlign(CENTER);
  if (getMode().equals(Mode.java) == true) text("Java mode", width/2, height/2);
  if (getMode().equals(Mode.android) == true) {
    orientation(LANDSCAPE);
    text("Android mode", width/2, height/2);
  }
}

enum Mode {
  java, android
}

Mode getMode() {
  return System.getProperty("java.runtime.name").equals("Android Runtime") ? Mode.android : Mode.java;
}

```

b.t.w Nice game!

---

<div class="post-metadata">

### Author: ![Magical](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/magical/32/11068_2.png) [@Magical](https://discourse.processing.org/u/Magical)
#### Post date: [September 6, 2020, 6:23pm UTC](https://discourse.processing.org/t/can-you-help-me-dir-my-game/23705/3 "2020-09-06T18:23:35Z")

</div>

what exactly does the code do?

---

<div class="post-metadata">

### Author: ![Magical](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/magical/32/11068_2.png) [@Magical](https://discourse.processing.org/u/Magical)
#### Post date: [September 6, 2020, 6:30pm UTC](https://discourse.processing.org/t/can-you-help-me-dir-my-game/23705/4 "2020-09-06T18:30:31Z")

</div>

i have only been programming for 10 weeks😅

---

<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: [September 6, 2020, 8:03pm UTC](https://discourse.processing.org/t/can-you-help-me-dir-my-game/23705/5 "2020-09-06T20:03:07Z")

</div>

Well, my assumption is that you want to run your sketches either on PC and on your android phone as well, with the same code. As you see, the code detect if it is in running on a PC or on a phone. So you can give specific android functions like f.e. orientation(LANDSCAPE);

---

<div class="post-metadata">

### Author: ![Magical](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/magical/32/11068_2.png) [@Magical](https://discourse.processing.org/u/Magical)
#### Post date: [September 6, 2020, 8:15pm UTC](https://discourse.processing.org/t/can-you-help-me-dir-my-game/23705/6 "2020-09-06T20:15:53Z")

</div>

Oh okay cool thanks 🙂

---

<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: [September 6, 2020, 8:24pm UTC](https://discourse.processing.org/t/can-you-help-me-dir-my-game/23705/7 "2020-09-06T20:24:29Z")

</div>

If you are just starting on Android, I recommend you to download the app APDE on Play Store.  
It is the same Processing core adapted to work on an Android phone.  
I also use the app Pigeon. With that you only will type on your PC.

---

<div class="post-metadata">

### Author: ![Magical](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/magical/32/11068_2.png) [@Magical](https://discourse.processing.org/u/Magical)
#### Post date: [September 6, 2020, 8:25pm UTC](https://discourse.processing.org/t/can-you-help-me-dir-my-game/23705/8 "2020-09-06T20:25:56Z")

</div>

My Game is only for Android

---

<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: [September 6, 2020, 8:32pm UTC](https://discourse.processing.org/t/can-you-help-me-dir-my-game/23705/9 "2020-09-06T20:32:11Z")

</div>

So just write orientation(LANDSCAPE); in setup, to avoid rotating, and you are good to go.
