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

2012/10/5

Trying to set a boundary

tomduff5985 tomduff5985

2012/10/5

#
I have to write a simple fishing program. This is the problem I am having: The fish has to stay below a certain point on the Y axis. Obviously, fish can't fly. I tried using the getY to define some if statements, but it doesn't work. Any suggestions?
davmac davmac

2012/10/5

#
We can't see what's wrong with your code if you don't post it ;)
Gevater_Tod4711 Gevater_Tod4711

2012/10/5

#
If you only want a fish to stay below an axis I would use something like this:
//write this in the act method of your fish class;
while (getY() < minY) { //minY is the y coordinate of the line the fish should never cross;
    setLocation(getX(), getY()+5);
}
tomduff5985 tomduff5985

2012/10/5

#
Thank you! I looked at the code this morning and realized I just made a stupid mistake. Nothing a night of sleep can't fix!
You need to login to post a reply.