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

2011/10/14

Help with "Run"

Ludiko Ludiko

2011/10/14

#
Hi im quite new here and quite new on programming things with Greenfoot... Can somebody of you tell me how i get more than 1 target moving at the same time? For e.g. 1Robot (moved by keyboard ) and a few Stones (moved by void act() itselfs)
danpost danpost

2011/10/14

#
EVERY object that has an act() method in Greenfoot will have a turn to act, and then, act again, repeatedly, in a cycle. Therefore, the act() method in Stone.class will take care of moving any and all stones within the world. The robot also can have an act() method which can check for specific keystrokes and act accordingly.
Ludiko Ludiko

2011/10/14

#
Ok thanks Can you tell how this guy (http://www.greenfoot.org/scenarios/3499) is doing it, so that the panda is moveable while the cats and the burgers move too.
danpost danpost

2011/10/14

#
That scenario does not provide the source code, so it is impossible to say how the programmer accomplished it. However, since the world of that scenario is in outer space, the cats and burgers are probably given random direction, velocity, and starting edge positions. BTW, the motherboard of my laptop blew; and I am, at present, incapable of even looking at any scenarios that do not provide source code. Anyway, the behaviour of the objects could be an indication as to what programming may have been used. Is the panda keyboard controlled?
danpost danpost

2011/10/14

#
I stand corrected. I am using a different browser and am able to run all scenarios. I looked at Space Panda and it appears that both cats and burgers are using random turning (something like: if(Greenfoot.getRandomNumber(100) < 5) { turnRandom(); } ). Also being used is edgeOfWorld checking to redirect the objects when needed. Both the cats and burgers will probably have an instance variable for the direction which is translated to X and Y offsets for moving the object.
Ludiko Ludiko

2011/10/14

#
Thank you :)
danpost danpost

2011/10/14

#
@Ludiko my previous post was edited (added to).
You need to login to post a reply.