def input(self): if not self.attacking: keys = pygame.key.get_pressed()#检测键盘是否有输入 #键盘up or down 改变y轴的值 if keys[pygame.K_UP]: self.direction.y = -1 self.status = 'up' elif keys[pygame.K_DOWN]: self.direction.y = 1 self.status = 'down' else: self.direction.y = 0 #键盘左右键改变x轴的值 if keys[pygame.K_RIGHT]: self.direction.x = 1 self.status = 'right' elif keys[pygame.K_LEFT]: self.direction.x = -1 self.status = 'left' else: self.direction.x = 0 # 攻击键为空格 if keys[pygame.K_SPACE]: self.attacking = True self.attack_time = pygame.time.get_ticks() self.create_attack() self.weapon_attack_sound.play() # 魔法攻击使用左边Shift键 if keys[pygame.K_LSHIFT]: self.attacking = True self.attack_time = pygame.time.get_ticks() style = list(magic_data.keys())[self.magic_index] strength = list(magic_data.values())[self.magic_index]['strength'] + self.stats['magic'] cost = list(magic_data.values())[self.magic_index]['cost'] self.create_magic(style,strength,cost) #键盘Q键切换武器 if keys[pygame.K_q] and self.can_switch_weapon: self.can_switch_weapon = False self.weapon_switch_time = pygame.time.get_ticks() if self.weapon_index < len(list(weapon_data.keys())) - 1: self.weapon_index += 1 else: self.weapon_index = 0 self.weapon = list(weapon_data.keys())[self.weapon_index] #键盘E键切换魔法道具 if keys[pygame.K_e] and self.can_switch_magic: self.can_switch_magic = False self.magic_switch_time = pygame.time.get_ticks() if self.magic_index < len(list(magic_data.keys())) - 1: self.magic_index += 1 else: self.magic_index = 0 self.magic = list(magic_data.keys())[self.magic_index]
时间: 2024-04-28 15:19:19 浏览: 121
论文研究-Tissue P systems with cell separation: attacking the partition problem.pdf
这段代码是角色控制的输入函数,用于检测玩家在键盘上的输入,并根据输入改变角色的状态。如果玩家按下向上或向下箭头键,则角色的y轴方向分别变为-1或1,并相应地设置角色的状态为up或down;如果按下向左或向右箭头键,则角色的x轴方向分别变为-1或1,并相应地设置角色的状态为left或right;如果按下空格键,则角色开始攻击,并播放相应的音效;如果按下左边Shift键,则角色使用魔法攻击;如果按下Q键,则角色切换武器;如果按下E键,则角色切换魔法道具。
阅读全文