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

2015/4/25

Need help with movement

alexios6 alexios6

2015/4/25

#
I am trying to make the enemy move directions at the edge of the screen to move right and then go down then left and continue. Plz help!
    public boolean right = true;
    public boolean down = false;
    public void toggleRight()
    {
        if(right == true)
        {
          right = false;             
        }
        
    }
    public void toggleLeft()
    {
        if(right == false)
        {
            right = true;
        }
    }
        public void movementBoundaries()
    {
        if(getX()==0)
        {
            down = true;
        }
        if(getX() == 599)
        {
            down = true;
        }
    }
    public void movement()
    {
        if(right == true)
        {
            move(5);   
        }
        if(down == true)
        {
            setLocation(getX(), getY() + 5);
            if(right == true){
              toggleRight();
              move(-5);
              down = false;
              
            }
            if(right == false){
             toggleLeft();
             move(5);
             down = false;
            }
            
        }
        if(right == false)
        {
            move(-5);
        }
    }
It's quite long but I would appreciate any help Thnx!
davmac davmac

2015/4/25

#
I am trying to make the enemy move directions at the edge of the screen to move right and then go down then left and continue.
Could you explain in more detail? I really don't understand what it is that you want it to do.
You need to login to post a reply.