def draw(): screen.clear() screen.fill(BCKG_COLOR) for i in range(LINES): for j in range(COLUMNS): screen.draw.filled_rect(bricks[i][j], colors[i][j]) screen.draw.filled_rect(pad, pad_color) ball.draw(screen)
def draw(): screen.clear() screen.fill(BCKG_COLOR) for i in range(LINES): for j in range(COLUMNS): if bricks[i][j] is not None: screen.draw.filled_rect(bricks[i][j], colors[i][j]) screen.draw.filled_rect(pad, pad_color) ball.draw(screen) screen.draw.text(f'Lives: {lives}', (10, 10))
def draw(): screen.clear() screen.fill(BCKG_COLOR) for i in range(LINES): for j in range(COLUMNS): if bricks[i][j] is not None: screen.draw.filled_rect(bricks[i][j], colors[i][j]) screen.draw.filled_rect(pad, pad_color) ball.draw(screen) # conteaza ordinea apelurilor; pentru ca textul e dupa bila, va ramane deasupra bilei screen.draw.text(f'Lives: {lives}', (10, 10))
def game_loop(): while True: display.fill((0, 0, 0)) maze.draw(display) ball.draw(display) ball.handle_input() ball.step(maze) pygame.display.update() clock.tick(60)
def draw(self, surface, pos: tuple, rect: pygame.Rect = None): """Отображает игровое поле со всеми шариками на экране :param surface: поверхность для отображения :param pos: координаты (x, y) левого верхнего угла поля в пикселях :param rect: зона поверхности для отображения """ pos_y = pos[1] dx = 38 dy = 38 if rect is None: rect = pygame.Rect(pos[0], pos[1], dx * self.length, dy * self.height) line_count = 0 for line in self.field: line_count += 1 if (line_count + self.__shift_count) % 2 == 1: pos_x = pos[0] else: pos_x = pos[0] + dx // 2 for ball in line: if ball is not None and rect.collidepoint((pos_x, pos_y)): ball.draw(surface, (pos_x, pos_y)) pos_x += dx pos_y += dy
def draw(): ball.draw(surface) player.draw(surface) cpu.draw(surface) draw_scores() draw_court()
new_ball = launcher.shoot() balls.append(new_ball) success = False ball_hist_coords = [] times = [] if keys[pygame.K_z]: break ph.fill_screen(screen, params.background_color) for ball_num in range(len(balls)): ball = balls[0] ready = ball.update() ball.draw(screen) if ready and not success: #ph.draw_circle(screen, (255,255,255), ph.world_coord_to_pixel_coord([ball.x_peak, ball.y_peak]), ball.radius) peak1 = ball.x_peak peak2 = ball.y_peak T_temp = np.array([[1, 0, 0, 0], [0, 1, 0, peak1], [0, 0, 1, peak2], [0, 0, 0, 1]]) thetas, success = robot.inverse_kinematics(T_temp, robot.thetas) if success: success_iter = 0 curr_thetas = np.array(robot.thetas) thetas = np.array(thetas)
# paddle.pixel_collision(cur_map.bricks, ball.shadow_ball_pos[0], ball.shadow_ball_pos[1], 5, ball.shadow_dir) paddle.pixel_collision(cur_map.bricks, ball.position[0], ball.position[1], 5, ball.direction) paddle.collide() text = font.render(("Score: " + str(paddle.score)), True, (255, 255, 255)) win.fill((0, 0, 0)) win.blit(bachground, (0, 0)) win.blit(text, (0, 770)) bachground.blit(background, (0, 0)) game_ui.draw_return() game_ui.draw_return_hov() paddle.draw() ball.draw() ball.move(dt) ball.collision(paddle.position, mPos, paddle.stamina) cur_map.render(win, grid_color=None) ball.power(dt, paddle.position, paddle.stamina, mClick) if attk_exists == False: attk_timer -= 1 * dt attk_type = 0 if attk_timer <= 0: a = random.randint(1, 5) b = random.randint(1, 5) if health <= (health / 2): attk_type = random.randint(1, 10) else: attk_type = a + b
block.Block(x, blockHeight * (y + 1) + offset, blockWidth, blockHeight)) # Sets graphical components of display window pygame.init() pygame.display.set_caption("Blockbreaker") window = pygame.display.set_mode([width, height]) window.fill(backgroundColor) FPSClock = pygame.time.Clock() FPS = 60 gameOver = False print(len(blocks)) while not gameOver: for event in pygame.event.get(): if event.type == pygame.QUIT: gameOver = True window.fill(backgroundColor) ball.draw(window) user.draw(window) user.move(pygame.mouse.get_pos()[0]) #window.display.flip() for i in range(len(blocks)): blocks[i].draw(window) pygame.display.update() FPSClock.tick(FPS) fps = pygame.time.Clock()