How to move obstacles?

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

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;
}

Welcome to the forum! When you post, please help us help you by formatting your code with the </> button or by putting ``` above and below your code.

1 Like

Please go back, edit your post

The code should be in one box, not 6…

:wink:

i think that fixed it haha

No, not really

please look at it again

edit the post

select ENTIRE code section with mouse

click </> in the command bar

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

1 Like

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

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?