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

2021/2/11

how to make multiple actors disappear at the same time after one of them got hit by another actor

Andreia Andreia

2021/2/11

#
I want to make a fun learning game where you can answes some questions by shooting one of the answer that are on the screen. When that happens i want all the answers to dissapear but the problem is i can only make the one that im shooting dissapear. How do I make the other answers dissapear?
danpost danpost

2021/2/11

#
Andreia wrote...
I want to make a fun learning game where you can answes some questions by shooting one of the answer that are on the screen. When that happens i want all the answers to dissapear but the problem is i can only make the one that im shooting dissapear. How do I make the other answers dissapear?
It should be something like this (in your Answer class):
1
2
3
4
5
6
7
if (isTouching(Bullet.class)
{
    removeTouching(Bullet.class);
    getWorld().removeObjects(getWorld().getObjects(Answer.class));
    ...
    return;
}
Andreia Andreia

2021/2/12

#
It works with one answer but when I add the other ones it says NullPointerEception. What do I do?
danpost danpost

2021/2/12

#
Andreia wrote...
It works with one answer but when I add the other ones it says NullPointerEception. What do I do?
1
2
3
4
5
6
7
8
9
10
if (isTouching(Bullet.class)
{
    removeTouching(Bullet.class);
    World world = getWorld();
    world.removeObjects(world.getObjects(Answer.class));
    ...
    world.addObject(...);
    ...
    return;
}
danpost danpost

2021/2/12

#
Actually, if you are posing a new question with new answers, it should probably be done in your World subclass.
1
2
3
4
5
6
7
public void act()
{
    if (questionNumber < questionCount && getObjects(Answer.class).isEmpty())
    {
        poseNewQuestion();
    }
}
The world is your main control for your scenario It is not the job of an answer to proceed to a new question.
Andreia Andreia

2021/2/12

#
That worked but they disappear before the bullet touches them. If you can help with that it would be great cuz Im a beginner and I dont know much
danpost danpost

2021/2/12

#
Andreia wrote...
That worked but they disappear before the bullet touches them. If you can help with that it would be great cuz Im a beginner and I dont know much
Show Answer class codes.
Andreia Andreia

2021/2/12

#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class RaspC1 here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class RaspC1 extends Intrebare1
{
    /**
     * Act - do whatever the RaspC1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        hitRasp();
    }   
    public void hitRasp()
    {
        if ( isTouching(Ball.class));
        {
            removeTouching(Ball.class);
            World world = getWorld();
            world.removeObjects(world.getObjects(RaspC1.class));
            world.removeObjects(world.getObjects(RaspG11.class));
            world.removeObjects(world.getObjects(RaspG12.class));
            world.removeObjects(world.getObjects(Intrebare1.class));
        }
    }
}
Andreia Andreia

2021/2/12

#
Rasp and RaspC1 RaspG11 Rasp G12 are the answers
Andreia Andreia

2021/2/12

#
And Intrebare1 is the question
danpost danpost

2021/2/12

#
Andreia wrote...
<< Code Omitted >>
You can remove lines 25 thru 27. They will be removed by line 28. How are your answer objects getting their images?
Andreia Andreia

2021/2/13

#
danpost danpost

2021/2/13

#
Andreia wrote...
<< Image Link Omitted >>
I hope you are not planning on having a class for each and every answer and question. Having an image for each is as far as I would go. One question class and one answer class is doable if you name the image files adequately (for example: q1, q2, q3 ... and a1_1, a1_2, a1_3, a2_1, a2_2, a2_3 ...). Side note: the answer class(es) should not extend the question class, anyway. An extending class is supposed to be the same type as the class it extends. An answer is NOT a question.
You need to login to post a reply.