health-bar.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use client";
  2. import { useEditorStore } from "@/lib/store";
  3. import { useIsMobile } from "@/lib/use-mobile";
  4. export function HealthBar() {
  5. const health = useEditorStore((s) => s.health);
  6. const shield = useEditorStore((s) => s.shield);
  7. const maxHealth = useEditorStore((s) => s.maxHealth);
  8. const maxShield = useEditorStore((s) => s.maxShield);
  9. const isMobile = useIsMobile();
  10. const healthPct = (health / maxHealth) * 100;
  11. const shieldPct = (shield / maxShield) * 100;
  12. return (
  13. <div
  14. className={`absolute ${isMobile ? "top-14 left-3" : "bottom-4 left-4"} z-10 flex flex-col gap-1.5 pointer-events-none`}
  15. >
  16. {/* Shield bar */}
  17. <div className="flex items-center gap-2">
  18. <div className="text-[10px] text-blue-400 w-5 text-right font-mono">
  19. {Math.round(shield)}
  20. </div>
  21. <div
  22. className={`${isMobile ? "w-28" : "w-40"} h-2 bg-[#1a1a1a] rounded-full overflow-hidden`}
  23. >
  24. <div
  25. className="h-full bg-gradient-to-r from-blue-600 to-blue-400 transition-all duration-300"
  26. style={{ width: `${shieldPct}%` }}
  27. />
  28. </div>
  29. </div>
  30. {/* Health bar */}
  31. <div className="flex items-center gap-2">
  32. <div
  33. className={`text-[10px] w-5 text-right font-mono ${
  34. health < 30 ? "text-red-400 animate-pulse-low" : "text-green-400"
  35. }`}
  36. >
  37. {Math.round(health)}
  38. </div>
  39. <div
  40. className={`${isMobile ? "w-28" : "w-40"} h-2 bg-[#1a1a1a] rounded-full overflow-hidden`}
  41. >
  42. <div
  43. className={`h-full transition-all duration-300 ${
  44. health < 30
  45. ? "bg-gradient-to-r from-red-600 to-red-400 animate-pulse-low"
  46. : "bg-gradient-to-r from-green-600 to-green-400"
  47. }`}
  48. style={{ width: `${healthPct}%` }}
  49. />
  50. </div>
  51. </div>
  52. </div>
  53. );
  54. }