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

2015/4/8

Question about random spawn in "false" world,

Zakuza Zakuza

2015/4/8

#
So yeah basically i got this question. Lets say we make our world false as in:
1
2
3
4
5
public GameWorld1()
{
    super(900, 600, 1, false);
    prepare();
}
And in that world we spawn something like this:
1
2
if (Greenfoot.getRandomNumber (8000) == 1)
            getWorld().addObject(new DmgUp(), Greenfoot.getRandomNumber(getWorld().getWidth()), 0);
Does it still spawn my objects in range from 0 to 900, or does it go out of boarder because the world is false?
danpost danpost

2015/4/9

#
Actually, it will not spawn in a location that would also be possible without the false -- but only by one pixel. Without the false, the right-most x location coordinate would be 'getWorld().getWidth()-1', which would be the 900th pixel across the screen if you created the world with:
1
super(900, 600, 1);
With the false, you can place your actors anywhere !! For example:
1
getWorld().addObject(new DmgUp(), 1200, -200);
would place the actor out of view at the location specified with respect to the upper-left corner of the world window, (0, 0).
Zakuza Zakuza

2015/4/9

#
So in other words it will never spawn out of boarders but -1 is a possibility.
danpost danpost

2015/4/9

#
Zakuza wrote...
So in other words it will never spawn out of boarders but -1 is a possibility.
No. That is not what I am saying at all. I am saying that in a bounded world (one where the boolean is not present or is true), your actors can never go beyond the x range of zero to one short of the width of the world and the y range of zero to one short of the height of the world. However, in an unbounded world (one where the boolean is false -- what you called a 'false world'), you can place actors at any location, whether in the bounds of the visible world or not.
Zakuza Zakuza

2015/4/9

#
Okay, sorry got it the wrong way. But can it spawn outside the world if i put in line
1
2
if (Greenfoot.getRandomNumber (8000) == 1)
            getWorld().addObject(new DmgUp(), Greenfoot.getRandomNumber(getWorld().getWidth()), 0);
Yes or no? I know i can spawn objects anywhere i want in 'false world'. But you see, in my scenario my World1 is false. It is false because i need to spawn my enemies out of boarder, so that it would seem they are gently walking in not just randomly appearing on the edge. Also i have power up system, they spawn just like this:
1
2
if (Greenfoot.getRandomNumber (8000) == 1)
            getWorld().addObject(new DmgUp(), Greenfoot.getRandomNumber(getWorld().getWidth()), 0);
i know random number 8000 makes a possibility to 1/8000 and it very low. which makes 0.0125% on every time my act method is called. but I'm getting a little paranoid - what if my power ups are spawning outside the world.
danpost danpost

2015/4/9

#
If you do not want your power ups to spawn outside the world -- no problem (even in a 'false world'). The spawn code you gave will not cause them to spawn outside of the view window. But, if you want your enemies to spawn outside the world window, then you need to use coordinate values that would put them out of view with an x value less than zero or greater than the width of the world or a y value less than zero or greater than the height of the world.
Zakuza Zakuza

2015/4/9

#
Thank you, now I fully understand how it works.
You need to login to post a reply.