# Hi can anyone help me with my game?

**URL:** <https://discourse.processing.org/t/hi-can-anyone-help-me-with-my-game/19162>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [March 30, 2020, 12:30am UTC](https://discourse.processing.org/t/hi-can-anyone-help-me-with-my-game/19162 "2020-03-30T00:30:49Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex21brom](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@alex21brom](https://discourse.processing.org/u/alex21brom)\
**Post date:** [March 30, 2020, 12:30am UTC](https://discourse.processing.org/t/hi-can-anyone-help-me-with-my-game/19162/1 "2020-03-30T00:30:49Z")

</div>

i am trying to make this image appear at random heights continuously

class Chaser {  
int x;  
int y;  
float ran;  
int rani;  
PImage carimageY, carimageN, carimageW;

Chaser()  
{  
x = Lane();  
y = height-50;  
carimageY=loadImage(“data/car1.png”);  
carimageY.resize(80, 80);

}

void render()  
{  
image(carimageY, x, y);  
}

boolean collided(){  
return false;  
}

int Lane() {  
int[] lanes = {-26,22,52,92,124,172,200,236,275,325,362,400,430,470,500,540,574,616,650,690};  
ran =random(18);  
rani = round(ran);

```
return lanes[rani];

```

}

void move(){  
y=y-3;  
}

void collide()  
{  
if(y\<0){  
y = height-200;  
x=Lane();  
}  
if(collided()==true){  
x=Lane();  
}  
}

void update()  
{  
move();  
collide();  
render();  
}  
}

---

<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:** [March 30, 2020, 7:25am UTC](https://discourse.processing.org/t/hi-can-anyone-help-me-with-my-game/19162/2 "2020-03-30T07:25:33Z")

</div>

Hello,

and welcome to the community!

Great to have you here!

> [@alex21brom](#):
>
> i am trying to make this image appear at random heights continuously

```auto
void collide()
{
if(y<0){
y = height + random(200); // that makes the car reappear below the screen
x=Lane();
}

```

Chrisir

---

<div class="post-metadata">

**Author:** ![alex21brom](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@alex21brom](https://discourse.processing.org/u/alex21brom)\
**Post date:** [April 2, 2020, 1:40pm UTC](https://discourse.processing.org/t/hi-can-anyone-help-me-with-my-game/19162/3 "2020-04-02T13:40:04Z")

</div>

Thanks. I entered the code but I’m getting an error

---

<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:** [April 2, 2020, 1:41pm UTC](https://discourse.processing.org/t/hi-can-anyone-help-me-with-my-game/19162/4 "2020-04-02T13:41:04Z")

</div>

show your entire code and describe your error.

what does it say and line number?

---

<div class="post-metadata">

**Author:** ![alex21brom](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@alex21brom](https://discourse.processing.org/u/alex21brom)\
**Post date:** [April 2, 2020, 1:42pm UTC](https://discourse.processing.org/t/hi-can-anyone-help-me-with-my-game/19162/5 "2020-04-02T13:42:50Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/5340334a09e8f4f6e677681617b43ed9e66ee701.jpeg)

Here is a pic of the error I’m getting

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 2, 2020, 1:43pm UTC](https://discourse.processing.org/t/hi-can-anyone-help-me-with-my-game/19162/6 "2020-04-02T13:43:24Z")

</div>

Hello,

Please format your code as a courtesy to everyone:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

---

<div class="post-metadata">

**Author:** ![alex21brom](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@alex21brom](https://discourse.processing.org/u/alex21brom)\
**Post date:** [April 2, 2020, 1:49pm UTC](https://discourse.processing.org/t/hi-can-anyone-help-me-with-my-game/19162/7 "2020-04-02T13:49:20Z")

</div>

```auto
class Chaser {
  int x;
  int y;
  float ran;
  int rani;
  PImage carimageY, carimageN, carimageW;

  Chaser()
  {
    x = Lane();
    y = height-50;    
    carimageY=loadImage("data/car1.png");
    carimageY.resize(80, 80);
  }

  void render()
  {
    image(carimageY, x, y);
  }

  boolean collided() {
    return false;
  }

  int Lane() {
    int[] lanes = {-26, 22, 52, 92, 124, 172, 200, 236, 275, 325, 362, 400, 430, 470, 500, 540, 574, 616, 650, 690};
    ran =random(18);
    rani = round(ran);

    return lanes[rani];
  }

  void move() {
    y=y-3;
  }

  void collide()
  {
    if (y<0) {
      y = height + random (200);
      x=Lane();
    }
    if (collided()==true) {
      x=Lane();
    }
  }

  void update()
  {
    move();
    collide();
    render();
  }
}

```

---

<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:** [April 2, 2020, 1:50pm UTC](https://discourse.processing.org/t/hi-can-anyone-help-me-with-my-game/19162/8 "2020-04-02T13:50:57Z")

</div>

> [@alex21brom](#):
>
> y = height + random (200);

```auto
  y = int(height + random (200));

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 2, 2020, 2:01pm UTC](https://discourse.processing.org/t/hi-can-anyone-help-me-with-my-game/19162/9 "2020-04-02T14:01:09Z")

</div>

Hello,

If you hover over a red error or orange warning it will show the error in the bar below code (above console).

You can set preferences in the Processing PDE for errors and warnings and lots of other stuff:  
file \> preferences \>

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/042168eb35f8a04a9a0fe1a3fb2937c0878e835f.png)

In this case:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4b03247fa5d1a0ee0d747a36d20ae972561da51f.png)

This is a reference to help you resolve this:  
[https://processing.org/reference/intconvert\_.html](https://processing.org/reference/intconvert_.html)

`:)`

---

<div class="post-metadata">

**Author:** ![alex21brom](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@alex21brom](https://discourse.processing.org/u/alex21brom)\
**Post date:** [April 2, 2020, 2:01pm UTC](https://discourse.processing.org/t/hi-can-anyone-help-me-with-my-game/19162/10 "2020-04-02T14:01:49Z")

</div>

Thanks the code works now but the cars still doing the same thing only three rows of cars are appearing. I would like for the cars to appear on the screen until the game is stopped. I called the two other rows using an extended class but i don’t want to have to keep extending the class to get new rows of cars.

---

<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:** [April 2, 2020, 2:52pm UTC](https://discourse.processing.org/t/hi-can-anyone-help-me-with-my-game/19162/11 "2020-04-02T14:52:06Z")

</div>

to get help, post an entire, runnable code
