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

2016/5/31

Need help with calculating percentages in status bars

Drvagax Drvagax

2016/5/31

#
Sorry for the confusing title! I'm currently making a program in which you need to take care of a Quokka and every second his/hers needs will drop and right now it goes down with 1 per second but it needs to be 1.5% per tick, i tried to simply make it from INT to LONG but then my status bars stop working. Status bar
    public void toonConditions(QuokkaModel qm)
    {
        GreenfootImage bg = getBackground();

        bg.setColor(Color.blue);
        bg.drawRect(8, 2, 8, 102);
        bg.fillRect(10,4,5,1*qm.getHealth());
The code above draws a bar which slowly decays every time. The code that gets executed every second, decreasing the conditions
    public void live()
    {
        health--;
        tiredness++;
        happiness--;
        hunger++;
}
So as you can see it just decreases it with 1, pretty simple but it needs to be 1.5% which i wanted to do with simply putting in that it should take off 1.5 per tick but then the code i posted before (with the bars) stop working. Can anyone help me?
danpost danpost

2016/5/31

#
Provided that you did not change anything at all in the 'toonConditions' method and the status bar was indeed working, then the only thing that could influence the status bar from in the QuokkaModel class is the 'getHealth' method. Where is it code? However, it is yet beyond me how the status bar could possibly work with the given code. The thing is that I cannot see how the bar would decay because it looks like you are filling a smaller rectangle over the full rectangle -- which would not actually change the appearance of a full status bar.
You need to login to post a reply.