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

2014/1/1

Power Ups

Elisam Elisam

2014/1/1

#
I have a question: I want to implement Power Ups in my Breakout game, like getting a greater paddle, or a second ball . I made a class Entity and let the single Power Ups inherit from that. So my question is: Is there a way in java to check only if the Player(paddle) collides with the an Entity, because checking every Power Up would be a little bit code.
Elisam Elisam

2014/1/1

#
Pls anybody? ;)
danpost danpost

2014/1/1

#
You can specify the class of intersection in most (if not all) of the collision detection methods provided by greenfoot in the Actor class.
Elisam Elisam

2014/1/1

#
Ok thanks for your answer, but i meant something other I know that all the collision detection methods and their parameters but i meant if i have to check every Power Up class with those methods for example: Actor a = getOneIntersectingObject(PlayerUp.class) and Actor a = getOneIntersectingObject(BallUp.class) or if i can just write Actor a = getOneIntersectingObject(Entity.class)? Entity is the superclass for the power ups
Elisam Elisam

2014/1/1

#
sry for my english, i am from Austria ;)
danpost danpost

2014/1/1

#
All objects of your subclasses of Entity are considered Entity objects and will be detected by the collision methods. Once detected, however, you will need to determine which kind it is to perform the correct action(s), anyway. So, your choice is (1) detect each kind individually, or (2) determine kind after detected. To determine the kind after detection, use the 'instanceof' keyword. For example:
Actor a = getOneIntersectingObject(Entity.class);
if (a != null)
{
    if (a instanceof PlayerUp.class)
    {
        // player up code
    }
    if (a instanceof BallUp.class)
    {
        // ball up code
    }
    // etc.
}
Elisam Elisam

2014/1/1

#
Great thanks for your answer, thats directly what i needed to know, thanks ;)
You need to login to post a reply.