import pygame import sys pygame.init() fpsClock = pygame.time.Clock() screen =…
- User
import pygame import sys
pygame.init() fpsClock = pygame.time.Clock() screen = pygame.display.set_mode((640, 480)) ball = pygame.image.load("ball_soccer.png") rect = ball.get_rect()
while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit()
coderect = rect.move([5, 5]) screen.fill((100, 100, 100)) screen.blit(ball, rect) pygame.display.update() fpsClock.tick(50)game = Game() game.addBall(Ball("ball_soccer.png", [0, 0], [5, 5])) game.addBall(Ball("ball_basketball.png", [100, 200], [-4, 4])) game.addBall(Ball("ball_volleyball.png", [200, 50], [8, -8])) game.start() Ćwiczenie polega na utworzeniu animacji trzech piłek, które odbijają się od krawędzi okna o rozmiarze 640 x 480 pikseli. Poniżej tabela z danymi (rozmiar, pozycja początkowa, prędkość) i grafikami piłek do pobrania: Nazwa (link) ball_soccer.png ball_volleyball.png ball_basketball.png Grafika Rozmiar grafiki (px) 100 x 100 90 x 90 120 x 120 Pozycja początkowa x: 0, y: 0 x: 100, y: 200 x: 200, y: 50 Prędkość dx: 5, dy: 5 dx: -4, dy: 4 dx: 8, dy: -8
- Assistant
- User
Ball("ball_soccer.png", [0, 0], [5, 5]), TypeError: Ball() takes no arguments
- Assistant
It appears there is an oversight in translating the design into a runnable code. This error suggests that the Python interpreter expects the
Ballclass not to take any arguments upon instantiation, which conflicts with the provided implementation because it's trying to pass arguments (image path, position, and velocity) toBallconstructor.Such an issue could arise if the
__init__method within the class is not correctly defined or if there's another error in the class definition that causes Python not to recognize the method properly. However, in the provided code, the method is correctly defined in the class. - User
da sie prosciej tamto zadanie i krocej?
- Assistant
Tak, można zrobić to zadanie w prostszy i krótszy sposób, chociaż przedstawiona wcześniej wersja jest już dość zoptymalizowana pod kątem obiektowości i łatwości rozbudowy. Jeśli chodzi o minimalizację kodu, można zrezygnować z definicji klasy
Balli zarządzać piłkami bezpośrednio w głównej pętli gry. Oto uproszczona wersja: