pygame坦克大战

!!!末尾附完整代码仓库!!!

由于找不到很多坦克图片,部分是自个ps画的…(略丑见谅)
敌方蓝色坦克3血,粉色2血,绿色1血,会根据坦克血量而变换颜色
我方俩坦克均2血,在坦克机体显示血条
在这里插入图片描述

1、实现双人模式。玩家有血条显示。
半血状态

2、有三款不同颜色血量的敌机,随机时间随机地点出现在地图内。

    for i in range(Settings.ENEMY_COUNT):
        direction = random.randint(0, 3)
        enemy = Enemy(Settings.ENEMY_IMAGES[direction], screen, out_time=random.randint(0, 15), hp=1)
        enemy.direction = direction
        enemies.add(enemy)
    for i in range(Settings.ENEMY_COUNT2):
        direction = random.randint(0, 3)
        enemy = Enemy(Settings.ENEMY_IMAGES2[direction], screen, out_time=random.randint(10, 25), hp=2)
        enemy.direction = direction
        enemies.add(enemy)
    for i in range(Settings.ENEMY_COUNT3):
        direction = random.randint(0, 3)
        enemy = Enemy(Settings.ENEMY_IMAGES3[direction], screen, out_time=random.randint(15, 25), hp=3)
        enemy.direction = direction
        enemies.add(enemy)

3、摧毁敌机有几率掉落加速道具,
摧毁墙体有几率掉落回血道具。

#碰撞道具
    for prop in props1:
        if pygame.sprite.collide_rect(player, prop):
            prop.kill()
            player.speed += 1
            player.temp = player.speed
            # print("i am temp"+ str(player.temp))
        if pygame.sprite.collide_rect(player2, prop):
            prop.kill()
            player2.speed += 1
            player2.temp = player2.speed
            # print("i am temp" + str(player2.temp))
    for prop in props2:
        if pygame.sprite.collide_rect(player, prop):
            prop.kill()
            player.hp = 2
        if pygame.sprite.collide_rect(player2, prop):
            prop.kill()
            player2.hp = 2

4、玩家经过河流发生减速

# 我方坦克撞墙
        if pygame.sprite.collide_rect(player, wall):
            # 不可穿越墙
            if wall.type == Settings.RED_WALL or wall.type == Settings.IRON_WALL or wall.type == Settings.home_WALL:
                player.is_hit_wall = True
                # 移出墙内
                player.move_out_wall(wall)
            elif wall.type == Settings.WATER_WALL:
                player.is_hit_wall = False
                t0 = clock.get_time()
                player.water(t0)
        if player.rect.right > wall.rect.left and player.rect.bottom > wall.rect.top and\
                player.rect.left > wall.rect.right and player.rect.top > wall.rect.bottom:
            player.water(2000)
    def water(self, t):
        self.water_time = t
        if self.water_time/1000 < 1:
            self.speed = 1
        else:
            self.speed = self.temp

码云开源仓库:https://gitee.com/a502314638/pygame-tank-battle
谢谢点赞🌹

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值