/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Sprites;

import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;

/**
 *
 * @author Ruslan
 */
public class HealthBar extends Group {

    private boolean didCheatToIncreaseHealth;
    
    private double health, initialHealth;
    private Rectangle greenBar, redBar;
    private double widthBar;
    
    public double getHealth() {
        
        return health;
        
    }
    
    public HealthBar(double health, double x, double y, double width, double height) {
        
        super();
        this.health = health;
        this.initialHealth = health;
        this.widthBar = width;
        this.initRectangles(x, y, width, height);
        
    }
    
    private void initRectangles(double x, double y, double width, double height) {
                
        redBar = new Rectangle();
        redBar.setFill(Color.RED);
        redBar.setTranslateX(x);
        redBar.setTranslateY(y);
        redBar.setHeight(height);
        redBar.setWidth(width);
        
        greenBar = new Rectangle();       
        greenBar.setFill(Color.GREEN);
        greenBar.setTranslateX(x);
        greenBar.setTranslateY(y);
        greenBar.setHeight(height);
        greenBar.setWidth(width);
        
        // Done in this very specific order for a reason -
        // creates a static red bar. Green bar is overlayed.
        // As green shrinks, red grows withou need for gross math. yay!
        this.getChildren().add(redBar);
        this.getChildren().add(greenBar);
        
    }
    
    public void decrementHealth(double amount) {
        
        this.health -= amount;
        readjustSizeOfRectangles(amount);
                
    }
    
    public void instantDeath() {
        
        this.health = 0;
        this.readjustSizeOfRectangles(-1.0);
        
    }

    private void readjustSizeOfRectangles(double amountDecrement) {

        double percent;
        
        if (amountDecrement == -1.0) {
            
            // Collided with enemy, instant loss
            percent = 0.0;
            
        }
        
        else {
            
            percent = health / initialHealth;
            
        }

        greenBar.setWidth(percent * widthBar);
    
    }
    
    
    
}

@@ -733,32 +733,79 @@
 ealth = health;%0A
+        this.didCheatToIncreaseHealth = false;%0A
         this.ini
@@ -922,24 +922,542 @@
 %0A    %7D%0A    %0A
+    public void decrementHealth(double amount) %7B%0A        %0A        this.health -= amount;%0A        readjustSizeOfRectangles(amount);%0A                %0A    %7D%0A    %0A    public void instantDeath() %7B%0A        %0A        if (!didCheatToIncreaseHealth) %7B%0A            %0A            this.health = 0;%0A            this.readjustSizeOfRectangles(-1.0);%0A            %0A        %7D%0A%0A    %7D%0A    %0A    public void infiniteHealth() %7B%0A        %0A        this.health = Double.MAX_VALUE;%0A        this.didCheatToIncreaseHealth = true;%0A        %0A    %7D%0A    %0A
     private 
@@ -2288,273 +2288,112 @@
    p
-ublic void decrementHealth(double amount) %7B%0A        %0A        this.health -= amount;%0A        readjustSizeOfRectangles(amount);%0A                %0A    %7D%0A    %0A    public void instantDeath() %7B%0A        %0A        this.health = 0;%0A        this.readjustSizeOfRectangles(-1.0);
+rivate void readjustSizeOfRectangles(double amountDecrement) %7B%0A%0A        if (!didCheatToIncreaseHealth) %7B
 %0A   
@@ -2401,85 +2401,17 @@
     
-%0A
     
-%7D%0A
 %0A    
-private void readjustSizeOfRectangles(double amountDecrement) %7B%0A%0A
     
@@ -2443,24 +2443,28 @@
    %0A        
+    
 if (amountDe
@@ -2478,39 +2478,31 @@
  == -1.0) %7B%0A
-      
+%0A
       
-%0A  
           //
@@ -2540,32 +2540,36 @@
 oss%0A            
+    
 percent = 0.0;%0A 
@@ -2567,29 +2567,21 @@
  = 0.0;%0A
-        
+%0A
     
-%0A
         
@@ -2582,24 +2582,25 @@
       %7D%0A
+%0A
         
 %0A       
@@ -2587,29 +2587,24 @@
  %7D%0A%0A        
-%0A    
     else %7B%0A 
@@ -2602,31 +2602,23 @@
  else %7B%0A
-      
+%0A
       
-%0A  
         
@@ -2649,24 +2649,25 @@
 tialHealth;%0A
+%0A
             
@@ -2670,28 +2670,23 @@
     
+%7D%0A
 %0A      
-  %7D%0A%0A
       
-  
 gree
@@ -2724,32 +2724,164 @@
 r);%0A    
-%0A
+        %0A  
     
+  
 %7D%0A    
+ 
+   
 %0A    
+    else %7B%0A            %0A            greenBar.setWidth(widthBar);%0A            %0A        %7D%0A        %0A        %0A    %0A    %7D
 %0A    %0A%7D%0A

refactor of healthBar class