OSDN Git Service

barが割合に応じて色変化するように
authorttwilb <ttwilb@users.sourceforge.jp>
Tue, 3 Sep 2013 08:49:04 +0000 (17:49 +0900)
committerttwilb <ttwilb@users.sourceforge.jp>
Tue, 3 Sep 2013 08:49:04 +0000 (17:49 +0900)
www/corelib/classes/EnemyCharacterClass.js
www/corelib/classes/MainCharacterClass.js

index 669f6db..e9b6485 100644 (file)
@@ -130,12 +130,21 @@ var EnemyCharacterClass = function(stage, args){
                //this.ownerStage.mainContext.strokeStyle = "rgba(0, 0, 0, 1)";
                //this.ownerStage.mainContext.font = "normal 12px sans-serif";
                //drawText(this.ownerStage.mainContext, this.HP, x, y - 20);
-               var color = "green";
+               
                var backColor = "gray";
                var thickness = 4;
                var barWidth = this.max_HP;
                if(barWidth < 16) barWidth = 16;
                var barPerHP = this.HP / this.max_HP;
+               var color = "green";
+               
+               if(barPerHP < 0.2)
+               {
+                       var backColor = "red";
+               }else if(barPerHP < 0.4)
+               {
+                       var backColor = "yellow";
+               }
                
                this.ownerStage.mainContext.fillStyle = backColor;
                this.ownerStage.mainContext.fillRect(x + (this.size.x - barWidth) / 2, y - thickness, barWidth, thickness);
index 9fcdd2a..6c1905f 100644 (file)
@@ -62,6 +62,14 @@ var MainCharacterClass = function(stage, args, isFromNetwork){
                        if(barWidth > this.size.x) barWidth = this.size.x;
                        var barPerHP = this.HP / this.max_HP;
                        
+                       if(barPerHP < 0.2)
+                       {
+                               var backColor = "red";
+                       }else if(barPerHP < 0.4)
+                       {
+                               var backColor = "yellow";
+                       }
+                       
                        this.ownerStage.mainContext.fillStyle = backColor;
                        this.ownerStage.mainContext.fillRect(x + (this.size.x - barWidth) / 2, y - thickness, barWidth, thickness);
                        this.ownerStage.mainContext.fillStyle = color;