I have a small question. If I go inside a building and then go out, it spawns at the very beginning. How can I make it spawn at the door of the building?
public class CenterInside extends World
{
/**
* Constructor for objects of class CenterInside.
*
*/
public CenterInside()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(280, 150, 1);
addObject (new menuPokemon(), 140, 150);
addObject (new redLine(), 222, 149);
addObject (new redLine(), 46, 149);
addObject (new redLine(), 9, 53);
addObject (new redLine(), 271, 53);
addObject (new redLine(), 138, 6);
addObject (new PCLobby(), 137, 76);
addObject (new Ash(), 144, 97);
}
}public class Ash extends SmoothMover
{
public double moveSpeed = 1.5;
/**
* Act - do whatever the Ash wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.isKeyDown ("up") || Greenfoot.isKeyDown ("w"))
{
setLocation(getExactX(), getExactY()-moveSpeed);
setImage("roodkapjeachter.gif");
if (isTouching(Tree.class))
{
setLocation(getExactX(), getExactY()+moveSpeed);
}
if (isTouching(house.class))
{
setLocation(getExactX(), getExactY()+moveSpeed);
}
if (isTouching(redLine.class))
{
setLocation(getExactX(), getExactY()+moveSpeed);
}
if (isTouching(Man.class))
{
setLocation(getExactX(), getExactY()+moveSpeed);
}
if (isTouching(Ant2.class))
{
setLocation(getExactX(), getExactY()+moveSpeed);
}
}
if (Greenfoot.isKeyDown ("down") || Greenfoot.isKeyDown ("s"))
{
setLocation(getExactX(), getExactY()+moveSpeed);
setImage("roodkapjevoor.gif");
if (isTouching(Tree.class))
{
setLocation(getExactX(), getExactY()-moveSpeed);
}
if (isTouching(house.class))
{
setLocation(getExactX(), getExactY()-moveSpeed);
}
if (isTouching(redLine.class))
{
setLocation(getExactX(), getExactY()-moveSpeed);
}
if (isTouching(Man.class))
{
setLocation(getExactX(), getExactY()-moveSpeed);
}
if (isTouching(Ant2.class))
{
setLocation(getExactX(), getExactY()-moveSpeed);
}
}
if (Greenfoot.isKeyDown ("left") || Greenfoot.isKeyDown ("a"))
{
setLocation(getExactX()-moveSpeed, getExactY());
setImage("roodkapjelinks.gif");
if (isTouching(Tree.class))
{
setLocation(getExactX()+moveSpeed, getExactY());
}
if (isTouching(house.class))
{
setLocation(getExactX()+moveSpeed, getExactY());
}
if (isTouching(redLine.class))
{
setLocation(getExactX()+moveSpeed, getExactY());
}
if (isTouching(Man.class))
{
setLocation(getExactX()+moveSpeed, getExactY());
}
if (isTouching(Ant2.class))
{
setLocation(getExactX()+moveSpeed, getExactY());
}
}
if (Greenfoot.isKeyDown ("right") || Greenfoot.isKeyDown ("d"))
{
setLocation(getExactX()+moveSpeed, getExactY());
setImage("roodkapjerechts.gif");
if (isTouching(Tree.class))
{
setLocation(getExactX()-moveSpeed, getExactY());
}
if (isTouching(house.class))
{
setLocation(getExactX()-moveSpeed, getExactY());
}
if (isTouching(redLine.class))
{
setLocation(getExactX()-moveSpeed, getExactY());
}
if (isTouching(Man.class))
{
setLocation(getExactX()-moveSpeed, getExactY());
}
if (isTouching(Ant2.class))
{
setLocation(getExactX()-moveSpeed, getExactY());
}
}
}
}public class Tent extends WorldChanger
{
/**
* Act - do whatever the Tent wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (isTouching(Ash.class))
{
Greenfoot.setWorld(new CenterInside());
}
}
}public class menuPokemon extends IntrosAndText
{
/**
* Act - do whatever the menuPokemon wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (isTouching(Ash.class))
{
Greenfoot.setWorld(new MyWorld());
}
}
}import greenfoot.*;
public class Tent extends WorldChanger
{
private boolean touchingAsh; // to track touching state
public void act()
{
if (touchingAsh != isTouching(Ash.class)) // does touching state change
{
touchingAsh = !touchingAsh; // changed state
if (touchingAsh) // is it just now touching
{
CenterInside inside = new CenterInside();
Greenfoot.setWorld(inside);
}
}
}
}// change line 8 of CenterInside class to public menuPokemon(World trigger)
// change line 14 in my Tent class code above to CenterInside inside = new CenterInside(getWorld());
/** in the menuPokemon class */ // add instance field public World myWorld;
menuPokemon menu = new menuPokemon(); menu.myWorld = trigger; addObject (menu, 140, 150);
Greenfoot.setWorld(myWorld);