I have trees on the map. How to realize the player's inability to pass through them? I've never actually developed games before, so I don't quite understand how to do it.
So, i think that code would be in this block that I have now:
Here my move function if this would be helpful:
Help please..
public boolean canMove()
{
World myWorld = getWorld();
int x = getX();
int y = getY();
// test for outside border
if (x >= myWorld.getWidth() || y >= myWorld.getHeight()) {
return false;
}
else if (x < 0 || y < 0) {
return false;
}
return true;
}public void move()
{
if (!canMove()) {
return;
}
if (Greenfoot.isKeyDown("down")){
setImage("player.png");
setLocation(getX(), getY() + speed);
}
if (Greenfoot.isKeyDown("up")){
setImage("player.png");
setLocation(getX(), getY() - speed);
}
if (Greenfoot.isKeyDown("right")){
setImage("player.png");
setLocation(getX() + speed, getY());
}
if (Greenfoot.isKeyDown("left")){
setImage("playerLeft.png");
setLocation(getX() - speed, getY());
}
}


