|
|
# 刀光效果类
class SlashEffect:
def __init__(self, start, end):
self.start = start
self.end = end
self.alpha = 255
self.fade_speed = 10
def update(self):
self.alpha -= self.fade_speed
return self.alpha <= 0
def draw(self, win):
if self.alpha > 0:
# 创建临时表面绘制透明线条
s = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA)
color = (255, 255, 255, self.alpha)
pygame.draw.line(s, color, self.start, self.end, 3)
win.blit(s, (0, 0))
# 显示文字
def draw_text(win, text, size, x, y, color=WHITE):
font = pygame.font.SysFont("simsun", size)
text_surface = font.render(text, True, color)
text_rect = text_surface.get_rect()
text_rect.midtop = (x, y)
win.blit(text_surface, text_rect)
# 主函数
def main():
clock = pygame.time.Clock()
# 游戏变量
fruits = []
bombs = []
slashes = []
score = 0
lives = 3
spawn_timer = 0
spawn_interval = 60 # 生成水果的间隔(帧)
game_over = False
# 背景色
bg_color = (50, 50, 50)
# 主循环
running = True
mouse_down = False
last_mouse_pos = (0, 0)
while running:
clock.tick(60)
|
|