import pygame
import sys
pygame.init()
WIDTH, HEIGHT = 200, 400
window = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Pygame Animation")
BACKGROUND_COLOR = [105, 177, 245]
RED = (255, 0, 0)
object_width, object_height = 50, 50
object_x = WIDTH // 2 - object_width // 2
object_y = HEIGHT - object_height
FPS = 30
SPEED = 15
clock = pygame.time.Clock()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
object_y -= SPEED
if object_y < -object_height:
object_y = HEIGHT
window.fill(BACKGROUND_COLOR)
pygame.draw.rect(window, RED, (object_x, object_y, object_width, object_height))
pygame.display.flip()
clock.tick(FPS)
pygame.quit()
sys.exit()
Цвет: [105, 177, 245]
Параметры объекта:
Цвет: красный
Размер: (50, 50)
Стартовая позиция: самый низ окна по центру
Анимация
FPS = 30
Скорость = 15
Примечания
Помните про направление оси Y