我在学习使用pygame写游戏,想给游戏增加一个更换角色的选择,但游戏不报错也不出现效果,代码如下:
character_data = {
'GreenNinja': {'cooldown': 100, 'speed': 15, 'graphic': '../graphics/GreenNinja/'},
'player': {'cooldown': 400, 'speed': 5, 'graphic': '../graphics/player/'}}
self.character_index = 1
self.can_switch_character = True
self.character_switch_time = None
self.character = list(character_data.keys())[self.character_index]
self.switch_character_cooldown = 200
self.speed = character_data[self.character]['speed']
self.character_graphic = character_data[self.character]['graphic']
# self.character_path = f'../graphics/{self.character}/'
# def import_player_assets(self):
self.animations = {'up': [], 'down': [], 'left': [], 'right': [],
'right_idle': [], 'left_idle': [], 'up_idle': [], 'down_idle': [],
'right_attack': [], 'left_attack': [], 'up_attack': [], 'down_attack': []}
for animation in self.animations.keys():
full_path = self.character_graphic + animation
self.animations[animation] = import_folder(full_path)
if keys[pygame.K_l] and self.can_switch_character:
self.can_switch_character = False
self.character_switch_time = pygame.time.get_ticks()
if self.character_index < len(list(character_data.keys())) - 1:
self.character_index += 1
else:
self.character_index = 0
self.character = list(character_data.keys())[self.character_index]
print(self.character, self.character_index)
当我敲击l后,我的游戏人物角色应该更改,但情况是我的角色没有更改,但是控制台有输出:
player 1
我希望可以让我的角色更改,谢谢大家