The exact same code from my friend's windows computer does not work with my macbook and vice versa. We both get the same error, "TypeError: 'NoneType' object is not subscriptable" and the problem starts when we start importing png files. Otherwise normal code without needing the file directory works fine.
This was our tile module
import pygame
from support import import_folder
class Tile(pygame.sprite.Sprite):
def __init__(self, size, x, y):
super().__init__()
self.image = pygame.Surface((size, size))
self.rect = self.image.get_rect(topleft=(x, y))
def update(self, shift):
self.rect.x += shift
class StaticTile(Tile):
def __init__(self, size, x, y, surface):
super().__init__(size, x, y)
self.image = surface
class AnimatedTile(Tile):
def __init__(self, size, x, y, path):
super().__init__(size, x, y)
self.frames = import_folder(path)
self.frame_index = 0
self.image = self.frames[self.frame_index]
def animate(self):
self.frame_index += 0.15
if self.frame_index >= len(self.frames):
self.frame_index = 0
self.image = self.frames[int(self.frame_index)]
def update(self, shift):
self.animate()
self.rect.x += shift
This was our enemy module
import pygame
from tiles import AnimatedTile
from random import randint
class Enemy(AnimatedTile):
def __init__(self, size, x, y):
super().__init__(size, x, y, '../graphics/0/enemy/slay/1.png')
self.rect.y += size - self.image.get_size()[1]
self.speed = randint(3, 5)
def move(self):
self.rect.x += self.speed
def reverse_image(self):
if self.speed > 0:
self.image = pygame.transform.flip(self.image, True, False)
def reverse(self):
self.speed *= -1
def update(self, shift):
self.rect.x += shift
self.animate()
self.move()
self.reverse_image()
This is our first time coding a game so some help will really be appreciated. Thank you.