Hello
I would like to create a Labyrinth. At the moment I'm working on the walls so my actor can't pass them. I createt a matrix for the playground in the World-class and I need access to this class in the actor-class. I tried at least 3 hours to find a solution, but unfortunately I don't get it. : (
1.) part-code of the World-class
2.) code of the actor-class:
public boolean solid(int a, int b)
{
int x = a;
int y = b;
int ID = matrix [x][y];
if(ID == 1){
return false;
}
else{
return true;
}
} /**
* Act - do whatever the Player wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
collisionCheck();
}
/**
* Test for collision
*/
public void collisionCheck()
{
int a = 0;
int b = 0;
a = this.getX()+1% blockgrösse;
b = this.getY()+1% blockgrösse;
myWorld.solid(a,b);
if (moveRight == true)
{
if (m_World.solid(a,b)== true)
{
move();
}
}
if (moveLeft == true)
{
if (m_World.solid(a,b)== true)
{
move();
}
}
if (moveUp == true)
{
if (m_World.solid(a,b)== true)
{
move();
}
}
if (moveDown == true)
{
if (m_World.solid(a,b)== true)
{
move();
}
}
}
public void move(){
moveLeft = false;
moveRight = false;
moveUp = false;
moveDown = false;
if (Greenfoot.isKeyDown("a")){
setLocation(getX()-speed,getY());
moveLeft = true;
}
if (Greenfoot.isKeyDown("d")){
setLocation(getX()+speed,getY());
moveRight = true;
}
if (Greenfoot.isKeyDown("w")){
setLocation(getX(),getY()-speed);
moveUp = true;
}
if (Greenfoot.isKeyDown("s")){
setLocation(getX(),getY()+speed);
moveDown = true;
}
}

