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

2013/5/27

dog world help

gyrlonfilm gyrlonfilm

2013/5/27

#
Hi All, I am just trying very hard to get through this class. I am completely absolutely new to programming, and I am trying to do the dog world scenario in Greenfoot. One thing I have not understood throughout the class is to get one object to move when there are multiples of the same object in the world. I was able to create four dogs, and I have to make one dog move using arrow keys, greet the other dogs, and basically do everything else while the other dogs just sit there. How do I make a player controlled Dog do everything? I don't know how to write the code for this.
GreenGoo GreenGoo

2013/5/27

#
The simplest way is to make to classes of Actor, both of which have dog images representing them. One would be controlled by you and the others would do whatever dogs do. There is probably some way of coding it so that you can have lots of dogs and only control one, but I don't know what that is.
gyrlonfilm gyrlonfilm

2013/5/27

#
Thanks for your help. That is the part I am stuck on.
danpost danpost

2013/5/27

#
Better might be to have a main Dog class (for just sitting there); then, sub-class that class with 'MyDog' or 'ActiveDog' and put the action code in its 'act' method (the main Dog class should have an empty 'act' method). Create one dog using 'new MyDog()' or 'new ActiveDog()'; create all the others with 'new Dog()'.
gyrlonfilm gyrlonfilm

2013/5/27

#
Got it! Thanks!
You need to login to post a reply.