Untitled

Anonymous
plain_text
01/29/2026 7:04 PM
2.7 KB
12
Indexable
import pygame

pygame.init()

FPS = 60
WINDOW_HEIGHT = 500
WINDOW_WEIDTH = 500

BACKGROUND_COLOR = (0, 150, 160)



window = pygame.display.set_mode((WINDOW_WEIDTH, WINDOW_HEIGHT))



class Area():
    def __init__(self, x=0, y=0, width=10, height=10, color=None):
        self.rect = pygame.Rect(x, y, width, height)
        self.fill_color = color

    def color(self, new_color): #встановлюємо колір
        self.fill_color = new_color

    def fill(self): #відмальовуємо прямокутник на екрані
        pygame.draw.rect(mw, self.fill_color, self.rect)


class Picture(Area):
    def __init__(self,x, y, width, height, color, filename):
        super().__init__(x, y, width, height, color)
        self.image = pygame.image.load(filename)

    def draw(self):
        window.blit(self.image, (self.rect.x, self.rect.y))

platform = Picture(220, 430, 40,10, None, filename = "platform.png")

monsters = []
n = 9
x_start = 5
y_start = 5
for i in range(3):
    x = x_start + (27 * i)
    y = y_start + (55 * i)
    for j in range(n):
        enemy = Picture(x, y, 50, 50,None,"enemy.png")
        monsters.append(enemy)
        x += 55
    n -= 1

game_over = False
move_right = False
move_left = False

clock = pygame.time.Clock()

while not game_over:

    for e in pygame.event.get():
        if e.type == pygame.KEYDOWN:
            if e.key == pygame.K_d:
                move_right = True
            if e.key == pygame.K_a:
                move_left = True

        if e.type == pygame.KEYUP:
            if e.key == pygame.K_d:
                move_right = False
            if e.key == pygame.K_a:
                move_left = False

    if move_right == True:
        platform.rect.x += 3

    if move_left == True:
        platform.rect.x -= 3

    window.fill(BACKGROUND_COLOR)
    platform.draw()



    for m in monsters:
        m.draw()


    clock.tick(FPS)
    pygame.display.update()


Editor is loading...
Leave a Comment