def test_move(self): for param in ParamBallTest.TEST_VALUES: with self.subTest(param=param): x0, y0, x1, y1 = param b = Ball(x0, y0) b.move() self.assertTrue(b.rect() == (x1, y1, 20, 20))
def test_corner(self): b = Ball(300, 220) # dx = 5, dy = 5 b.move() self.assertTrue(b.rect() == (295, 215, 20, 20))
from p4_ball import Ball import pygame pygame.init() # Prepare pygame clock = pygame.time.Clock() # To set game speed screen = pygame.display.set_mode((Ball.ARENA_W, Ball.ARENA_H)) balls = [Ball(40, 80), Ball(80, 40)] playing = True while playing: for e in pygame.event.get(): # Handle events: mouse, keyb etc. if e.type == pygame.QUIT: playing = False screen.fill((255, 255, 255)) for b in balls: b.move() pygame.draw.rect(screen, (127, 127, 127), b.rect()) pygame.display.flip() # Surface ready, show it! clock.tick(30) # Delay to get 30 fps pygame.quit() # Close the window