My teacher gave me the solution: The trees are the ones, which should have the bounce method. In that way it works. I made a new “game” where i have walls, and it works how it should. Thank you all for your help and your work.
Girl Mel;
Wall wall1;
Wall wall2;
void setup()
{
size(1200,700,P3D);
Mel=new Girl(0,695,0,0,0);
wall1=new Wall(300,350,500,1000,700,20);
wall2=new Wall(-200,350,-500,20,700,1000);
}
void draw()
{
background(#17BFFA);
pushMatrix();
translate(0,700,0);
fill(#1CB714);
box(5000,10,5000);
popMatrix();
Mel.drawGirl();
Mel.moveGirl();
Mel.cam();
Mel.Gravity();
wall1.drawWall();
wall1.bouncer();
wall2.drawWall();
wall2.bouncer();
}
void keyPressed()
{
Mel.pressedkeysGirl();
}
void keyReleased()
{
Mel.releasedkeysGirl();
}
void mouseMoved()
{
Mel.mouseturn();
}
void mousePressed()
{
}
void mouseReleased()
{
}
float a1=0;
float b1=0;
float c1=0;
float xPos=0;
float yPos=455;
float zPos=0;
float cammeter=0;
float jumpmod=5;
float mouseturnX=0;
float mouseturnY=0;
color colour=#22EA11;
class Girl
{
float camdist;
float floor;
float xCam;
float yCam;
float zCam;
Girl(float cd,float f,float xc,float yc,float zc)
{
camdist=cd;
floor=f;
xCam=xc;
yCam=yc;
zCam=zc;
}
void drawGirl()
{
pushMatrix();
translate(xPos,yPos,zPos);
//if(a1!=0||c1!=0)
//{rotateY(mouseturnX);}//if other figur shall back bounce, then use variables as summands and if the touch the object the variable is -variable
fill(#F5C372);//Face
beginShape();
vertex(10,0,5);
vertex(0,20,0);
vertex(0,-10,0);
endShape();
beginShape();
vertex(-10,0,5);
vertex(0,20,0);
vertex(0,-10,0);
endShape();
fill(colour);//Eyes
beginShape();
vertex(5,0,0);
vertex(7.5,2.5,2.5);
vertex(7.5,-2.5,2.5);
endShape();
beginShape();
vertex(-5,0,0);
vertex(-7.5,2.5,2.5);
vertex(-7.5,-2.5,2.5);
endShape();
popMatrix();
}
void pressedkeysGirl()
{
if(key=='w')
{c1=-5;}
if(key=='s')
{c1=5;}
if(key=='a')
{a1=5;}
if(key=='d')
{a1=-5;}
if(key=='x')
{b1=5;}
if(key=='c')
{cammeter=5;}
}
void releasedkeysGirl()
{
if(key=='w')
{c1=0;}
if(key=='s')
{c1=0;}
if(key=='a')
{a1=0;}
if(key=='d')
{a1=0;}
if(key=='x')
{b1=0;}
if(key=='c')
{cammeter=0;}
}
void mouseturn()
{
if(mouseX<500)
{mouseturnX=(-(-mouseX+500))*0.01;}
if(mouseX>500)
{mouseturnX=(mouseX-500)*0.01;}
if(mouseY<350)
{mouseturnY=-(-mouseY+350)*0.5;}
if(mouseY>350)
{mouseturnY=(mouseY-350)*0.5;}
}
void moveGirl()
{
if(c1<0||c1>0)
{
xPos=(sin(mouseturnX)*c1)+xPos;
zPos=(cos(mouseturnX)*c1)+zPos;
}
if(a1<0||a1>0)
{
xPos=(cos(mouseturnX)*a1)+xPos;
zPos=(sin(mouseturnX)*a1)+zPos;
}
if(b1!=0)
{
yPos=yPos+jumpmod;
if(yPos<floor-500||yPos>floor-225)
{jumpmod=-jumpmod;}
}
}
void cam()
{
xCam=(sin(mouseturnX)*camdist)+xPos;
zCam=(cos(mouseturnX)*camdist)+zPos;
if(cammeter>0)
{
camdist=10;
yCam=yPos;
}
if(cammeter==0)
{
camdist=250;
yCam=yPos+mouseturnY;
}
camera(xCam,yCam,zCam,xPos,yPos,zPos,0,1,0);
}
void Gravity()
{
if(yPos<floor-250)
{yPos=yPos+2.5;}
if(yPos>floor-250)
{yPos=yPos-2.5;}
}
}
class Wall
{
float xWall;
float yWall;
float zWall;
float xWidth;
float yWidth;
float zWidth;
Wall(float x,float y,float z,float xw,float yw,float zw)
{
xWall=x;
yWall=y;
zWall=z;
xWidth=xw;
yWidth=yw;
zWidth=zw;
}
void drawWall()
{
pushMatrix();
fill(#FFFFFF);
translate(xWall,yWall,zWall);
box(xWidth,yWidth,zWidth);
popMatrix();
}
void bouncer()
{
if((xPos>xWall-xWidth*0.5&xPos<xWall+xWidth*0.5)&(yPos>yWall-yWidth*0.5&yPos<yWall+yWidth)&(zPos>zWall-zWidth*0.5&zPos<zWall+zWidth*0.5))
{
xPos=(sin(mouseturnX)*-c1)+xPos;
zPos=(cos(mouseturnX)*-c1)+zPos;
xPos=(cos(mouseturnX)*-a1)+xPos;
zPos=(sin(mouseturnX)*-a1)+zPos;
}
}
}