dirとspeedの引数をball = Ball(ball_color, ball_rect, 320, 10)と合わせたいのですがどうすればいいでしょう
import sys import pygame import math from pygame.locals import QUIT from pygame.locals import Rect pygame.init() SURFACE = pygame.display.set_mode((400,300)) FPSCLOCK = pygame.time.Clock() class Block: def __init__(self, color, rect): self.color = color self.rect = rect def draw(self): pygame.draw.rect(SURFACE, self.color, self.rect) class Ball: def __init__(self, color, rect): self.color = color self.rect = rect self.dir = 320 def draw(self): pygame.draw.ellipse(SURFACE, self.color, self.rect) def move(self): speed = 10 if rect.centerx < 0 or rect.centerx > 400: self.dir = 180-self.dir if rect.centery < 0 or rect.centery > 300: self.dir = -self.dir self.rect.centerx += math.cos(math.radians(self.dir))*speed self.rect.centery -= math.sin(math.radians(self.dir))*speed left = 50 top = 50 width = 45 height = 20 block_color = (200, 50, 200) block_rect = Rect(left, top, width, height) block = Block(block_color, block_rect) ball_rect = Rect(150,100,10,10) ball_color = (255,255,0) ball = Ball(ball_color, ball_rect, 320, 10) while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() SURFACE.fill((0,0,0)) ball.move() block.draw() ball.draw() if ball.rect.colliderect(block.rect)==True: print("衝突した") pygame.display.update() FPSCLOCK.tick(30) コード
colliderect.txt", line 52, in <module>
ball = Ball(ball_color, ball_rect, 320, 10)
TypeError: init() takes 3 positional arguments but 5 were given
回答1件
あなたの回答
tips
プレビュー