I am trying to create my own game using pygame with classes and my problem is that I cannot understand why my program is not working properly
import pygame
import time
import random
import sys
pygame.init()
screen = pygame.display.set_mode((1280, 720))
pygame.display.set_caption("this game")
class Background:
def __init__(self, x, y):
self.xpos = x
self.ypos = y
picture = pygame.image.load("C:/images/dunes.jpg")
picture = pygame.transform.scale(picture, (1280, 720))
def draw(self):
pygame.surface.Surface.blit(picture, (self.xpos, self.ypos))
class Monster:
def __init__(self, x, y):
self.xpos = x
self.ypos = y
def move_left(self):
self.xpos =- 5
def move_right(self):
self.xpos =+ 5
def jump(self):
for x in range(1, 10):
self.ypos =-1
pygame.display.show()
for x in range(1, 10):
self.ypos =+1
pygame.display.show()
picture = pygame.image.load("C:/pics/hammerhood.png")
picture = pygame.transform.scale(picture, (200, 200))
def draw(self):
pygame.surface.Surface.blit(picture, (self.xpos, self.ypos))
class enemy:
def __init__(self, x, y):
self.xpos = x
self.ypos = y
picture = pygame.image.load("C:/pics/dangler_fish.png")
picture = pygame.transform.scale(picture, (200, 200))
def teleport(self):
self.xpos = random.randint(1, 1280)
self.pos= random.randint(1, 720)
def draw(self):
pygame.surface.Surface.blit(picture, (self.xpos, self.ypos))
while True:
ice = Background(720, 360)
hammerhood = Monster(200, 500)
fish = enemy(0, 0)
fish.teleport()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if pygame.event == pygame.K_d:
hammerhood.move_right()
if pygame.event == pygame.K_a:
hammerhood.move_left()
if pygame.event == pygame.K_w:
hammerhood.jump()
hammerhood.draw()
ice.draw()
fish.draw()
what it is saying to me is, line 49, in the draw
pygame.surface.Surface.blit(picture, (self.xpos, self.ypos))
NameError: name 'picture' is not defined
I have tried everything and there is another project I copied from the internet and this has the exact same way of blitting the picture in the class but in this one, it is not working