Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | import React, { useMemo } from "react"; import * as PIXI from "pixi.js"; import { KOREAN_COLORS } from "../../types/constants"; import { ResponsivePixiContainer } from "./base/ResponsivePixiComponents"; export interface HealthBarProps { readonly current: number; readonly max: number; readonly playerName: string; readonly position?: "left" | "right" | "center"; readonly x: number; readonly y: number; readonly width: number; readonly height: number; readonly screenWidth: number; readonly screenHeight: number; readonly showText?: boolean; readonly animated?: boolean; readonly showDamageIndicator?: boolean; } export const HealthBar: React.FC<HealthBarProps> = ({ current, max, playerName, position = "left", x, y, width, height, screenWidth, screenHeight, showText = true, animated = true, showDamageIndicator = true, }) => { const isMobile = screenWidth < 768; const { healthPercentage, healthStatus, displayHealth } = useMemo(() => { const percentage = max > 0 ? current / max : 0; let status: "critical" | "low" | "medium" | "high" = "high"; if (percentage <= 0.15) status = "critical"; else if (percentage <= 0.35) status = "low"; else if (percentage <= 0.65) status = "medium"; return { healthPercentage: Math.max(0, Math.min(1, percentage)), healthStatus: status, displayHealth: Math.max(0, current), }; }, [current, max]); const getHealthColor = () => { switch (healthStatus) { case "critical": return KOREAN_COLORS.ACCENT_RED; case "low": return KOREAN_COLORS.ACCENT_GOLD; case "medium": return KOREAN_COLORS.ACCENT_CYAN; default: return KOREAN_COLORS.ACCENT_GREEN; } }; // Enhanced gradient for better visual appeal const getHealthGradient = () => { if (healthPercentage > 0.5) { return [KOREAN_COLORS.ACCENT_GREEN, KOREAN_COLORS.ACCENT_CYAN]; } else if (healthPercentage > 0.25) { return [KOREAN_COLORS.ACCENT_GOLD, KOREAN_COLORS.ACCENT_GREEN]; } else { return [KOREAN_COLORS.ACCENT_RED, KOREAN_COLORS.ACCENT_GOLD]; } }; const isRightAligned = position === "right"; const isCenterAligned = position === "center"; // Animation states for enhanced visuals const pulseAnimation = animated ? Math.sin(Date.now() * 0.005) * 0.1 + 0.9 : 1; const damageFlash = showDamageIndicator && healthStatus === "critical" ? Math.sin(Date.now() * 0.01) * 0.3 + 0.7 : 1; return ( <ResponsivePixiContainer x={x} y={y} screenWidth={screenWidth} screenHeight={screenHeight} data-testid={`health-bar-${position}`} > {/* Player Name with enhanced styling */} {showText && ( <pixiText text={playerName} style={{ fontSize: isMobile ? 12 : 14, fill: KOREAN_COLORS.TEXT_PRIMARY, fontWeight: "bold", fontFamily: "Noto Sans KR", align: isRightAligned ? "right" : isCenterAligned ? "center" : "left", dropShadow: { color: KOREAN_COLORS.BLACK_SOLID, blur: 2, distance: 2, }, }} x={isRightAligned ? width : isCenterAligned ? width / 2 : 0} y={0} anchor={ isRightAligned ? { x: 1, y: 0 } : isCenterAligned ? { x: 0.5, y: 0 } : { x: 0, y: 0 } } data-testid={`health-bar-name-${position}`} /> )} {/* Enhanced Health Bar Container */} <pixiContainer x={0} y={showText ? (isMobile ? 20 : 25) : 5} data-testid={`health-bar-container-${position}`} > {/* Background with Korean pattern */} <pixiGraphics draw={(g) => { g.clear(); const barHeight = height - (showText ? (isMobile ? 25 : 30) : 5); // Main background g.fill({ color: KOREAN_COLORS.UI_BACKGROUND_DARK, alpha: 0.9 }); g.roundRect(0, 0, width, barHeight, 4); g.fill(); // Korean-style decorative pattern g.stroke({ width: 1, color: KOREAN_COLORS.ACCENT_GOLD, alpha: 0.3, }); for (let i = 0; i < width; i += 20) { g.moveTo(i, 0); g.lineTo(i + 10, barHeight / 2); g.lineTo(i, barHeight); } g.stroke(); // Border with enhanced styling g.stroke({ width: 2, color: KOREAN_COLORS.ACCENT_GOLD, alpha: 0.8, }); g.roundRect(0, 0, width, barHeight, 4); g.stroke(); }} data-testid={`health-bar-background-${position}`} /> {/* Enhanced Health Fill with gradient effect */} <pixiGraphics draw={(g) => { g.clear(); const barHeight = height - (showText ? (isMobile ? 25 : 30) : 5); const fillWidth = width * healthPercentage; if (fillWidth > 0) { // Gradient health fill using the enhanced gradient const [startColor, endColor] = getHealthGradient(); const gradient = new PIXI.FillGradient(0, 0, fillWidth, 0); gradient.addColorStop(0, startColor); gradient.addColorStop(1, endColor); g.fill(gradient); if (isRightAligned) { // Fill from right for player 2 g.roundRect(width - fillWidth, 0, fillWidth, barHeight, 4); } else { // Fill from left for player 1 g.roundRect(0, 0, fillWidth, barHeight, 4); } g.fill(); // Enhanced shine effect with animation g.fill({ color: 0xffffff, alpha: 0.3 * (animated ? pulseAnimation : 1), }); const shineWidth = fillWidth * 0.6; const shineHeight = barHeight * 0.4; if (isRightAligned) { g.roundRect( width - shineWidth - 4, 2, shineWidth, shineHeight, 2 ); } else { g.roundRect(4, 2, shineWidth, shineHeight, 2); } g.fill(); } }} data-testid={`health-bar-fill-${position}`} /> {/* Enhanced damage indicator effects */} {showDamageIndicator && healthStatus === "critical" && ( <pixiGraphics draw={(g) => { g.clear(); // Pulsing red warning effect g.stroke({ width: 3, color: KOREAN_COLORS.ACCENT_RED, alpha: 0.8 * damageFlash, }); g.roundRect( -3, -3, width + 6, height - (showText ? (isMobile ? 21 : 26) : 1), 7 ); g.stroke(); // Additional warning flashes g.fill({ color: KOREAN_COLORS.ACCENT_RED, alpha: 0.1 * damageFlash, }); g.roundRect( 0, 0, width, height - (showText ? (isMobile ? 25 : 30) : 5), 4 ); g.fill(); }} data-testid={`health-bar-critical-effect-${position}`} /> )} {/* Enhanced health segments with Korean aesthetic */} <pixiGraphics draw={(g) => { g.clear(); const barHeight = height - (showText ? (isMobile ? 25 : 30) : 5); // Traditional Korean division markers g.stroke({ width: 1, color: KOREAN_COLORS.ACCENT_GOLD, alpha: 0.4, }); const segments = 4; const segmentWidth = width / segments; for (let i = 1; i < segments; i++) { const segmentX = segmentWidth * i; // Vertical divider g.moveTo(segmentX, 2); g.lineTo(segmentX, barHeight - 2); // Korean-style decorative marks g.circle(segmentX, barHeight / 2, 2); } g.stroke(); }} data-testid={`health-bar-segments-${position}`} /> </pixiContainer> {/* Enhanced Health Text with better positioning */} {showText && ( <pixiText text={`${Math.ceil(displayHealth)} / ${max}`} style={{ fontSize: isMobile ? 10 : 12, fill: getHealthColor(), fontWeight: "bold", align: isRightAligned ? "right" : isCenterAligned ? "center" : "left", dropShadow: { color: KOREAN_COLORS.BLACK_SOLID, blur: 1, distance: 1, }, }} x={isRightAligned ? width : isCenterAligned ? width / 2 : 0} y={height - (isMobile ? 12 : 15)} anchor={ isRightAligned ? { x: 1, y: 0 } : isCenterAligned ? { x: 0.5, y: 0 } : { x: 0, y: 0 } } data-testid={`health-bar-text-${position}`} /> )} {/* Enhanced Korean health status with martial arts terminology */} {showText && ( <pixiText text={ healthStatus === "critical" ? "위험 - 기절 직전" : healthStatus === "low" ? "부상 - 약한 상태" : healthStatus === "medium" ? "보통 - 전투 가능" : "건강 - 최상 컨디션" } style={{ fontSize: isMobile ? 7 : 9, fill: KOREAN_COLORS.TEXT_SECONDARY, fontFamily: "Noto Sans KR", align: isRightAligned ? "right" : isCenterAligned ? "center" : "left", fontStyle: "italic", }} x={isRightAligned ? width - 2 : isCenterAligned ? width / 2 : 2} y={showText ? (isMobile ? 22 : 27) : 7} anchor={ isRightAligned ? { x: 1, y: 0 } : isCenterAligned ? { x: 0.5, y: 0 } : { x: 0, y: 0 } } data-testid={`health-bar-status-${position}`} /> )} {/* Ki/Energy indicator for martial arts theme */} {healthPercentage > 0.8 && animated && ( <pixiGraphics draw={(g) => { g.clear(); g.fill({ color: KOREAN_COLORS.ACCENT_GREEN, alpha: 0.3 * Math.sin(Date.now() * 0.008) + 0.3, }); g.circle( isRightAligned ? width - 10 : 10, (showText ? (isMobile ? 22 : 27) : 7) + 5, 3 ); g.fill(); }} data-testid={`health-bar-ki-indicator-${position}`} /> )} </ResponsivePixiContainer> ); }; export default HealthBar; |