# Help with character spawning

**URL:** <https://discourse.processing.org/t/help-with-character-spawning/6687>\
**Category:** Coding Questions\
**Created:** [December 17, 2018, 3:28am UTC](https://discourse.processing.org/t/help-with-character-spawning/6687 "2018-12-17T03:28:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarvis](https://avatars.discourse-cdn.com/v4/letter/t/ecccb3/32.png) [@Tarvis](https://discourse.processing.org/u/Tarvis)\
**Post date:** [December 17, 2018, 3:28am UTC](https://discourse.processing.org/t/help-with-character-spawning/6687/1 "2018-12-17T03:28:26Z")

</div>

I haven’t been programming in processing or java that long, but I am trying to make a game where and enemy spawns at random inter volts, but my enemy program isn’t working. Any help? Thank you

```auto
//var setup
int high = 2;
int enemyX = 850;

//setting it up
void setup() {
  background(150);
  size(1280, 800);
  line(0, 260, 1280, 260);
  line(0, 530, 1280, 530);
}

//Changing the variable for player height
public void keyPressed(KeyEvent e) {
  if (e.getKeyCode() == 38 && !(high == 3)) {
    high = high + 1;
  } else if (e.getKeyCode() == 40 && !(high == 1)) {
    high = high - 1;
  }
}

//Player Drawing
void draw() {
  if (high == 2) {
    background(150);
    line(0, 260, 1280, 260);
    line(0, 530, 1280, 530);
    rectMode(CENTER);
    rect(300, 395, 250, 250);
  } else if (high == 1) {
    background(150);
    line(0, 260, 1280, 260);
    line(0, 530, 1280, 530);
    rectMode(CENTER);
    rect(300, 665, 250, 250); 
  } else if (high == 3) {
    background(150);
    line(0, 260, 1280, 260);
    line(0, 530, 1280, 530);
    rectMode(CENTER);
    rect(300, 130, 250, 250);
  }
  
  if (enemyX <= 0) {
    rectMode(CENTER);
    rect(enemyX,665,250,250);
    enemyX = enemyX - 5;
  }
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 17, 2018, 6:08am UTC](https://discourse.processing.org/t/help-with-character-spawning/6687/2 "2018-12-17T06:08:11Z")

</div>

hi,  
looks like you are fighting with translating from p5.js?

as i not understand what you want to do i can not fix your ?game?  
but just as a example i want show you a different coding style,  
if you think it is more readable and like it, use it.

```auto
int high = 2, enemyX = 800, rposY = 400, rw = 250;

// __________________________________________
void setup() {
 size(1280, 800);
 rectMode(CENTER);
}

// __________________________________________ //Player Drawing
void draw() {
 background(150);
 line(0, 260, width, 260);
 line(0, 530, width, 530);  
 if (high == 1) rposY = 665;
 if (high == 2) rposY = 395;
 if (high == 3) rposY = 130;
 rect(enemyX, rposY, rw, rw);
 enemyX = enemyX - 5;
 if (enemyX <= 0) enemyX = width-rw/2;
}

// __________________________________________ //Changing the variable for player height
void keyPressed() {
 if (keyCode == UP && !(high == 3)) high += 1;
 if (keyCode == DOWN && !(high == 1)) high -= 1;
}

```
