Вылезает ошибка:TypeError: argument 1 must be pygame.Surface, not int.Помогите исправить
import pygame
import random
pygame.init()
display_width = 800
display_height = 600
display = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption("Dino")
cactus_img = [pygame.image.load("кактус 0.png"), pygame.image.load("кактус 1.png"),
pygame.image.load("кактус 2.png")]
cactus_option = [28, 430, 35, 430, 55, 449]
class Cactus():
def __init__(self, x ,y, width, speed, image):
self.x = x
self.y = y
self.wigth = width
self.speed = speed
self.image = image
def move(self):
if self.x >= self.wigth:
display.blit(self.image, (self.x, self.y))
# pygame.draw.rect(display, (255, 10, 25), (self.x, self.y, self.wigth, self.height))
self.x -= self.speed
return True
else:
self.x = display_width -50
return False
def return_self(self, radius, y, width, image):
self.x = radius
self.y = y
self.wigth = width
self.image = image
display.blit(self.image, (self.x, self.y))
user_width = 60
user_height = 100
user_x = display_width // 3
user_y = display_height - user_height - 100
cactus_width = 30
cactus_height = 80
cactus_x = display_width - 50
cactus_y = display_height - cactus_height - 100
clock = pygame.time.Clock()
make_jump = False
jump_counter = 30
def run_game():
global make_jump
game = True
land = pygame.image.load('поле.png')
cactus_arr = []
create_cactus_arr(cactus_arr)
while game:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
keys = pygame.key.get_pressed()
if keys[pygame.K_SPACE]:
make_jump = True
if make_jump:
jump()
display.blit(land, (0, 0))
draw_array(cactus_arr)
pygame.draw.rect(display, (00, 255, 00), (user_x, user_y, user_width, user_height))
pygame.display.update()
clock.tick(30)
def jump():
global user_y, jump_counter, make_jump
if jump_counter >= -28 :
user_y -= jump_counter // 3
jump_counter -= 1
else:
jump_counter = 30
make_jump = False
def create_cactus_arr(array):
choice = random.randrange(0, 3)
img = cactus_img[choice]
width = cactus_option[choice * 2]
height = cactus_option[choice * 2 + 1]
array.append(Cactus(display_width - 50, height, width, img, 3))
choice = random.randrange(0, 3)
img = cactus_img[choice]
width = cactus_option[choice * 2]
height = cactus_option[choice * 2 + 1]
array.append(Cactus(display_width + 200, height, width, img, 3))
choice = random.randrange(0, 3)
img = cactus_img[choice]
width = cactus_option[choice * 2]
height = cactus_option[choice * 2 + 1]
array.append(Cactus(display_width + 500, height, width, img, 3))
def find_radius(array):
maximum = max(array[0].x, array[1].x ,array[2].x)
if maximum < display_width:
radius = display_width
if radius - maximum < 50:
radius += 150
else:
radius = maximum
choice = random.randrange(0, 5)
if choice == 0:
radius += random.randrange(10, 15)
else:
radius += random.randrange(200, 350)
return radius
def draw_array(array):
for cactus in array:
check = cactus.move()
if not check:
radius = find_radius(array)
choice = random.randrange(0, 3)
img = cactus_img[choice]
width = cactus_option[choice * 2]
height = cactus_option[choice * 2 + 1]
cactus.return_self(radius, height, width, img)
run_game()
Ответы (1 шт):
Автор решения: Koliqa
→ Ссылка
В create_cactus_arr (в array.append(Cactus(...))) ты перепутал speed и img (сравни то что ты передаешь в класс Cactus, и что он должен принимать)