В полном тупике, __init__() missing 1 required positional argument
При нажатии на кнопку L Ctrl выбрасывает ошибку. Вроде бы правильно передаю параметры, в чем причина? Понимаю что закидаете помидорами, но подскажите в какую сторону думать.
File "C:/Users/Andrei/PycharmProjects/educational-tasks/Funny_сrab/funny_crab.py", line 81, in <module>
shells.append(ammo((round(position_x + widht_object // 2), round(position_y + height_object // 2)), 5, (0, 0, 0), orient))
TypeError: __init__() missing 1 required positional argument: 'orient'
Код:
import pygame
pygame.init()
window_width = 768
window_height = 600
widht_object = 64
height_object = 64
speed_object = 2
isJump = False
jump_count = 8
move_object = False
animCount = 0
last_move = True
shells = []
position_x = (window_width - widht_object)
position_y = window_height - height_object
fps = pygame.time.Clock()
win = pygame.display.set_mode((window_width, window_height))
pygame.display.set_caption("Funny crab")
walk_object = [pygame.image.load('files/crabs-1.png.png'), pygame.image.load('files/crabs-2.png.png'),
pygame.image.load('files/crabs-3.png.png'), pygame.image.load('files/crabs-4.png.png'),
pygame.image.load('files/crabs-5.png.png'), pygame.image.load('files/crabs-6.png.png'),
pygame.image.load('files/crabs-7.png.png'), pygame.image.load('files/crabs-8.png.png'),
pygame.image.load('files/crabs-9.png.png'), pygame.image.load('files/crabs-10.png.png'),
pygame.image.load('files/crabs-11.png.png'), pygame.image.load('files/crabs-12.png.png'),
pygame.image.load('files/crabs-13.png.png'), pygame.image.load('files/crabs-14.png.png')]
objectStand = pygame.image.load('files/crabs-1.png.png')
background = pygame.image.load('files/background.png')
class ammo():
def __init__(self, x, y, radius, color, orient):
self.x = x
self.y = y
self.radius = radius
self.color = color
self.orient = orient
self.velocity = 5 * orient
def draw(self, win):
pygame.draw.circle(win, self.color, (self.x, self.y), self.radius)
def draw_window():
global animCount
win.blit(pygame.transform.scale(background, (window_width, window_height)), (0, 0))
if animCount + 1 >= 60:
animCount = 0
if move_left:
win.blit(pygame.transform.scale(walk_object[animCount // 5], (64, 64)), (position_x, position_y))
animCount += 1
elif move_right:
win.blit(pygame.transform.scale(walk_object[animCount // 5], (64, 64)), (position_x, position_y))
animCount += 1
else:
win.blit(pygame.transform.scale(objectStand, (64, 64)), (position_x, position_y))
for shell in shells:
shell.draw(win)
pygame.display.update()
run = True
while run:
fps.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
for shell in shells:
if 0 < shell.x < window_width:
shell.x += shell.velocity
else:
shells.pop(shells.index(shell))
keys = pygame.key.get_pressed()
if keys[pygame.K_RCTRL]:
if last_move == True:
orient = 1
else:
orient = -1
if len(shells) <= 3:
shells.append(ammo((round(position_x + widht_object // 2), round(position_y + height_object // 2)), 5, (0, 0, 0), orient))
if keys[pygame.K_LEFT] and position_x > 0:
position_x -= speed_object
move_left = True
move_right = False
last_move = False
elif keys[pygame.K_RIGHT] and position_x < (window_width - widht_object):
position_x += speed_object
move_left = False
move_right = True
last_move = True
else:
move_left = False
move_right = False
animCount = 0
if not (isJump):
if keys[pygame.K_SPACE]:
isJump = True
else:
if jump_count >= -8:
if jump_count < 0:
position_y += (jump_count ** 2) / 2
else:
position_y -= (jump_count ** 2) / 2
jump_count -= 1
else:
isJump = False
jump_count = 8
draw_window()
pygame.quit()```
Ответы (1 шт):
Автор решения: x3wgs
→ Ссылка
shells.append(ammo(**(**round(position_x + widht_object // 2), round(position_y + height_object // 2)**)**, 5, (0, 0, 0), orient))
Лишние скобки были. Поэтому передавал меньше элементов