【Python】毕设 仿PVZ 23.3.27

进度

  1. 实现右键铲除植物

  2. 实现点击1、2、3选择植物并更新卡槽箭头

# 原理很简单,实现起来有些复杂,以后看情况进行优化吧
mouse_pressed = [None, False, False, False]

# 点击事件
elif event.type == pygame.KEYDOWN:
    if 49 <= event.key <= 49+2:
        gameManager.check_key(event.key-49)
elif event.type == pygame.MOUSEBUTTONDOWN:
    mouse_pressed[event.button] = True
elif event.type == pygame.MOUSEBUTTONUP:
    mouse_pressed[event.button] = False
    mouse_pos = pygame.mouse.get_pos()
    gameManager.check_click(mouse_pos, event.button)

# 控制系统的改动
def check_click(self, click_pos, click_type):
    # 点击的是卡槽
    if click_type == 1 and click_pos[1] <= Benchmark[1]:
        (a, b) = self.seedbank.cards_BM
        (x, y) = click_pos
        if a <= x and b <= y <= b + 70:
            self.seedbank.nowpt = (x - a) // 50

    # 点击的是草坪
    else:
        logic_pos = [(click_pos[i] - Benchmark[i]) // Cell[i] for i in range(2)]
        if 0 <= logic_pos[0] <= 8 and 0 <= logic_pos[1] <= 4:
            if click_type == 1:
                self.gameMap.deal_events(logic_pos, self.seedbank.nowpt)
            elif click_type == 3:
                self.gameMap.deal_events(logic_pos, -1)

# 地图的改动
    def deal_events(self, logic_pos, key):
        (col, row) = logic_pos
        if 0 <= key < len(Plants):
            self.all_GrRows[row].add(Plants[key], col)
        elif key == -1:
            self.all_GrRows[row].dig(col)

# 植物类添加全局变量
Plants = (PL_peashooter, PL_sunflower, PL_nut)
  1. 加入小推车,实现其静止、推动动画
# 根据逻辑,小推车是由该行的植物行控制的,在GrassRow下添加对应代码
self.LC_surf = pygame.image.load('assets/LawnCleaner.png')
self.LC_x = 0
self.LC_y = Benchmark[1]+self.row*Cell[1]

效果

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值