Hello, I've made a HealthCounter class for making hp bar and I have two players in my game. My first player's hp bar was fine with decreasing health from the right side but I want the second player's hp bar to decrease from the left side. How can I make it ?
Here is my code for making hp bar. For your information Thank you (:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | public class HealthCounter extends Actor { int health = 180 ; int healthBarWidth = 180 ; int healthBarHeight = 16 ; GreenfootImage hp; public void act() { update(); } public void update(){ setImage( new GreenfootImage(healthBarWidth + 2 ,healthBarHeight + 2 )); hp = getImage(); hp.setColor(Color.WHITE); hp.drawRect( 0 , 0 , healthBarWidth + 1 , healthBarHeight + 1 ); //when health is less than 80, become red. if (health < 80 ){ hp.setColor(Color.RED); } else { //the default color is green hp.setColor(Color.GREEN); } hp.fillRect( 1 , 1 , health, healthBarHeight); } public void loseHealth(){ health = health - 10 ; } } |