How to fix my wrong image loading in pygame

I’m working on a little game project with friends using python and pygame.

Today I tried to write the weapon part in the code and everything is correct but when I’m running the code, it is loading the wrong weapons images (it is loading the character images which are in another folder…) so I checked the code many times but I dont find anything and why is it taking the character images…

(Btw we didnt designed the weapons already, I just wanted to finish the code part so that we can work on weapons design later… so I just replaced them with temporary images with number for animation)

Here is the part of the code loading the weapon images, I’ve done almost the same thing for the character images and its working perfectly:

weapon_animation_types = ["empty", "sword", "rifle"]
for weapon_animation in weapon_animation_types:
    weapon_temp_list = []
    longueur_fichier_weapon = len(os.listdir(f'img/weapons/{weapon_animation}'))
    for j in range(longueur_fichier_weapon):
        img_weapon = pygame.image.load(f'img/weapons/{weapon_animation}/{j}.png')
        img_weapon = pygame.transform.scale(img, (int(img.get_width() * scale), int(img.get_height() * scale)))
self.weapon_image = self.weapons_animations_list[self.weapon][self.weapon_frame_index]

I dont think the issue is in this part but we never know…

Here you can find the GitHub repository (which I think is more usefull to understand my issue…) of the project with the full code and the images to be loaded:

Appreciate every feedback 🙂


img_weapon = pygame.transform.scale(img, (int(img.get_width() * scale), int(img.get_height() * scale)))

Should be

img_weapon = pygame.transform.scale(img_weapon, (int(img_weapon.get_width() * scale), int(img_weapon.get_height() * scale)))

You’re re-assigning img_weapon with a scaled version of another surface, named img.