Feeding Exercise - Make Doty face a different direction

4 replies [Last post]
Ayu
Ayu's picture
Offline
Joined: 06/12/2013

Hey, I just joined the site.  :)

I'm a Java beginner and I started the lessons on this site yesterday.

Right now I'm stuck at the "Doty Feeding Exercise". I somehow managed to let Doty stop in front of the walls, now I just have to make it face the direction it's moving to. But I have no idea how to do that. I already added a rotateY state variable to the Doty class and after that I tried a few different things but I just can't figure out how this is supposed to work. :/

It would be really nice if somebody could tell me what to do now or maybe show me their finished Feeding Exercise so that I can understand what I did wrong?

Thanks in advance.  :)

Offline
Joined: 12/13/2010
Maybe you can post your code

Maybe you can post your code so we can see what you are doing wrong?

Also, welcome to the site!

Jason

Ayu
Ayu's picture
Offline
Joined: 06/12/2013
Well ok. Even though it's

Well ok. Even though it's totally embarrasing. I'm not even sure if everything I made so far makes sense. (like Doty stopping in front of the walls etc.)

 

public class Doty
{   private double x;
    private double y;
    private double z;
    private String texture;
    private double rotateY;
    
    public Doty(double x, double y, double z)
    {
        // initialise instance variables
        this.x = x;
        this.y = y;
        this.z = z;
        texture = "textures/doty.png";
        rotateY = 0;
    }
    
    public void moveX(double delta)
    {
        if (x > 9) {
            x = 9;
        }

      
        else if (x < 1) {
            x = 1;
        }
       
        else {
            x = x + delta;
        }
       
    }
               
    public void moveZ(double delta)
    {
        if (z > 9) {
            z = 9;
        }
       
        else if (z < 1) {
            z = 1;
        }
       
        else {
            z = z + delta;
        }
    }   
}

 

As you can see... I added the rotateY state variable... But the rest... I don't even know where to start.

As I sad. I'm just a beginner.

Offline
Joined: 12/13/2010
You are very close.  You

You are very close.  You simple needs to change the rotateY to point to the proper direction, like this:

 

   public void moveX(double delta)
    {
        if (x > 9) {
            x = 9;
        }       
        else if (x < 1) {
            x = 1;
        }
       
        else {
            x = x + delta;
        }

 

        if (delta > 0) {

            rotateY = 90;

        } else {

            rotateY = -90;

        }
       
    }

Ayu
Ayu's picture
Offline
Joined: 06/12/2013
Thank you so much. You helped

Thank you so much. You helped me a lot. :)

I did the same thing with moveZ just now and it works perfectly fine.