鱼C论坛

 找回密码
 立即注册
查看: 2081|回复: 1

就飞机大战补给未进入循环(每三十秒投放一次)而提出的问题

[复制链接]
发表于 2021-3-15 22:16:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#附上补给模块代码
import pygame
from random import *

#超级子弹补给
class Bullet_Supply(pygame.sprite.Sprite):
    def   __init__(self,bg_size):
          pygame.sprite.Sprite.__init__(self)

          self.image = pygame.image.load("images/bullet_supply.png").convert_alpha()
          self.rect = self.image.get_rect()
          self.width,self.height = bg_size[0], bg_size[1]
          self.rect.left,self.rect.bottom = randint(0,self.width - self.rect.width),-100
          self.speed = 5
          self.active = False
          self.mask = pygame.mask.from_surface(self.image)

    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.active = False

    def reset(self):
        self.active = True
        self.rect.left, self.rect.bottom = randint(0, self.width - self.rect.width),-100

class Bomb_Supply(pygame.sprite.Sprite):
    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)

        self.image = pygame.image.load("images/bomb_supply.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.rect.left,self.rect.bottom = randint(0,self.width - self.rect.width),100
        self.speed = 5
        self.active = False
        self.mask = pygame.mask.from_surface(self.image)

    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.active = False

    def reset(self):
        self.rect.left,self.rect.bottom = randint(-36, self.width - self.rect.width), -100
        self.active = True
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-3-15 22:19:53 | 显示全部楼层
  # 补给定时器                                       
  bomb_supply = supply.Bomb_Supply(bg_size)      
  bullet_supply = supply.Bullet_Supply(bg_size)  
  SUPPLY_TIME = USEREVENT                        
  pygame.time.set_timer(SUPPLY_TIME, 30 * 1000)  
       #补给包响应                                
       elif event.type == SUPPLY_TIME:      
           supply_sound.play()               
           if supply.choice([True, False]):  
               bullet_supply.reset()         
           else:                             
               bullet_supply.reset()         
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-14 00:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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