# 创建敌机定时器事件常量CREATE_ENEMY_EVENT=pygame.USEREVENT # 主程序初始化方法中设置定时器事件 - 创建敌机 1000毫秒pygame.time.set_timer(CREATE_ENEMY_EVENT,1000) """敌机精灵"""classEnemy(GameSprite):def__init__(self):# 调用父类方法 创建敌机精灵,指定图片super().__init__('./images/enemy1...
0, 450, 700)#刷新帧率,每秒60帧FRAME_PER_SECOND = 60#创建敌机的定时器常量CREATE_ENEMY_EVENT =pygame.USEREVENT#创建英雄开火事件HERO_FIRE_EVENT = pygame.USEREVENT + 1classGameSprite(pygame.sprite.Sprite):def__init__(self, image_para, speed_para=1):#父类不是object时都需要调用父类初始...
self.screen = pygame.display.set_mode(SCREEN_RECT.size) # 2.创建时钟对象 self.clock = pygame.time.Clock() # 3.创建精灵组 self.__create_speites() # 4.设置定时器 pygame.time.set_timer(CREATE_ENEMY_EVENT, 1000) pygame.time.set_timer(HERO_FIRE_EVENT, 500) def __create_speites(self)...
self.__create_sprites() # 4、设置定时器事件,每隔一秒出现一架敌机,每隔0.5秒发射一次子弹,每次连发三枚 pygame.time.set_timer(CREATE_ENEMY_EVENT, 1000) pygame.time.set_timer(HERO_FIRE_EVENT, 500) def __create_sprites(self): # 游戏坐标系:原点左上角,x轴水平向右增加,y轴水平向下增加 # 分别...
self.clock = pygame.time.Clock() # 3.调用私有方法,精灵和精灵组的创建 self.__create_sprite() # 4.创建敌机定时器 pygame.time.set_timer(CREATE_ENEMY_EVENT, 1000) # 5.创建子弹定时器 pygame.time.set_timer(HERO_FIRE_EVENT, 500) def __create_sprite(self): ...
(CREATE_ENEMY_EVENT,1000),一个是每隔0.5秒的英雄开火事件,pygme.time.set_timer(HERO_FIRE_EVENT,500),定时器放在游戏主文件PlaneGame类的初始化方法中,两个eventid在全局中定义,一个USEREVENT一个+1,然后在PlaneGame类的stargame方法中循环调用事件监听,监听用一个私有方法__event_handler,除了监听这两个事件,...
pygame.time.set_timer(CREATE_ENEMY_EVENT,1000)pygame.time.set_timer(HERO_FIRE_EVENT,500)self.enemy_group=pygame.sprite.Group()#开始游戏defstartGame(self):print("开始游戏")whileTrue:self.clock.tick(60)self.__event_handler()self.__check_collide()self.__update_sprites()pygame.display.update(...
screen.blit(hero,(150,300))#可以在所有绘制工作完成后,统一调用update方法pygame.display.update()#创造时钟对象 屏幕绘制速率clock = pygame.time.Clock()#定义飞机初始位置hero_rect = pygame.Rect(150,300,100,122)#敌机精灵创建enemy = GameSprite("./image/enemy0.png") ...
Currently, pygame.time.set_timer() has only two options, it can either keep sending events forever, or send once and stop. IMHO, it would be more useful if we had a way to send a particular amount of events, that can be easily specified ...
两种可能 1程序没有初始化,加上 pygame.init()2 pygame-ai没有安装 参考下面链接 安装