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

2018/2/26

How do I stop an actor from going past a certain point

TheMidget TheMidget

2018/2/26

#
Hey i am making a fishing game and the fish in the water is currently going above the water line how do I stop this. Thanks
Super_Hippo Super_Hippo

2018/2/26

#
What is you moving code right now? If you simply want them to turn when they hit the edge (of the water area) you can write a similar method than the atEdge method but with the area of the water and not the whole world. You could also make them turn earlier so they won't hit the surface at all.
TheMidget TheMidget

2018/2/26

#
import greenfoot.*;
/**
 * Write a description of class Pelican here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bonusfish extends Animal
{
        /**
         * Act - do whatever the Pelican wants to do. This method is called whenever
         * the 'Act' or 'Run' button gets pressed in the environment.
         */
        public void act() 
        {
            
                  move (3);
                  int num=Greenfoot.getRandomNumber(100);
                  if(num<10)
                {
                    turn(15);
                }
                    if (atWorldEdge())
               {
                 turn(3); 
                }    
 }         
}   

danpost danpost

2018/2/27

#
What is the size of your world? What is the size of the water image? Where is the water actor located in the world? or, if the background, at what y-coordinate value in your world does the water end (or begin)? Basically, describe where your water line is at in your world.
TheMidget TheMidget

2018/2/27

#
The water line is at 200 y sorry for late reply
danpost danpost

2018/2/27

#
Then in act method for class of fish, put:
if (getY() < 200) setLocation(getX(), 200);
TheMidget TheMidget

2018/2/27

#
ok i will try this thanks
TheMidget TheMidget

2018/2/27

#
Thank you so much you wouldnt prehaps now how to keep my fish from facing the right way it kind of goes backwards and do you know how to slow the speed down
You need to login to post a reply.