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()