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

2019/1/24

Java turnAtEdge

Iz.\uo Iz.\uo

2019/1/24

#
I recently started using Greenfoot/Java for school and I wanted to know how i can vertically and horizontally turn my object after using turnAtEdge , by using Gimp2. I already figured how to turn the image the way that it is correct after it has been turned vertically and horizontally. This is the current situation:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * the Wolf is trying to get LittleRedcap
 * 
 * @author (***** ****) 
 * @version (*-*-****)
 */

public class BackForthWolf extends Wolf
{

    private int marge=90;

    public void act() 
    {
        move(4);
        turnAtEdge();
        eatLitteRedCap();
    }

     /**
     * turns the Wolf at the edge in another rotation. 
     * The rotation depends on wich side the wolf is located.
     */
    public void turnAtEdge()
    {   
        int min=0;
        int max=135;
        if(atWorldEdge())
        {
           //east
            if (getX()>570)
            {
                max=(180);
            }
           //west
            if (getX()<30)
            {
                max=(360);
            }
            setRotation(max);
        }

    } 
Baseclass ^ \____Wolf ^ \______BackForthWolf
danpost danpost

2019/1/24

#
I think what you want is this:
public class BackForthWolf()
{
    private int max;
    
    public void act()
    {
        setRotation(max);
        // do stuff
        ...        
        max = getRotation();
        setRotation(0);
    }
    
    private void turnAtEdge()
    {
        if (getX() > 570) setRotation(180);
        if (getX() < 30) setRotation(0);
    }
You need to login to post a reply.