My teacher recommend me some code but i can't quite understand it here it is
That's form the player class.
private void Grounds()
{
if (world.isGround(getX(), getY()+16))
{ yspeed = 0;
canjump = true; }// to check if standing on the color black
if (world.isGround(getX(), getY()+14) )
{ y -= 1;}//
if (world.isGround(getX(), getY()-14) )
{ y += 1;
if (yspeed < 0){yspeed = 0;}
}//to check if under color black
if (world.isGround(getX()+14, getY()) )
{ x -= 1;
if (xspeed > 0) {xspeed = 0;}
}// to check if trying to run into color black from the right side
if (world.isGround(getX()-14, getY()) )
{ x += 1;
if (xspeed < 0) {xspeed = 0;}
}// to check if trying to run into color black from left side
}private void setColors()
{
groundColor = codes.getColorAt(1,1);
AIColor=codes.getColorAt(22,1);
spikeColor = codes.getColorAt(57,1);
}
public boolean isGround(Color mg)
{
if (groundColor.equals(mg))
{return true;}
return false;
}
public boolean isGround(int x, int y)
{
if (x > swidth-1 || x < 0 || y > sheight-1 || y < 0) {return false;}
Color ez = bgmask.getColorAt(x,y);
if (groundColor.equals(ez))
{return true;}
return false;
}
public boolean isPatrol(int x, int y)
{
if (x > swidth-1 || x < 0 || y > sheight-1 || y < 0) {return false;}
Color ez = bgmask.getColorAt(x,y);
if (AIColor.equals(ez))
{return true;}
return false;
}
public boolean isSpike(int x, int y)
{
if (x > swidth-1 || x < 0 || y > sheight-1 || y < 0) {return false;}
Color ez = bgmask.getColorAt(x,y);
if (spikeColor.equals(ez))
{return true;}
return false;
}
static public void paintBg(int x, int y)
{
background.setColorAt(x,y, Color.RED);
background.setColor(Color.RED);
background.fillRect(x,y, 10,10);
}