找回密码
 中文实名注册
搜索
查看: 5|回复: 0

《炼狱残痕》(下)

[复制链接]

12

主题

109

回帖

1131

积分

金牌会员

积分
1131
发表于 昨天 20:53 | 显示全部楼层 |阅读模式

            # 碎裂平台踩踏计时
            if plat["type"] == "crumble":
                pr = pygame.Rect(plat["x"], plat["y"], plat["w"], plat["h"])
                if player_rect.colliderect(pr) and vy >= 0 and player_rect.bottom-vy <= pr.top+4:
                    plat["timer"] += 1
                if plat["timer"] >= plat["timer_max"]:
                    plat["visible"] = False

        # 平台碰撞判定
        for plat in platform_list:
            if not plat["visible"]: continue
            pr = pygame.Rect(plat["x"], plat["y"], plat["w"], plat["h"])
            if player_rect.colliderect(pr):
                if vy>0 and player_rect.bottom - vy <= pr.top + 3:
                    py = pr.top - ph
                    vy = 0
                    on_ground = True

        # 边界 & 坠落死亡
        if px < 0: px = 0
        if px > WIDTH - pw: px = WIDTH - pw
        if py > HEIGHT: game_over = True

        # 静态尖刺碰撞
        for spike in lv_data["spikes"]:
            if player_rect.colliderect(pygame.Rect(*spike)):
                game_over = True

        # ===== 激光脉冲刷新 =====
        for ls in laser_list:
            ls["timer"] += 1
            if ls["timer"] >= ls["cycle"]:
                ls["timer"] = 0
                ls["active"] = not ls["active"]
            if ls["active"]:
                laser_rect = pygame.Rect(ls["x"], ls["y"], 6, ls["h"])
                if player_rect.colliderect(laser_rect):
                    game_over = True

        # 地面巡逻怪物
        for mob in ground_mob_list:
            mob["x"] += mob["spd"] * mob["dir"]
            if mob["x"] >= mob["ox"] + mob["range"]: mob["dir"] = -1
            if mob["x"] <= mob["ox"] - mob["range"]: mob["dir"] = 1
            if player_rect.colliderect(pygame.Rect(mob["x"],mob["y"],mob["w"],mob["h"])):
                game_over = True

        # 飞行怪物
        for mob in fly_mob_list:
            mob["x"] += mob["spd"] * mob["dir"]
            if mob["x"] >= mob["ox"] + mob["range"]: mob["dir"] = -1
            if mob["x"] <= mob["ox"] - mob["range"]: mob["dir"] = 1
            if player_rect.colliderect(pygame.Rect(mob["x"],mob["y"],mob["w"],mob["h"])):
                game_over = True

        # 弹跳怪物物理
        for mob in bounce_mob_list:
            mob["y"] += mob["vy"]
            mob["vy"] += gravity
            # 地面反弹
            if mob["y"] >= mob["ox"]:
                mob["y"] = mob["ox"]
                mob["vy"] = -mob["bspd"]
            if player_rect.colliderect(pygame.Rect(mob["x"],mob["y"],mob["w"],mob["h"])):
                game_over = True

        # 终点判定
        finish_rect = pygame.Rect(*lv_data["finish"])
        if player_rect.colliderect(finish_rect):
            win_level = True

    # 关卡跳转
    if win_level and not game_complete:
        current_level += 1
        if current_level >= len(levels):
            game_complete = True
        else:
            pygame.time.delay(380)
            load_level(current_level)

    # ============ 渲染绘图 ============
    # 绘制平台
    for plat in platform_list:
        if not plat["visible"]: continue
        x,y,w,h = plat["x"],plat["y"],plat["w"],plat["h"]
        if plat["type"] == "crumble":
            # 碎裂平台闪烁警告
            alpha = 255
            if plat["timer"] > plat["timer_max"]*0.6:
                alpha = 120 if (frame_count%12 <6) else 255
            surf = pygame.Surface((w,h))
            surf.set_alpha(alpha)
            surf.fill(PLATFORM_CRUMBLE)
            screen.blit(surf, (x,y))
            pygame.draw.rect(screen, PLATFORM_TOP, (x,y,w,5))
        else:
            pygame.draw.rect(screen, PLATFORM_STATIC, (x,y+3,w,h-3))
            pygame.draw.rect(screen, PLATFORM_TOP, (x,y,w,5))

    # 尖刺
    for s in lv_data["spikes"]:
        x,y,w,h = s
        pts = [(x,y+h),(x+w//2,y),(x+w,y+h)]
        pygame.draw.polygon(screen, SPIKE_COLOR, pts)

    # 激光
    for ls in laser_list:
        if ls["active"]:
            pygame.draw.rect(screen, LASER_COLOR, (ls["x"], ls["y"], 6, ls["h"]))
            pygame.draw.rect(screen, WHITE, (ls["x"], ls["y"], 6, ls["h"]),1)

    # 地面怪物
    for mob in ground_mob_list:
        x,y,w,h = mob["x"],mob["y"],mob["w"],mob["h"]
        pygame.draw.rect(screen, GROUND_MONSTER, (x,y,w,h), border_radius=4)
        pygame.draw.circle(screen,WHITE,(x+7,y+8),2.5)
        pygame.draw.circle(screen,WHITE,(x+19,y+8),2.5)
    # 飞行怪物
    for mob in fly_mob_list:
        x,y,w,h = mob["x"],mob["y"],mob["w"],mob["h"]
        pygame.draw.ellipse(screen, FLY_MONSTER, (x,y,w,h))
        pygame.draw.circle(screen,YELLOW,(x+7,y+8),2.5)
        pygame.draw.circle(screen,YELLOW,(x+19,y+8),2.5)
    # 弹跳怪物
    for mob in bounce_mob_list:
        x,y,w,h = mob["x"],mob["y"],mob["w"],mob["h"]
        pygame.draw.circle(screen, BOUNCE_MONSTER, (x+w//2,y+h//2), w//2)
        pygame.draw.circle(screen,BLACK,(x+9,y+10),3)
        pygame.draw.circle(screen,BLACK,(x+19,y+10),3)

    # 玩家绘制
    pygame.draw.rect(screen, PLAYER_MAIN, (px,py,pw,ph), border_radius=5)
    pygame.draw.rect(screen, PLAYER_OUTLINE, (px,py,pw,ph),2,border_radius=5)
    ey = py+7
    pygame.draw.circle(screen,WHITE,(px+7,ey),3)
    pygame.draw.circle(screen,WHITE,(px+19,ey),3)
    pygame.draw.circle(screen,BLACK,(px+8,ey),1.5)
    pygame.draw.circle(screen,BLACK,(px+20,ey),1.5)

    # UI面板
    panel = pygame.Rect(8,8,175,36)
    pygame.draw.rect(screen,(0,0,0,140),panel,border_radius=6)
    pygame.draw.rect(screen,WHITE,panel,1,border_radius=6)
    txt = small_font.render(f"关卡 {current_level+1}/{len(levels)}", True, WHITE)
    screen.blit(txt,(14,12))

    # 弹窗
    if game_complete:
        ovl = pygame.Surface((WIDTH,HEIGHT))
        ovl.set_alpha(150)
        ovl.fill(BLACK)
        screen.blit(ovl,(0,0))
        t = font.render("闯过终焉炼狱!按R重来",True,YELLOW)
        screen.blit(t,t.get_rect(center=(WIDTH//2,HEIGHT//2)))
    elif win_level:
        ovl = pygame.Surface((WIDTH,HEIGHT))
        ovl.set_alpha(100)
        ovl.fill(BLACK)
        screen.blit(ovl,(0,0))
        t = font.render("炼狱通路开启!",True,WHITE)
        screen.blit(t,t.get_rect(center=(WIDTH//2,HEIGHT//2)))
    elif game_over:
        ovl = pygame.Surface((WIDTH,HEIGHT))
        ovl.set_alpha(100)
        ovl.fill(BLACK)
        screen.blit(ovl,(0,0))
        t = font.render("坠入地狱!按R重试",True,RED)
        screen.blit(t,t.get_rect(center=(WIDTH//2,HEIGHT//2)))

    pygame.display.update()

pygame.quit()
sys.exit()

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 中文实名注册

本版积分规则

快速回复 返回顶部 返回列表