ошибка:
Traceback (most recent call last):
File "C:/DinoGame/DinoGame.py", line 92, in <module>
run_game()
File "C:/DinoGame/DinoGame.py", line 54, in run_game
draw_array(cactus_arr)
File "C:/DinoGame/DinoGame.py", line 86, in draw_array
check = cactus.move()
File "C:/DinoGame/DinoGame.py", line 29, in move
if self.x >= -self.width:
TypeError: '>=' not supported between instances of 'NoneType' and '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('DinoRun')
icon = pygame.image.load('Sprite-0001.png')
pygame.display.set_icon(icon)
usr_width = 60
usr_height = 100
usr_x =display_width//3
usr_y =display_height-100-100
clock = pygame.time.Clock()
make_jump = False
jump_counter = 30
cactus_width =20
cactus_height =70
cactus_x=800-50
cactus_y=600-100-70
class Cactus:
def __init__(self,x,y,width,height,speed):
self.x = x
self.y = y
self.width = width
self.height = height
self.speed = speed
def move(self):
if self.x >= -self.width:
pygame.draw.rect(display, (5, 149, 0), (self.x, self.y, self.width, self.height))
self.x -= self.speed
return True
else:
self.x = display_width + 100 + random.randrange(-80,60)
return False
def return_self(self,radius):
self.x = radius
def run_game():
global make_jump
game = True
cactus_arr =[]
create_cactus_arr(cactus_arr)
while game:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
key = pygame.key.get_pressed()
if key[pygame.K_SPACE]:
make_jump = True
if make_jump:
jump()
display.fill((4,192,232))
draw_array(cactus_arr)
pygame.draw.rect(display,(232,44,4),(usr_x,usr_y,usr_width,usr_height))
pygame.display.update()
clock.tick(80)
def jump():
global usr_y, make_jump, jump_counter
if jump_counter >= -30:
usr_y -= jump_counter/2.5
jump_counter -=1
else:
jump_counter = 30
make_jump = False
def create_cactus_arr(array):
array.append(Cactus(display_width+20,display_height-170,20,70,4))
array.append(Cactus(display_width+300,display_height-150,30,50,4))
array.append(Cactus(display_width+600,display_height-180,25,80,4))
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
choise = random.randrange(0,5)
if choise == 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)
cactus.return_self(radius)
run_game()