FineNerds

Health Bar

Aug 18th, 2013
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. /** Starts the health bar **/
  2.  
  3. /** Shields is equal to Current health - Maximum Health **/
  4. /** Shields is equal to Current Health - 100 (The total of the health bar) **/
  5. player.shields = player.health - player.maxHealth;
  6.  
  7. /** Makes sure shields don't go below 0 **/
  8. if(player.shields < 0)
  9. {
  10. player.shields = 0;
  11. }
  12.  
  13. /** Makes sure the player's health doesn't go negative **/
  14. if(player.health <= 0)
  15. {
  16. player.visibleHealth = 0;
  17. player.health = 0;
  18. }
  19.  
  20. /** Makes sure that the health shown doesn't exceed 100 when showing shields **/
  21. if(player.health >100)
  22. {
  23. player.visibleHealth = 100;
  24. }
  25. else if(player.health <= 100)
  26. {
  27. player.visibleHealth = player.health;
  28. }
  29.  
  30. if(player.health >100)
  31. {
  32. /** The text for when shields appear **/
  33. /** Used as an outside object to allow for barrier.length(); **/
  34. String barrier = "Cacophony Barrier: " + player.shields;
  35.  
  36. ** Checks to see if shields are at least 1 **/
  37. if(player.shields >= 1)/
  38. {
  39. d.DrawStringWithShadow(g, "" + player.visibleHealth, screenSize.width / 2 - 7, screenSize.height / 2 - 55, 0, 0, 0, 0, 0, 200);
  40. g.setColor(new Color(255, 45, 178));
  41. g.fillRect(screenSize.width / 2 - 47, screenSize.height /2 - 46, (int) player.shields, 7);
  42. g.setColor(new Color(0, 209, 255));
  43. g.fillRect(screenSize.width / 2 - 47, screenSize.height /2 - 46, (int) player.health, 7);
  44. g.setFont(d.arial);
  45. d.DrawStringWithFullDrop(g, barrier, screenSize.width / 2 - (barrier.length() *3), screenSize.height / 2 - 69, 0, 0, 0, 255, 255, 255);
  46. }
  47. else if(player.shields > 100) /** If shields are more than 100 **/
  48. {
  49. d.DrawStringWithShadow(g, "" + player.visibleHealth, screenSize.width / 2 - 7, screenSize.height / 2 - 55, 0, 0, 0, 0, 0, 200);
  50. g.setColor(new Color(255, 45, 178));
  51. g.fillRect(screenSize.width / 2 - 47, screenSize.height /2 - 46, (int) player.health - (int)player.maxHealth, 7);
  52. g.setColor(new Color(0, 209, 255));
  53. g.fillRect(screenSize.width / 2 - 47, screenSize.height /2 - 46, (int) player.health, 7);
  54. g.setFont(d.arial);
  55. d.DrawStringWithFullDrop(g, barrier, screenSize.width / 2 - (barrier.length() *3), screenSize.height / 2 - 69, 0, 0, 0, 255, 255, 255);
  56. }
  57. }
  58. else if(player.health >=75) /** Checks if the player's health is between 75 and 100 **/
  59. {
  60. d.DrawStringWithShadow(g, "" + player.visibleHealth, screenSize.width / 2 - 7, screenSize.height / 2 - 55, 0, 0, 0, 0, 0, 200);
  61. g.setColor(new Color(0, 209, 255));
  62. g.fillRect(screenSize.width / 2 - 47, screenSize.height /2 - 46, (int) player.health, 7);
  63. }
  64. else if(player.health >= 50) /** Check to see if health is between 50 and 74 **/
  65. {
  66. d.DrawStringWithShadow(g, "" + player.visibleHealth, screenSize.width / 2 - 7, screenSize.height / 2 - 55, 0, 0, 0, 0, 255, 0);
  67. g.setColor(new Color(0, 255, 0));
  68. g.fillRect(screenSize.width / 2 - 47, screenSize.height /2 - 46, (int) player.health, 7);
  69. }
  70. else if(player.health >= 25) /** Checks to see if health is between 25 and 49 **/
  71. {
  72. d.DrawStringWithShadow(g, "" + player.visibleHealth, screenSize.width / 2 - 7, screenSize.height / 2 - 55, 0, 0, 0, 255, 178, 0);
  73. g.setColor(new Color(255, 178, 0));
  74. g.fillRect(screenSize.width / 2 - 47, screenSize.height /2 - 46, (int) player.health, 7);
  75. }
  76. else if(player.health >= 1)/** Checks to see if health is between 1 and 24 **/
  77. {
  78. d.DrawStringWithShadow(g, "" + player.visibleHealth, screenSize.width / 2 - 7, screenSize.height / 2 - 55, 0, 0, 0, 255, 0, 0);
  79. g.setColor(new Color(255, 0, 0));
  80. g.fillRect(screenSize.width / 2 - 47, screenSize.height /2 - 46, (int) player.health, 7);
  81. }
Advertisement
Add Comment
Please, Sign In to add comment