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

2022/5/26

hello I need help with this getObjectsInRange method

1
2
danpost danpost

2022/5/29

#
bañaperras wrote...
Hello, do you know any method so that when the lives of an object are removed, it drops an object and reappears in another place and thanks for the previous code, it worked for me :)
Just have the actor reset its lives and randomly relocate itself when dropping the object.
bañaperras bañaperras

2022/5/29

#
Can you give me an example I'm new to greenfoot
bañaperras bañaperras

2022/5/29

#
@Roshan123 if you are correct it just has to respawn at a random coordinate
danpost danpost

2022/5/29

#
bañaperras wrote...
Can you give me an example I'm new to greenfoot
Show codes where the object is being dropped.
bañaperras bañaperras

2022/5/29

#
I haven't done it yet, I don't know what method to use
Roshan123 Roshan123

2022/5/30

#
When the life is equal to zero, you have to add a coffin in its location by writing addObject(coffin, this.getX(), this.getY()); and after that remove the object from the world Now to respawn it randomly within your world size, write something like this:
addObject( obj, Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight()) );
OR Do this
danpost wrote...
Just have the actor reset its lives
without removing the actor and then
danpost wrote...
randomly relocate itself when dropping the object.
bañaperras bañaperras

2022/5/30

#
ok thanks i will implement it
bañaperras bañaperras

2022/5/31

#
 if(isTouching(turle.class))
         { 
         removeTouching(turle.class);
         getWorld().addObject (new turle(), 60, 20);   
        }
in which part I add that when the object is removed, drop the coffin in the coordinate since the other code did not work for me
bañaperras bañaperras

2022/5/31

#
that is, in the coordinate that the player died
Roshan123 Roshan123

2022/5/31

#
make a life variable which will instantly checks it's health
//In Object class
Actor coffin = (Actor)getWorld().getObjects(Coffin.class).get(0);
if(life==0)
{
getWorld().addObject(coffin, getX(), getY());
getWorld().removeObject(this);
}

//In world
if(getObjects(Object.class).isEmpty())
addObject(obj, Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight()) );
Now implement it accordingly
bañaperras bañaperras

2022/5/31

#
Thanks I will implement it :)
Spock47 Spock47

2022/6/1

#
Roshan123 wrote...
Actor coffin = (Actor)getWorld().getObjects(Coffin.class).get(0);
Note, that this will only work when there is already a coffin in the world and that coffin would be removed from the old position to the new one. If you want to add a new coffin, use instead:
Actor coffin = new Coffin();
Roshan123 Roshan123

2022/6/1

#
Spock47 wrote...
Note, that this will only work when there is already a coffin in the world and that coffin would be removed from the old position to the new one.
Oh sorry, thanks for rectifying it
bañaperras bañaperras

2022/6/2

#
hey thanks for the help I have already finished my game it has been a good experience in the forum I feel very comfortable in this community thank you really soon I will upload it to the forum so you can see what I learned thanks to you I hope that if someone is in need can help see you soon :)
You need to login to post a reply.
1
2