import pygame
import sys

pygame.init()
W, H = 1000, 700
screen = pygame.display.set_mode((W, H))
pygame.display.set_caption("三角洲风格界面")
clock = pygame.time.Clock()

# 配色（三角洲冷青战术色）
BG = (8, 10, 14)
LINE_CYAN = (0, 210, 200)
DARK_CYAN = (0, 90, 90)
RED = (200, 40, 40)
WHITE = (220, 225, 230)
GRAY = (100, 110, 120)

# 重点修改：用 None 代替字体名称，解决这个编辑器的sysfont报错
font_small = pygame.font.Font(None, 18)
font_mid = pygame.font.Font(None, 24)
font_big = pygame.font.Font(None, 32)

# 游戏数据
hp = 82
armor = 65
ammo_cur = 24
ammo_max = 30
ammo_back = 112
angle = 0

# 按钮
btn_start = pygame.Rect(420, 480, 160, 48)
btn_setting = pygame.Rect(420, 550, 160, 48)

def draw_hud():
    # 四角三角装饰（三角洲标志性边角）
    # 左上
    pygame.draw.line(screen, LINE_CYAN, (20, 20), (70, 20), 2)
    pygame.draw.line(screen, LINE_CYAN, (20, 20), (20, 70), 2)
    # 右上
    pygame.draw.line(screen, LINE_CYAN, (W-20, 20), (W-70, 20), 2)
    pygame.draw.line(screen, LINE_CYAN, (W-20, 20), (W-20, 70), 2)
    # 左下
    pygame.draw.line(screen, LINE_CYAN, (20, H-20), (70, H-20), 2)
    pygame.draw.line(screen, LINE_CYAN, (20, H-20), (20, H-70), 2)
    # 右下
    pygame.draw.line(screen, LINE_CYAN, (W-20, H-20), (W-70, H-20), 2)
    pygame.draw.line(screen, LINE_CYAN, (W-20, H-20), (W-20, H-70), 2)

    # 底部血条+护甲
    # 血条框
    pygame.draw.rect(screen, GRAY, (60, H-90, 220, 22), 2)
    pygame.draw.rect(screen, RED, (62, H-88, 216 * hp/100, 18))
    hp_text = font_small.render(f"HP {hp}/100", True, WHITE)
    screen.blit(hp_text, (60, H-115))

    # 护甲条
    pygame.draw.rect(screen, GRAY, (300, H-90, 180, 22), 2)
    pygame.draw.rect(screen, LINE_CYAN, (302, H-88, 176 * armor/100, 18))
    armor_text = font_small.render(f"护甲 {armor}/100", True, WHITE)
    screen.blit(armor_text, (300, H-115))

    # 右下角弹药
    ammo_text = font_big.render(f"{ammo_cur}/{ammo_max}", True, WHITE)
    back_text = font_mid.render(f"+{ammo_back}", True, GRAY)
    screen.blit(ammo_text, (W - 160, H - 100))
    screen.blit(back_text, (W - 80, H - 85))

    # 顶部方位罗盘
    cx, cy = W//2, 60
    pygame.draw.circle(screen, DARK_CYAN, (cx, cy), 42, 2)
    dir_text = font_small.render("N 0°", True, LINE_CYAN)
    screen.blit(dir_text, (cx-22, cy-10))

    # 中心准星
    cxm, cym = W//2, H//2
    pygame.draw.line(screen, LINE_CYAN, (cxm-14, cym), (cxm-5, cym), 2)
    pygame.draw.line(screen, LINE_CYAN, (cxm+5, cym), (cxm+14, cym), 2)
    pygame.draw.line(screen, LINE_CYAN, (cxm, cym-14), (cxm, cym-5), 2)
    pygame.draw.line(screen, LINE_CYAN, (cxm, cym+5), (cxm, cym+14), 2)
    pygame.draw.circle(screen, LINE_CYAN, (cxm, cym), 2, 0)

def draw_button(rect, text, hover):
    col = LINE_CYAN if hover else DARK_CYAN
    pygame.draw.rect(screen, col, rect, 2)
    t = font_mid.render(text, True, WHITE)
    tr = t.get_rect(center=rect.center)
    screen.blit(t, tr)

running = True
while running:
    mouse = pygame.mouse.get_pos()
    click = False
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            click = True

    screen.fill(BG)
    draw_hud()

    # 按钮判断
    hover_start = btn_start.collidepoint(mouse)
    hover_set = btn_setting.collidepoint(mouse)
    draw_button(btn_start, "开始对局", hover_start)
    draw_button(btn_setting, "设置", hover_set)

    if click:
        if hover_start:
            print("开始对局！")
        if hover_set:
            print("打开设置")

    pygame.display.flip()
    clock.tick(60)

pygame.quit()
sys.exit()
