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

2018/1/26

help with exam plz due monday

1
2
danpost danpost

2018/1/28

#
roonie01 wrote...
but now my actor only faces right
Okay. Show what you have now (the entire class).
roonie01 roonie01

2018/1/28

#
ok here it is
public class Player1 extends Actor
{
    // GLOBAL DECLARATIONS
    // -------------------
    int walkRate = 0;
    GreenfootImage Right=new GreenfootImage("mega1.png");
    GreenfootImage Left=new GreenfootImage("mega1b.png");
    GreenfootImage RightA=new GreenfootImage("mega2b.png");
    GreenfootImage LeftA=new GreenfootImage("mega2.png");
    int fire=0;
    int move=3;
    // CONSTRUCTOR   // runs one time only
    // -----------
    public Player1()    
    {
        setImage(Right);

    } // end constructor

    // ACT METHOD   // runs repeatedly
    // ----------
    public void act() 
    {
        setLocation(getX(),getY());
        checkForDirectionalControll();
        laser();
        
         walkRate++;
    } // end act

    public void checkForDirectionalControll()
    {
       
        if (Greenfoot.isKeyDown("up"))
        { 
            //says to check for key up and if condition is true move up 3 pixel's 
            setLocation(getX(),getY()-3);
        }//end if
        if (Greenfoot.isKeyDown("down"))
        {
            //says to check for key down and if condition is true move down 3 pixel's
            setLocation(getX(),getY()+3);
        }//end if
        if(Greenfoot.isKeyDown("left")&&(getImage()==Right||getImage()==RightA))
        {
            //says to set the image to the left image when the left arrow is pressed
            
        
        
           
           
            walkrate=0;
        }
        if  (Greenfoot.isKeyDown("left"))
        { 
            //says to check for key left and if condition is true move left 3 pixel's 
            LeftImages();
            setLocation(getX()-3,getY());
        }//endif
        if(Greenfoot.isKeyDown("right")&&(getImage()==Left||getImage()==LeftA))
        {
            //says to set the image to right image when the right arrow is pressed
            //and the walkRate variable = 20
            
      
            
            walkRate=0;
        }
        if (Greenfoot.isKeyDown("right"))
        {

            //says to check for key right and if condition is true move right 3 pixel's
             RightImages();
            setLocation(getX()+3,getY());
        }//end if
        //end checkForDirectionalControll
    } 

    public void RightImages()
    {
       
        if(getImage()==Right&&walkRate==10)
        {
            setImage(RightA);
            
        }
        else if(walkRate==0||walkRate==20)
        {
            setImage(Right);
            walkRate=0;
        }
       
        
    }

    public void LeftImages()
    {

        if(getImage()==Left&&walkRate==10)
        {
            setImage(LeftA);
           
        }

        else if(walkRate==0||walkRate==20)
        {
            setImage(Left);
            walkRate=0;
        }
        

     }
danpost danpost

2018/1/28

#
Remove the 'getImage() == ???' condition from lines 82 and 99.
roonie01 roonie01

2018/1/28

#
ok did that and my player1 still wont face left if I click left
roonie01 roonie01

2018/1/28

#
never mind it works thanks so much danpost
You need to login to post a reply.
1
2