Sorry I just realized I for some reason had only posted half of what I intended to write ^^'.
The right sentence: All of my tile classes i.e. my Coin, Torch and Sword class just extend Actor, not a Tile class
if (Greenfoot.mousePressed(null) && mouseActor == null)
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse.getActor() == null || mouse.getActor().getClass() != PIP.class) return;
mouseActor = mouse.getActor();
mouseOffX = mouseActor.getX()-mouse.getX();
mouseOffY = mouseActor.getY()-mouse.getY();
removeObject(mouseActor);
addObject(mouseActor, mouse.getX()+mouseOffX, mouse.getY()+mouseOffY);
}
if (mouseActor != null && Greenfoot.mouseDragged(mouseActor))
{
MouseInfo mouse = Greenfoot.getMouseInfo();
mouseActor.setLocation(mouse.getX()+mouseOffX, mouse.getY()+mouseOffY);
}
if (mouseActor != null && Greenfoot.mouseClicked(mouseActor)) mouseActor = null;public class Sword extends Tile{}public class Tile extends greenfoot.Actor
{
static Tile tileSelected;
public Tile()
{
getImage().scale(40, 40);
}
public static void setSelected(Tile tile)
{
tileSelected = tile;
}
}if (minorPIP != null && minorPIP.getWorld() != null && Greenfoot.mouseClicked(minorPIP))
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse == null) return;
int x = (mouse.getX()-(minorPIP.getX()-minorPIP.getWidth()/2))/minor.getCellSize();
int y = (mouse.getY()-(minorPIP.getY()-minorPIP.getHeight()/2))/minor.getCellSize();
Tile.setSelected((Tile)minor.getObjectsAt(x, y, Tile.class).get(0));
}public class Major extends World
{
PIP pip;
PIP pip2;
boolean wDown;
boolean sDown;
Actor mouseActor;
int mouseOffX, mouseOffY;
public Major()
{
super(1675, 910, 1);
//paint the background blue
GreenfootImage background = getBackground();
background.setColor(Color.blue);
background.fill();
//spawn the Bejeweled/puzzle world
World minor = new Bejeweled_World();
Class[] order = { Sword.class };
Class[] order2 = { Torch.class };
Class[] order3 = { Coin.class };
pip = new PIP(minor, order);
addObject(pip, 1070, 605);
}
public void act()
{
// control running state the wombat PIP objects
if (!wDown && Greenfoot.isKeyDown("1"))
{
pip.setActiveState(!pip.getActiveState());
wDown = true;
}
if (wDown && !Greenfoot.isKeyDown("1")) wDown = false;
// control running state the ship PIP objects
if (!sDown && Greenfoot.isKeyDown("2"))
{
pip2.setActiveState(!pip2.getActiveState());
sDown = true;
}
if (sDown && !Greenfoot.isKeyDown("2")) sDown = false;
// all the below if statements control dragging of PIP objects
if (Greenfoot.mousePressed(null) && mouseActor == null)
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse.getActor() == null || mouse.getActor().getClass() != PIP.class) return;
mouseActor = mouse.getActor();
mouseOffX = mouseActor.getX()-mouse.getX();
mouseOffY = mouseActor.getY()-mouse.getY();
removeObject(mouseActor);
addObject(mouseActor, mouse.getX()+mouseOffX, mouse.getY()+mouseOffY);
}
if (mouseActor != null && Greenfoot.mouseDragged(mouseActor))
{
MouseInfo mouse = Greenfoot.getMouseInfo();
mouseActor.setLocation(mouse.getX()+mouseOffX, mouse.getY()+mouseOffY);
}
if (mouseActor != null && Greenfoot.mouseClicked(mouseActor)) mouseActor = null;
if (minorPIP != null && minorPIP.getWorld() != null && Greenfoot.mouseClicked(minorPIP))
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse == null) return;
int x = (mouse.getX()-(minorPIP.getX()-minorPIP.getWidth()/2))/minor.getCellSize();
int y = (mouse.getY()-(minorPIP.getY()-minorPIP.getHeight()/2))/minor.getCellSize();
Tile.setSelected((Tile)minor.getObjectsAt(x, y, Tile.class).get(0));
}
}
}Bejeweled_World minor;