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

2011/10/14

Help with sending an object back to where it started.

ub3030 ub3030

2011/10/14

#
hello i am making a frogger game and i have everything in place except the fact that when my frog hits an object on the world i need him to be sent back to the start point, also when he reaches the end i need him to do the same. i can not find a way to do this and i am very loss. any help will be amazingly great.
danpost danpost

2011/10/14

#
You obviously have a check to see if the frog has hit an object (coded like: if (hitAnyObject()) { doSomething(); } ). In the doSomething() code (that I am guessing will be, or is, in your Frog.class), use the setLocation(int, int) method to return it to its starting position. Same thing, when the frog reaches the end (if (reachedEnd()) { doSomethingElse(); }).
ub3030 ub3030

2011/10/14

#
i have it as a get eat method for the objects that hit the frog, still not sure where to put the set location
danpost danpost

2011/10/14

#
Collision checking should probably be done within the Frog class, as the frog is the main object in the collision (the frog is always involved when a collision occurs). Also, it is the frog that has to be relocated, not the other objects. BTW, 'get eat' really does not say much. When talking about a method, it is best to describe it in detail (give info such as (1) when the method is called (2) what the method is supposed to do (or what information is returned (3) what class the method is in and, (4) any other information that may be helpful (like what name you gave the method). Answering questions correctly, then becomes more likely, and in a timely fashion. Supplying what code you may have so far (again, giving pertinent info about it) also can be extremely helpful in getting quick useful responses. I hope the initial part of this posting was useful. I am sure that other users as well as myself would be more than happy to answer any question you may have or help out with coding.
You need to login to post a reply.