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

2019/3/21

Prevent different objects from completely overlapping with each other

1
2
Abwatts Abwatts

2019/3/23

#
Sorry about that. I have a class called Roach where I have two methods that are in charge of "doubling" (doubles the number of roaches in the population), and "spraying", (decreasing the size of the population by 10%). What I'm trying to is wait a couple of seconds before either doubling the population or spraying it to make it look more natural rather than just executing the methods right away. Now, I don't know if there's a way to pause the game without using the while loop which essentially prevents other methods from executing in the same time (they wait for while loop to finish its thing first and then they execute, I guess). Yes, you're right, I use the terminal as a way to debug my program, they're just temporarily there.
danpost danpost

2019/3/23

#
Abwatts wrote...
I don't know if there's a way to pause the game without using the while loop which essentially prevents other methods from executing in the same time (they wait for while loop to finish its thing first and then they execute, I guess).
I think you want something like:
private boolean grow;

// sample code for spraying method

if (timer == 0)
{
    if (<< some condition >>)
    {
        grow = false;
        setWait(10);
    }
}
else if (grow == false && --timer == 0) spray();
Abwatts Abwatts

2019/3/24

#
danpost wrote...
Abwatts wrote...
I don't know if there's a way to pause the game without using the while loop which essentially prevents other methods from executing in the same time (they wait for while loop to finish its thing first and then they execute, I guess).
I think you want something like:
private boolean grow;

// sample code for spraying method

if (timer == 0)
{
    if (<< some condition >>)
    {
        grow = false;
        setWait(10);
    }
}
else if (grow == false && --timer == 0) spray();
Thanks a lot! I truly appreciate all of your help! Especially since I'm just a beginner who would like to become better one day.
You need to login to post a reply.
1
2