Compare commits
No commits in common. "b3e6a3965b902719c6c302c9a2fb35fbe9b6f389" and "b16b429bc84b2e1cb3b29735b3fe63759ec6751b" have entirely different histories.
b3e6a3965b
...
b16b429bc8
@ -19,21 +19,15 @@ class SourceCollector:
|
|||||||
self.end_pos = None
|
self.end_pos = None
|
||||||
self.path = []
|
self.path = []
|
||||||
self.node_path = []
|
self.node_path = []
|
||||||
self.boss_pos = None
|
|
||||||
self.lock_pos = None
|
|
||||||
if self.filename:
|
if self.filename:
|
||||||
self.maze = []
|
self.maze = []
|
||||||
with open(f"{self.filename}",'r') as f:
|
with open(f"{self.filename}",'r') as f:
|
||||||
reader = csv.reader(f)
|
reader = csv.reader(f)
|
||||||
for idx,row in enumerate(reader):
|
for row in reader:
|
||||||
t = []
|
t = []
|
||||||
for idy,i in enumerate(row):
|
for i in row:
|
||||||
if i.startswith('b'):
|
if i.startswith('b') or i.startswith('l'):
|
||||||
t.append('0')
|
t.append('0')
|
||||||
self.boss_pos = (idx,idy)
|
|
||||||
elif i.startswith('l'):
|
|
||||||
t.append('0')
|
|
||||||
self.lock_pos = (idx,idy)
|
|
||||||
else:
|
else:
|
||||||
t.append(i)
|
t.append(i)
|
||||||
self.maze.append(t)
|
self.maze.append(t)
|
||||||
@ -148,7 +142,7 @@ class SourceCollector:
|
|||||||
children = sn.children[:]
|
children = sn.children[:]
|
||||||
for child in children:
|
for child in children:
|
||||||
self.dfs(child)
|
self.dfs(child)
|
||||||
if self.colNums < 11:
|
|
||||||
children.sort(key=lambda c: len(c.path))
|
children.sort(key=lambda c: len(c.path))
|
||||||
cur = None
|
cur = None
|
||||||
for idx, child in enumerate(children):
|
for idx, child in enumerate(children):
|
||||||
@ -210,7 +204,10 @@ class SourceCollector:
|
|||||||
if item == self.path[idx-1]:
|
if item == self.path[idx-1]:
|
||||||
del self.path[idx]
|
del self.path[idx]
|
||||||
|
|
||||||
|
if self.path and self.end_pos and self.path[-1] != self.end_pos:
|
||||||
|
bfs_tail = self.bfs_path(self.path[-1], self.end_pos)
|
||||||
|
if bfs_tail:
|
||||||
|
self.path.extend(bfs_tail[1:])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
135
wan.py
135
wan.py
@ -1,135 +0,0 @@
|
|||||||
import pygame
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
|
|
||||||
# 配置
|
|
||||||
SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600
|
|
||||||
BOSS_IMG = 'boss.png' # 替换为你的boss图片路径
|
|
||||||
SKILL_IMG = 'skill.png' # 替换为你的技能图片路径
|
|
||||||
FPS = 60
|
|
||||||
|
|
||||||
# 震动参数
|
|
||||||
def shake_pos(x, y, frame):
|
|
||||||
if frame % 2 == 0:
|
|
||||||
return x + 5, y
|
|
||||||
else:
|
|
||||||
return x - 5, y
|
|
||||||
|
|
||||||
def draw_health_bar(screen, x, y, w, h, hp, max_hp):
|
|
||||||
pygame.draw.rect(screen, (180, 0, 0), (x, y, w, h))
|
|
||||||
pygame.draw.rect(screen, (0, 220, 0), (x, y, int(w * hp / max_hp), h))
|
|
||||||
pygame.draw.rect(screen, (0, 0, 0), (x, y, w, h), 2)
|
|
||||||
|
|
||||||
class Skill:
|
|
||||||
def __init__(self, idx, dmg, img):
|
|
||||||
self.idx = idx
|
|
||||||
self.dmg = dmg
|
|
||||||
self.img = img
|
|
||||||
self.x = 0
|
|
||||||
self.y = SCREEN_HEIGHT // 2
|
|
||||||
self.active = True
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
self.x += 20
|
|
||||||
if self.x > SCREEN_WIDTH:
|
|
||||||
self.active = False
|
|
||||||
|
|
||||||
def draw(self, screen):
|
|
||||||
screen.blit(self.img, (self.x, self.y))
|
|
||||||
|
|
||||||
class Boss:
|
|
||||||
def __init__(self, img, hp):
|
|
||||||
self.img = img
|
|
||||||
self.hp = hp
|
|
||||||
self.max_hp = hp
|
|
||||||
self.x = SCREEN_WIDTH - img.get_width() - 50
|
|
||||||
self.y = SCREEN_HEIGHT // 2 - img.get_height() // 2
|
|
||||||
self.shake_frame = 0
|
|
||||||
self.shake = False
|
|
||||||
|
|
||||||
def hit(self, dmg):
|
|
||||||
self.hp = max(0, self.hp - dmg)
|
|
||||||
self.shake = True
|
|
||||||
self.shake_frame = 10
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
if self.shake:
|
|
||||||
self.shake_frame -= 1
|
|
||||||
if self.shake_frame <= 0:
|
|
||||||
self.shake = False
|
|
||||||
|
|
||||||
def draw(self, screen):
|
|
||||||
if self.shake:
|
|
||||||
x, y = shake_pos(self.x, self.y, self.shake_frame)
|
|
||||||
else:
|
|
||||||
x, y = self.x, self.y
|
|
||||||
screen.blit(self.img, (x, y))
|
|
||||||
draw_health_bar(screen, x, y - 30, 200, 20, self.hp, self.max_hp)
|
|
||||||
|
|
||||||
|
|
||||||
def main(boss_hp, skill_seq):
|
|
||||||
pygame.init()
|
|
||||||
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
|
||||||
pygame.display.set_caption('自动打Boss')
|
|
||||||
clock = pygame.time.Clock()
|
|
||||||
boss_img = pygame.image.load(BOSS_IMG).convert_alpha()
|
|
||||||
skill_img = pygame.image.load(SKILL_IMG).convert_alpha()
|
|
||||||
boss = Boss(boss_img, boss_hp)
|
|
||||||
skills = []
|
|
||||||
skill_idx = 0
|
|
||||||
running = True
|
|
||||||
skill_cooldown = 0
|
|
||||||
font = pygame.font.SysFont(None, 36)
|
|
||||||
|
|
||||||
while running:
|
|
||||||
for event in pygame.event.get():
|
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
running = False
|
|
||||||
|
|
||||||
screen.fill((220, 220, 255))
|
|
||||||
boss.update()
|
|
||||||
boss.draw(screen)
|
|
||||||
|
|
||||||
# 技能释放
|
|
||||||
if skill_idx < len(skill_seq) and skill_cooldown == 0:
|
|
||||||
s = skill_seq[skill_idx]
|
|
||||||
skills.append(Skill(s['first'], s['second'], skill_img))
|
|
||||||
skill_cooldown = 30 # 帧数间隔
|
|
||||||
skill_idx += 1
|
|
||||||
if skill_cooldown > 0:
|
|
||||||
skill_cooldown -= 1
|
|
||||||
|
|
||||||
# 技能动画
|
|
||||||
for skill in skills:
|
|
||||||
if skill.active:
|
|
||||||
skill.update()
|
|
||||||
skill.draw(screen)
|
|
||||||
# 判断是否击中boss
|
|
||||||
if skill.x + skill.img.get_width() > boss.x and boss.hp > 0:
|
|
||||||
boss.hit(skill.dmg)
|
|
||||||
skill.active = False
|
|
||||||
# 移除无效技能
|
|
||||||
skills = [s for s in skills if s.active]
|
|
||||||
|
|
||||||
# 显示血量数字
|
|
||||||
hp_text = font.render(f'Boss HP: {boss.hp}/{boss.max_hp}', True, (0,0,0))
|
|
||||||
screen.blit(hp_text, (50, 30))
|
|
||||||
|
|
||||||
pygame.display.flip()
|
|
||||||
clock.tick(FPS)
|
|
||||||
if boss.hp <= 0 and not skills:
|
|
||||||
time.sleep(1)
|
|
||||||
running = False
|
|
||||||
pygame.quit()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
# 示例:boss血量1000,技能序列
|
|
||||||
boss_hp = 1000
|
|
||||||
skill_seq = [
|
|
||||||
{'first': 0, 'second': 120},
|
|
||||||
{'first': 1, 'second': 200},
|
|
||||||
{'first': 2, 'second': 150},
|
|
||||||
{'first': 3, 'second': 300},
|
|
||||||
{'first': 4, 'second': 250},
|
|
||||||
]
|
|
||||||
main(boss_hp, skill_seq)
|
|
Loading…
Reference in New Issue
Block a user