This site requires JavaScript, please enable it in your browser!
Greenfoot back
Charles1025
Charles1025 wrote ...

2016/12/6

Danpost's light beam class collision help

Charles1025 Charles1025

2016/12/6

#
I and currently using danpost's light beam class for a game that i am working on. How do I detect collision with the light beam due to the fact that it is created through a big square image and 2 black rectangle (which is pretty smart, thank you danpost). If i can't is there any other way that can create a light beam and than make collision with other actors?
danpost danpost

2016/12/6

#
I do not have time right now; but, maybe sometime later today I might be able to have some methods you can add to the light beam class to assist in this regard.
Charles1025 Charles1025

2016/12/6

#
Thx :)
danpost danpost

2016/12/7

#
I added the following two methods to the class:
/**
 * indicates if an object of the given class is illumated by this beam
 * 
 * @return true if an object of the given class is illuminated by this beam; else false
 */
public boolean isIlluminated(Class clss)
{
    return getOneIlluminatedObject(clss) != null;
}

/**
 * gets one illuminated object of the given class
 * 
 * @return an illuminated object of the given class, if any; else null
 */
public Actor getOneIlluminatedObject(Class clss)
{
    Actor illuminated = null;
    int rot = getRotation();
    for (Object obj : getIntersectingObjects(clss))
    {
        Actor actor = (Actor)obj;
        turnTowards(actor.getX(), actor.getY());
        int rot2 = getRotation();
        if (rot2-rot > 180) rot2 -= 360;
        if (rot2-rot < -180) rot2 += 360;
        if (Math.abs(rot2-rot) <= range/2)
        {
            illuminated = actor;
            break;
        }
    }
    setRotation(rot);
    return illuminated;
}
Hope they can help.
Charles1025 Charles1025

2016/12/7

#
Thank you Danpost it WORKS!!!!
danpost danpost

2016/12/7

#
Charles1025 wrote...
Thank you Danpost it WORKS!!!!
Glad to be of assistance.
You need to login to post a reply.