Python: Trying to use polymorphism with pygame -


i'm trying use polymorphism in pygame project keep getting errors.

i have moveable class , objects class inherits moveable , attributeerror: 'nonetype' object has no attribute 'ypos' in game loop.

i plan on having more moveable objects in project people, houses, road signs... if can working.

class moveable:     __name = ""     __xpos = 0     __ypos = 0     __hight = 0     __width = 0     __speed = 0     __image = 0      def __init__(self, xpos, ypos, hight, width, speed, image):         self.__xpos = xpos         self.__ypos = ypos         self.__hight = hight         self.__width = width         self.__image = image      def set_xpos(self, xpos):         self.__xpos = xpos      def get_xpos(self):         return self.__xpos      # ... , other getters , setters...   class objects(moveable):      def car(xpos, ypos, width, hight, speed, image):         pygame.surface.blit(gamedisplay, image, [xpos, ypos, hight, width])  def game_loop():  game_exit = false #sets game loop false  while not game_exit: # runs game loop until game exit = true      car = objects.car(random.randrange(250, 550), -400, 60, 70, 4, pygame.image.load('car.png'))     gamedisplay.blit(backgroundimg, (0, 0)) #displays background     car.ypos += car.speed # error here ********** 

r

you need return pygame if intent.

def car(xpos, ypos, width, hight, speed, image):     return pygame.surface.blit(gamedisplay, image, [xpos, ypos, hight, width]) 

as stands, car has no return statement, assigning variable method return none, hence error trying access attribute on nonetype


Popular posts from this blog