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

2016/10/16

boolean

Nosson1459 Nosson1459

2016/10/16

#
private GreenfootImage image1=new GreenfootImage("mystery.png");
    private GreenfootImage image2=new GreenfootImage("MysteryG.png");
    private int timer=0;
    private boolean hit=false;
    private int counter=0;
    public Box()
    {
       setImage(image1);
    }
    /**
     * Act - do whatever the Box wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
         hit();
    }  
    private boolean checkPengu1()
    {
        Object under=getOneObjectAtOffset(0,getImage().getHeight()/2+1,Pengu.class);
        return under!=null;
    }
    private boolean checkPengu2()
    {
        Object under=getOneObjectAtOffset(getImage().getWidth()/2-1,getImage().getHeight()/2,Pengu.class);
        return under!=null;
    }
    private boolean checkPengu3()
    {
        Object under=getOneObjectAtOffset(-getImage().getWidth()/2+1,getImage().getHeight()/2,Pengu.class);
        return under!=null;
    }
    private void checkPengu()
    {
        if(checkPengu1()||checkPengu2()||checkPengu3())
        {
            hit=true;
        }
    }
    private void hit()
    {
        if(hit==true)
        {
            timer++;
            if(counter<6)
            {
                if(timer==2&&getImage()==image1)
                {
                    setImage(image2);
                    timer=0;
                    counter++;
                }
                if(timer==2&&getImage()==image2)
                {
                    setImage(image1);
                    timer=0;
                    counter++;
                }
            }
        }
        if(counter==6)
        counter=0;
    }
4 some reason da variable hit never becomes true
Nosson1459 Nosson1459

2016/10/16

#
and i need da variable bec. otherwise the counter wont count and it wont switch back and forth
Nosson1459 Nosson1459

2016/10/16

#
got it stupid mistake forgot 2 call da checkHit method in da act
You need to login to post a reply.