Is there any possibility to check, if the Image of an Object touchs another image?
I don't mean "getOneIntersectingObject(Whatever.class)".
I mean, if that, what is drawed on the Image, touches anything, that is drawed on another Objects Image?
public boolean checkTouch(Actor a)
{
if(checkOneTouch(-20, 20, -40, a)) return true;
if(checkOneTouch(-17, 17, -39, a)) return true;
if(checkOneTouch(-18, 18, -38, a)) return true;
if(checkOneTouch(-14, 14, -37, a)) return true;
if(checkOneTouch(-15, 15, -36, a)) return true;
//...
if(checkOneTouch(-14, 14, 40, a)) return true;
return false;
}
public boolean checkOneTouch(int xStart, int xEnd, y, Actor a)
{
for(int x=start; x<end; x++)
{
if(getOneObjectAtOffset(x,y, a.class)!=null)
return true;
}
return false;
}
public List getTouchedObjects(Class clss)
{
List<Actor> list = getIntersectingObjects(clss);
List<Actor> list2 = getIntersectingObjects(clss);
list2.clear();
GreenfootImage i=new GreenfootImage(getImage());
i.rotate(getRotation());
int w=i.getWidth(),h=i.getHeight(),x=getX(),y=getY();
for(Actor A : list)
{
GreenfootImage Ai = new GreenfootImage(A.getImage()), i2 = new GreenfootImage(w,h);
Ai.rotate(A.getRotation());
int Aw=Ai.getWidth(),Ah=Ai.getHeight(),Ax=A.getX(),Ay=A.getY();
i2.drawImage(Ai,Ax-x-(Aw/2-w/2),Ay-y-(Ah/2-h/2));
boolean b = true;
for(int yi = 0; yi<h && b; yi++)
for(int xi = 0; xi<w && b; xi++)
if(i2.getColorAt(xi,yi).getAlpha()>0 && i.getColorAt(xi,yi).getAlpha()>0)
{
list2.add(A);
b=false;
}
}
return list2;
}
public Actor getOneTouchedObject(Class clss)
{
List<Actor> list = getIntersectingObjects(clss);
List<Actor> list2 = getIntersectingObjects(clss);
list2.clear();
GreenfootImage i=new GreenfootImage(getImage());
i.rotate(getRotation());
int w=i.getWidth(),h=i.getHeight(),x=getX(),y=getY();
for(Actor A : list)
{
GreenfootImage Ai = new GreenfootImage(A.getImage()), i2 = new GreenfootImage(w,h);
Ai.rotate(A.getRotation());
int Aw=Ai.getWidth(),Ah=Ai.getHeight(),Ax=A.getX(),Ay=A.getY();
i2.drawImage(Ai,Ax-x-(Aw/2-w/2),Ay-y-(Ah/2-h/2));
for(int yi = 0; yi<h; yi++)
for(int xi = 0; xi<w; xi++)
if(i2.getColorAt(xi,yi).getAlpha()>0 && i.getColorAt(xi,yi).getAlpha()>0)
return A;
}
return null;
}import java.util.List;
import greenfoot.*;