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

2016/11/11

Score problems

cesararp10 cesararp10

2016/11/11

#
i got a problem on trying to make my score count. the logic is: when my char hits an "garbage", it disappears and we add a point. i don't know why, but the points doesn't change ... we tried some solutions of this forum but they didn't work. can someone help us? i will show the code below. this is our score counter code:
public class pontos extends Actor
{
      int pontos = 0;
public void act() 
    {
       mostraPontos();
    }    
    
    public void mostraPontos()
    {
        setImage(new GreenfootImage("Pontos : " + pontos, 24, Color.WHITE, new Color(0,0,0,0)));
    }
    
    public void addPontos()
    {
        pontos++;
    }

}
this is our character code (the part of hitting the "garbage" and adding a point):
public void someObjetos()
        {
             Actor vidroSome;
             vidroSome = getOneIntersectingObject (vidro.class);

if(vidroSome != null)
             {
                 World terreno;
                 terreno = getWorld();
                 
                 terreno.removeObject(vidroSome);
             }
}
thanks! PS: i'm brazilian and i don't know english very well, sorry.
Super_Hippo Super_Hippo

2016/11/11

#
You could try this in line 10:
(pontos)(terreno.getObjects(pontos.class).get(0)).addPontos();
cesararp10 cesararp10

2016/11/11

#
thank you so much ... worked great!!
You need to login to post a reply.