Вопрос задан 23.10.2023 в 03:38. Предмет Информатика. Спрашивает Ивасенко Саша.

Python import time import pygame pygame.init() mw = pygame.display.set_mode((500,500)) background

= (200,255,255) mw.fill(background) abc = (255,255,255) clock = pygame.time.Clock() game_over = False rect_x = 200 rect_y = 330 move = "" speed_x=5 speed_y=5 class Area(): def init(self,x=0,y=0,width=10,height=10,color1 = None): self.rect = pygame.Rect(x,y,width,height) self.fill_color = background if color1: self.fill_color = color1 def color(self,abc): self.fill_color = abc def fill(self): pygame.draw.rect(mw,self.fill_color ,self.rect) class Picture(Area): def init(self,filename,x=0,y=0,width=10,height=10): Area.init(self,x=x,y=y,width=width,height=height,color1 = None) self.image = pygame.image.load(filename) def draw(self,shift_x = 0,shift_y = 0): self.fill() mw.blit(self.image,(self.rect.x + shift_x, self.rect.y + shift_y)) class Label(Area): def set_text(self,text,fsize = 12, text_color = (255,255,255)): self.text = text self.image = pygame.font.Font(None,fsize).render(text,True,text_color) def draw(self,shift_x = 0,shift_y = 0): pygame.draw.rect(mw,self.fill_color,self.rect) mw.blit(self.image,(self.rect.x + shift_x,self.rect.y + shift_y)) ball = Picture("ball.png",160,200,50,50) platform = Picture("platform.png",rect_x,rect_y,100,30) enemies = [] default_x = 5 default_y = 5 enemies_count1 = 9 for k in range(3): x = default_x+(27*k) y = default_y+(55*k) for i in range(enemies_count1): enemy = Picture("enemy.png",x,y,50,50) enemies.append(enemy) x += 55 enemies_count1 -= 1 lvl = 1 while not game_over: ball.fill() platform.fill() for event in pygame.event.get(): if event.type == pygame.QUIT: game_over = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_a: move = "left" if event.key == pygame.K_d: move = "right" if event.type == pygame.KEYUP: move = "" if move == "left" and platform.rect.x > 0: platform.rect.x = platform.rect.x - 15 if move == "right" and platform.rect.x < 500-platform.rect.width: platform.rect.x = platform.rect.x + 15 for enemy in enemies: enemy.draw() if enemy.rect.colliderect(ball.rect): enemies.remove(enemy) enemy.fill() speed_y *= -1 ball.rect.x += speed_x ball.rect.y += speed_y if ball.rect.x < 0 or ball.rect.x >500 - ball.rect.width: speed_x *= -1 if ball.rect.y<0: speed_y *= -1 if ball.rect.colliderect(platform.rect): speed_y *= -1 if ball.rect.y > rect_y - 10: lose_text = Label(150,150,50,50,background) lose_text.set_text("YOU LOSE",60,text_color = (255,0,0)) lose_text.draw(10,10) game_over = True if len(enemies) == 0: win_text = Label(150,150,50,50,background) win_text.set_text("YOU WIN",60,text_color = (0,200,0)) win_text.draw(10,10) speed_x += 5 speed_y += 5 if lvl == 1: default_x1 = 5 default_y1 = 5 ball.rect.x = 160 ball.rect.y = 200 enemies_count1 = 14 for j in range(3): x1 = default_x1+(27*j) y1 = default_y1+(55*j) for i in range(enemies_count1): enemy = Picture("enemy.png",x1,y1,50,50) enemies.append(enemy) x1 += 55 enemies_count1 -= 1 lvl += 1 ball.draw() platform.draw() pygame.display.update() clock.tick(60)потрібно доробити код на пайтоні а точніше ускладнити ось список що потрібно зробити 1.сделать уровни(4)2.сделать что бы на втором и тд уровне появлялся второй шарик когда первый шарик попадает в одного из enemies на рандом3.кнопку пауза4.меню. самое банальное типа играть и закончитьі виправити помилку в коді
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Григорьева Марина.

Ответ:

Нужно приложить немного старания.

Объяснение:

Щоб ускладнити код та додати вказані функціональності, вам знадобиться багато змін. Ось список кроків, які вам потрібно виконати:

1. Створіть змінну 'level', яка початково має значення 1. Використовуйте цю змінну, щоб налаштувати кількість ворогів на кожному рівні.

2. Створіть змінну 'ball2', яка буде представляти другий м'ячик. Зробіть так, щоб на початку кожного рівня 'ball2' з'являвся, коли перший м'ячик зіштовхується з ворогом на випадковому місці. Наприклад, ви можете створити нову функцію 'spawn_ball2', яка генерує випадкові координати для 'ball2' і додає його до списку м'ячиків.

3. Створіть кнопку 'Пауза'. Додайте змінну 'paused', яка початково має значення False. Використовуйте цю змінну для призупинки руху м'ячиків і платформи, коли гра в паузі. Зробіть кнопку 'пауза' активною, коли гра запущена, і натисніть на неї, щоб змінити значення змінної 'paused'. У циклі гри додайте перевірку на зупинку руху, якщо 'paused' дорівнює True.

4. Створіть головне меню гри. Розмістіть головне меню в окремому циклі, що запускається під час запуску гри. Встановіть початкові значення змінних та привітання. Перевіряйте події в головному меню, щоб перевести користувача в ігровий цикл або закрити гру.

5. Виправте помилку в коді. Ви не вклали цикл "for enemy in enemies" всередину циклу "while not game_over", через що можна втратити функціональність рухомих ворогів.

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

It seems like you've posted a Python code that appears to be a basic game implemented using the Pygame library. The game involves a ball, a platform, and enemies. Players control the platform to bounce the ball and eliminate the enemies. The code you provided seems to be incomplete as it ends abruptly. Below is a summary of the code structure and what it does:

  1. Import necessary libraries and initialize Pygame.
  2. Create a game window with a blue background.
  3. Define classes for game objects: Area, Picture, and Label. These classes are used for creating rectangles, images, and labels on the game screen.
  4. Create instances of game objects, including a ball, platform, and a list of enemy objects.
  5. Implement the game loop using a while loop. The loop handles user input, collision detection, and updates the game objects' positions.
  6. Check for user input to move the platform left or right using the arrow keys.
  7. Check for collisions between the ball, the platform, and enemies. Remove enemies when they collide with the ball.
  8. Display "YOU LOSE" when the ball reaches the bottom of the screen, and "YOU WIN" when all enemies are eliminated.
  9. Increase the speed of the ball and add more enemies as the player progresses to higher levels.

However, the code provided is missing the ending part, especially the part that handles Pygame events and the game display update, which is essential to keep the game running.

If you have any specific questions or need assistance with a particular aspect of this code, please let me know, and I'd be happy to help.

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос