0

I have been working on a tutorial video to recreate a space invader model, but I have ran into a bit of wall that has me confused. I am receiving an error message of "argument 1 must be pygame.Surface, not None" within code for a base class to have inherited by other classes. Within the base class we set the img = None, and then have other classes inherit and fill self.img with an Img regarding the correct img for them.

Here below is a look at the base Ship Class I have written. The error comes from the line with: window.blit(self.ship_img, (self.x, self.y))

class Ship():
  COOLDOWN = 30 

  def __init__(self, x, y, health=100):
    self.x = x 
    self.y = y 
    self.health = health 
    self.ship_img = None 
    self.laser_img = None 
    self.lasers = []
    self.laser_cool_down = 0
    
  def draw(self, window):
    window.blit(self.ship_img, (self.x, self.y))
    for laser in self.lasers: 
        laser.draw(window)

def move_lasers(self, speed, obj):
    self.cooldown()
    for laser in self.lasers:
        laser.move(speed)
        if laser.off_screen(height):
            self.lasers.remove(laser)
        elif laser.collision(obj): # check for player collision
            obj.health -= 10 
            self.laser.remove(laser)
            

  def cooldown(self):
    if self.laser_cool_down >= self.COOLDOWN:
        self.laser_cool_down = 0 
    elif self.laser_cool_down > 0:
        self.laser_cool_down += 1 
    
    
  def shoot(self):
    if self.laser_cool_down == 0: 
        laser = Laser(self.x, self.y, self.laser_img)
        self.lasers.append(laser)
        self.laser_cool_down = 1 
        
            

  def get_width(self):
    return self.ship_img.get_width()
  def get_height(self):
    return self.ship_img.get_height()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Jacob.b20
  • 3
  • 1
  • 2
    `self.ship_img = None` in `Ship.__init__`. `self.ship_image` is never set - so what do you expect? – Rabbid76 Nov 23 '21 at 18:17
  • Please read https://ericlippert.com/2014/03/05/how-to-debug-small-programs/, and try to *read* and *understand* your error messages. – Karl Knechtel Nov 23 '21 at 18:47
  • See [Python debugging tips](https://stackoverflow.com/questions/1623039/python-debugging-tips) – Rabbid76 Nov 25 '21 at 20:44

0 Answers0