TypeError: 'int' object is not callable (Pygame)

ship228background img

import pygame
import random as rnd
from random import randint, randrange

pygame.init()
pygame.display.set_caption('Final Project')
WIDTH, HEIGHT = 800, 400
SIZE = 128
screen = pygame.display.set_mode((WIDTH, HEIGHT))
bg_img = pygame.image.load('228.jpg')

clock = pygame.time.Clock()


class Ship:
    def __init__(self, color, x, y, keysList):
        self.color = color
        self.ship = pg.Rect(x, y, w, h)
        self.speed = 15
        self.rect = pg.Rect(x, y, SIZE, SIZE)
        self.keyUP = keysList[2]
        self.keyDOWN = keysList[3]
Ship228 = Ship (HEIGHT / 2 - SIZE (pygame.K_UP, pygame.K_DOWN))
ship_img = pygame.image.load('ship228.png')




block_x = WIDTH - 50
block_y = HEIGHT // 2
block_speed = 10
asteroidslist = list()





run = True
for i in range(5):
    asteroids = pygame.Rect(randint(1000, 2000), randint(0, HEIGHT - 50), 25, 25)
    asteroidslist.append(asteroids)


while run:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
    screen.blit(bg_img, (0, 0))
    key = pygame.key.get_pressed()
    if key[pygame.K_w] and ship.y > 0:
        ship.y -= ship_speed
    if key[pygame.K_s] and ship.y < HEIGHT - ship_h:
        ship.y += ship_speed

    for x in (asteroidslist):
        pygame.draw.rect(screen, 'red', x)
        x.x -= 10
        if x.x < 0 - 25:
            x.x, x.y = (rnd.randint(1000, 2000)), (rnd.randint(0, HEIGHT - 50))
        # if pygame.sprite.collide_rect(ship, asteroids):
            if rect.colliderect(ship, asteroids):
                run = False



    screen.blit(ship_img, ship.rect)
    clock.tick(60)


    pygame.display.update()

Ответы (1 шт):

Автор решения: CrazyElf
SIZE = 128
...
Ship228 = Ship (WIDTH / 2 - SIZE (pygame.K_UP, pygame.K_DOWN))
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Вы пытаетесь целочисленную переменную SIZE использовать как функцию.

Я не смог догадаться из контекста, что вы хотели тут сделать и как это можно исправить.

→ Ссылка