# How to move obstacles?

**URL:** https://discourse.processing.org/t/how-to-move-obstacles/18944
**Category:** Coding Questions
**Created:** [March 23, 2020, 6:54pm UTC](https://discourse.processing.org/t/how-to-move-obstacles/18944 "2020-03-23T18:54:03Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![NotConsumable](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@NotConsumable](https://discourse.processing.org/u/NotConsumable)
#### Post date: [March 23, 2020, 6:54pm UTC](https://discourse.processing.org/t/how-to-move-obstacles/18944/1 "2020-03-23T18:54:03Z")

</div>

So I am trying to make a frogger game and I have everything doing what I need it to do, but my hazards wont move and everything i try to do does not work? I have no idea how to make them move and how to add another row after advancing in each level? Here is my entire code i’m sorry if its super messy

```auto
float frogX;
int level = 1;
float frogY;
float frogSize;
//creating the band sized
float bandHeight;
float BANDWIDTH;
float bottomBand_y;
float edge; 
float radius;
float inner;
float offset;
float x0;
float x1;
float x2;
float middleBand_y;

//final ints and floats
final int BAND_X = 0;
final int TOPBAND_Y = 0;
final float SPEED = 0.75;

//setup of the program
void setup()
{
  fullScreen();
  bandHeight = height/(level+4);
  BANDWIDTH = width;
  frogX = width/2;
  frogY = height-bandHeight/2;
  frogSize = bandHeight/2;
  radius = frogSize/100;
  edge = frogSize;
  inner = edge+radius;

}

//initial draw for the program
void draw()
{
  drawWorld();
  drawFrog(frogX,frogY,frogSize);
  drawHazards();
 
  displayMessage("level"+str(level));
 
}
void drawWorld()
{
  for (int i=1;i<level+3;i++)
  {
    fill(0,0,255);
    stroke(0,0,255);
    rect(BAND_X,middleBand_y,BANDWIDTH,bandHeight);
    middleBand_y = bandHeight*i;
    if (detectWin())
    {
      level++;
      frogY = height-bandHeight/2;
      frogX = width/2;
    }
  }
  fill(139,100,40);
  stroke(0);
  rect(BAND_X,TOPBAND_Y,BANDWIDTH,bandHeight);
  rect(BAND_X,bottomBand_y,BANDWIDTH,bandHeight);
  bottomBand_y = height-bandHeight;
}

//draw frog paramiters
void drawFrog(float x, float y, float diam)
{
  fill(0,255,50);
  ellipse(x,y,diam,diam);
  
  
}

//move frog peramiters
void moveFrog(float xChange, float yChange)
{
  if (objectInCanvas(frogX, frogY, frogSize))
    {
      frogX = frogX+xChange;
      frogY = frogY+yChange;
      frogX = constrain(frogX,inner,width-inner);
      frogY = constrain(frogY,inner,height-inner);
    }
}

//peramiters on how to move the frog 
void keyPressed()
{
  if ( key == 'w')
  moveFrog(0,-bandHeight);
  if ( key == 's')
  moveFrog(0,bandHeight);
  if ( key == 'a')
  moveFrog(-bandHeight,0);
  if ( key == 'd')
  moveFrog(bandHeight,0);
  if ( key == 'i')
  moveFrog(0,-bandHeight);
  if ( key == 'k')
  moveFrog(0,bandHeight);
  if ( key == 'j')
  moveFrog(-bandHeight,0);
  if ( key == 'l')
  moveFrog(bandHeight,0);
}
boolean objectInCanvas(float x, float y, float diam)
{
  boolean InCanvas = true;
  if ( x < 0 || x > width || y < 0 || y > height || diam < 0)
  InCanvas = false;
  return InCanvas;
}

//drawing hazard peramiters
void drawHazards()
{
  
  for (int j=0;j<width;j++)
  {
    for (float i=0;i<level+2;i++)
    {
      float y0 = (height-bandHeight*1.5)-i*(bandHeight*3);
      if (y0 < bandHeight)
        {
          y0 = height-bandHeight*1.5;
        }
      float y1 = (height-bandHeight*2.8)-i*(bandHeight*3);
      if (y1 < bandHeight)
        {
          y1 = height-bandHeight*2.8;
        }
      float y2 = (height-bandHeight*3.5)-i*(bandHeight*3);
      if (y2 < bandHeight)
        {
          y2 = height-bandHeight*3.5;
        }
         x0 = j*(bandHeight*3);
         x1 = j*(bandHeight*4)-((bandHeight-50)/2);
         x2 = j*(bandHeight*5);
      drawHazard(0,x0,y0,bandHeight/1.5);
      drawHazard(1,x1,y1,bandHeight/1.5);
      drawHazard(2,x2,y2,bandHeight/1.5);
   
    }
   
  }  
  
}

//hazard draw peramiters
void drawHazard(int type, float x, float y, float size)
{
  if (type == 0)
  {
    fill(255,0,0);
    ellipse(x,y,size,size);
   
  }
  if (type == 1)
  {
    fill(0);
    rect(x,y,size,size);
  }
  if (type == 2)
  {
    fill(255);
    ellipse(x,y,size,size);
   
  }
}

//displaying the level selector peramiters
void displayMessage(String l)
{
  
  textSize(bandHeight/2);
  text(l,width/2.4,bandHeight/1.5);
  if (detectWin())
  {
    
    frogY = height-bandHeight/2;
  
  }
  
}
//return frog when reaching end of the level to advance to the next level
boolean detectWin()
{
  boolean win=false;
  if (frogY < bandHeight)
  {
    win=true;
   
  
  }
  return win;
}

```

---

<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 23, 2020, 7:55pm UTC](https://discourse.processing.org/t/how-to-move-obstacles/18944/2 "2020-03-23T19:55:17Z")

</div>

Welcome to the forum! When you post, please help us help you by [formatting your code](https://discourse.processing.org/faq#format-your-code) with the \</\> button or by putting ``` above and below your code.

---

<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 23, 2020, 7:58pm UTC](https://discourse.processing.org/t/how-to-move-obstacles/18944/4 "2020-03-23T19:58:33Z")

</div>

Please go back, edit your post

The code should be in **one** box, not 6…

😉

---

<div class="post-metadata">

### Author: ![NotConsumable](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@NotConsumable](https://discourse.processing.org/u/NotConsumable)
#### Post date: [March 23, 2020, 8:03pm UTC](https://discourse.processing.org/t/how-to-move-obstacles/18944/5 "2020-03-23T20:03:05Z")

</div>

i think that fixed it haha

---

<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 23, 2020, 8:06pm UTC](https://discourse.processing.org/t/how-to-move-obstacles/18944/6 "2020-03-23T20:06:05Z")

</div>

No, not really

please look at it again

edit the post

select ENTIRE code section with mouse

click `</>` in the command bar

---

<div class="post-metadata">

### Author: ![NotConsumable](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@NotConsumable](https://discourse.processing.org/u/NotConsumable)
#### Post date: [March 23, 2020, 8:09pm UTC](https://discourse.processing.org/t/how-to-move-obstacles/18944/7 "2020-03-23T20:09:15Z")

</div>

i have it all selected in my initial post not in the reply, im confused on what i have wrong there haha

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [April 1, 2020, 3:37pm UTC](https://discourse.processing.org/t/how-to-move-obstacles/18944/8 "2020-04-01T15:37:42Z")

</div>

Okay – I’ve removed the duplicate unformatted posts, and the top post looks good, @NotConsumable – thank you.

> [@NotConsumable](#):
>
> my hazards wont move and everything i try to do does not work?

How do you want them to move? Where in your code are you currently telling them to move – or where should you be telling them to move?
