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

2019/5/19

Would like some assistance on my counter class

Bossman1827 Bossman1827

2019/5/19

#
I'm creating Flappy Bird within Greenfoot and my Counter class adds 2 points when i go into between the tubes instead of 1. I'm using this for my code https://www.greenfoot.org/topics/60635/0 but within the pipe class which I'm trying to implement this it is adding 2. Here is my tube public void act code:
   public void act() 
     { 
         setLocation( getX() + SPEEDO, getY());
       if (getX()<=20)
        
          ((Counter)getWorld().getObjects(Counter.class).get(0)).add(1);
       if(getX()<=20)
            getWorld().removeObject(this);

  }
Bossman1827 Bossman1827

2019/5/19

#
This is my full tube code.
   public void act() 
     { 
         setLocation( getX() + SPEEDO, getY());
       if (getX()<=20)
        
          ((Counter)getWorld().getObjects(Counter.class).get(0)).add(1);
       if(getX()<=20)
            getWorld().removeObject(this);

  }
Bossman1827 Bossman1827

2019/5/20

#
Would appreciate a response sooner than later, as I need this done to have for a friend.
Bossman1827 Bossman1827

2019/5/20

#
It is getting late where I am and I'm supposed to have this game ready by early tomorrow, I would even pay for help if necessary.
Super_Hippo Super_Hippo

2019/5/20

#
I can't see what could cause it in the code you have shown. (You posted the same code twice.) The problem might be somewhere else or there are always two pipes on top of each other. Btw, since lines 6 and 8 have the same condition, you don't need to write the condition twice.
if (getX()<=20)
{
    ((Counter)getWorld().getObjects(Counter.class).get(0)).add(1);
    getWorld().removeObject(this);
}
danpost danpost

2019/5/20

#
It is probably having each tube, both top and bottom, adding to the score. It would be okay to just allow it, internally. You can display half that value in the score display actor.
You need to login to post a reply.