Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.6 kB
2
Indexable
Never
import pygame
pygame.init()

racket_x = 220
racket_y = 330

back = (123, 321, 213)
mw = pygame.display.set_mode((500, 500))
mw.fill(back)
clock = pygame.time.Clock()


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 = back

    def color(self, new_color):
        self.fill_color = new_color

    def fill(self):
        pygame.draw.rect(mw, self.fill_color, self.rect)

    def colliderect(self, x, y):
        return self.rect.colliderect(x, y)

    def colliderect(self, x, y):
        return self.rect.colliderect(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, color=None)


        self.image = pygame.image.load(filename)
    

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






ball = Picture('ball.png', 160, 200, 50, 50)
platform = Picture('platform.png', racket_x, racket_y, 100, 30)




start_x = 5
start_y = 5
count = 9 
monsters = []

for j in range(3):
    y = start_y + (55 * j)
    x = start_x + (27.5 * j)

    for i in range(count):
        d = Picture('enemy.png', x, y, 50, 50)
        monsters.append(d)
        x += 55
    count -= 1


game_over = False




while not game_over:
    ball.fill()
    platform.fill()



    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            game_over = True




    for m in monsters: 
        m.draw()
    
    platform.draw()
    ball.draw()
    pygame.display.update()
    clock.tick(40)
Leave a Comment