Edit: In the shooting lines in my code, the ) right after 0/1 have to be removed.
// instance field in World subclass
private Portal portal;
// in World subclass constructor
portal = new Portal();
new Portal(portal);
// in 'act' method of World subclass
if (Greenoot.mouseClicked(null))
{
MouseInfo mouse = Greenoot.getMouseInfo();
if (mouse.getButton() == 1)
{
if (portal.getWorld() != this)
{
addObject(portal, mouse.getX(), mouse.getY());
}
else // (optional)
{
portal.setLocation(mouse.getX(), mouse.getY());
} // (end optional)
}
if (mouse.getButton() == 3)
{
Portal p = portal.getLinkedPortal();
if (p.getWorld() != this)
{
addObject(p, mouse.getX(), mouse.getY());
}
else // (optional)
{
p.setLocation(mouse.getX(), mouse.getY());
} // (end optional)
}
}public MyWorld()
{
super(800, 800, 1);
testChamber1();
showScore();
endGame();
portal = new Portal1();
new Portal1(portal);
}
public void act()
{
if(Greenfoot.mouseClicked(null))
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if(mouse.getButton() == 1)
{
if(portal.getWorld() != this)
{
addObject( portal, mouse.getX(), mouse.getY());
}
}
if(mouse.getButton() == 3)
{
Portal1 p = getLinkedPortal();
if(p.getWorld() != this)
{
addObject( p, mouse.getX(), mouse.getY());
}
}
}
}
public Portal1 getLinkedPortal()
{
return linkedPortal;
}
public Portal1(Portal1 counterpart)
{
linkedPortal = counterpart;
counterpart.linkedPortal = this;
}
public Portal1 getLinkedPortal()
{
return linkedPortal;
}if (isTouching(Portal1.class))
{
if ( ! transferred )
{
Portal1 portal = ((Portal1)getOneIntersectingObject(Portal1.class)).getLinkedPortal();
setLocation(portal.getX(), portal.getY());
transferred = true;
}
}if(Greenfoot.mouseClicked(null))
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if(mouse.getButton() == 1)
{
if(portal.getWorld() != this)
{
addObject( portal, mouse.getX(), mouse.getY());
}
}
if(mouse.getButton() == 3)
{
Portal1 p = portal.getLinkedPortal();
if(p.getWorld() != this)
{
addObject( p, mouse.getX(), mouse.getY());
}
}
}