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

2012/10/11

Respawning

MoneyFishSlap MoneyFishSlap

2012/10/11

#
So my meteor gets destroyed when i hit it with my missile. How would i make it respawn every time the original one dies?
Game/maniac Game/maniac

2012/10/11

#
Bounce time Check out the ball class in this scenario
danpost danpost

2012/10/11

#
From your other discussion thread, I see that the meteors gets hit more than once, getting smaller each time. Do you have more than one meteor coming out of each hit? or is the only change per hit the scaling down in size or removal of the meteor? That is, aside from your attempt to re-spawn a new meteor. If only scaling down and removing, then the scenario Game/maniac suggests to check out would probably be sufficient.
MoneyFishSlap MoneyFishSlap

2012/10/11

#
i couldn't get the shrinking part to work with the disappearing part so i scrapped that idea until i am a bit better at java. Its just a simple case of missile hits meteor, meteor dissapears.
MoneyFishSlap MoneyFishSlap

2012/10/11

#
Game/maniac wrote...
Bounce time Check out the ball class in this scenario
couldn't find anything, looking for something more direct
danpost danpost

2012/10/11

#
The easiest thing to do, is instead of remove one and adding another, just re-locate the one anywhere
int x = Greenfoot.getRandomNumber(getWorld().getWidth()); // get a random x location
int y = Greenfoot.getRandomNumber(getWorld().getHeight()); // get a random y location
setLocation(x, y); // re-locate meteor
See the 'Greenfoot' class API in the documentation here .
MoneyFishSlap MoneyFishSlap

2012/10/11

#
It works but it dosen't look very smooth. Maybe if i added some kind of explosion where the missile hits the meteor it would look better. Could you direct me to a tutorial for explosions?
danpost danpost

2012/10/11

#
You could check out this scenario. Or, I believe that the 'Lunar Landing' scenario that comes with greenfoot has an explosion in it; you could check it out.
Game/maniac Game/maniac

2012/10/11

#
You could also check out this scenario which creates debris when the rock explodes
Pacplay Pacplay

2012/12/17

#
So, yo my homies. Where do you put that there code up there?
danpost danpost

2012/12/17

#
Pacplay wrote...
So, yo my homies. Where do you put that there code up there?
In with the code that detects the collision between the missle and the meteor.
Pacplay Pacplay

2012/12/20

#
Alright, so I did that but instead of meteors respawning, the player respawns
danpost danpost

2012/12/20

#
You need to prefix line 3 with the meteor object that is intersecting the actor. An example intersecting detection with respawn:
Meteor meteor=(Meteor) getOneIntersectingObject(Meteor.class);
// get random x and y
meteor.setLocation(x, y);
ctgreenfoot ctgreenfoot

2012/12/27

#
so im using this for the Little Crab scenario instead where I want the worm to relocate ("respawn") every time the Crab eats it. However, it doesn't seem to be working:
private void eatWorm()
    {
    Actor Worm;
    Worm = getOneObjectAtOffset (0,0,Worm.class);
    if(Worm != null)
    {
        Worm worm = getOneIntersectingObject (Worm.class);
        int x = Greenfoot.getRandomNumber(getWorld().getWidth()); // get a random x location  
        int y = Greenfoot.getRandomNumber(getWorld().getHeight()); // get a random y location  
        setLocation(x, y); // re-locate meteor
        counter.add(1);
        Greenfoot.playSound ("eating.wav");
danpost danpost

2012/12/27

#
First, let me say that it is customary to start variable (aka field) names with lowercase letters. It gets a litle confusing for those looking at your code when you use the same name for a class as well as a field ('Worm'). Next, you already have the intersecting object in the field 'Worm' when you (again) get it in line 7. Finally, line 10 does not relocate the Worm object, but relocates the Crab object instead. The following would be more what you need:
private void eatWorm()
{
    Actor worm;
    worm = getOneObjectAtOffset (0,0,Worm.class);
    if(worm != null)
    {
        int x = Greenfoot.getRandomNumber(getWorld().getWidth());
        int y = Greenfoot.getRandomNumber(getWorld().getHeight());
        worm.setLocation(x, y);
        counter.add(1);
        Greenfoot.playSound ("eating.wav");
    }
}
You need to login to post a reply.