import pygame
import time
pygame.init()
BG_COLOR = (81, 203, 249)
mw = pygame.display.set_mode((500,500))
mw.fill(BG_COLOR)
clock = pygame.time.Clock()
class Area():
def init(self,x,y,height,width):
self.rect = pygame.Rect(x,y,height,width)
def fill(self):
pygame.draw.rect(mw, self.fill, self.rect)
def collidepoint(self, x, y,width,height):
return self.rect.collidepoint(x, y)
def colliderect(self,rect):
return self.rect.colliderect(rect)
def newcolor(self,new):
self.fill = new
self.draw()
class Picture(Area):
def init(self,filename,x,y,width,height):
self.image = pygame.image.load(filename)
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
mw.blit(self.image, (self.rect.x , self.rect.y ))
x_start = 5
y_start = 5
mons = []
n = 9
ball = Picture('ball.png', 160, 200, 50, 50)
platform = Picture('platform.png', 200, 330, 100, 30)
for j in range(3):
x = x_start + (27j)
y = y_start+(55j)
for i in range(n):
monster = Picture('enemy.png',x,y,50,50)
monster.draw()
mons.append(monster)
x +=55
n -= 1
ball.draw()
platform.draw()
speedx = 3
speedy = 3
quit = False
bx = 3
by = 3
pygame.display.update()
while not quit:
ball.rect.x += bx
ball.rect.y += by
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
platform.rect.x+=2
if event.key == pygame.K_LEFT:
platform.rect.x -=2
if ball.rect.x >=450 or ball.rect.x <= 0:
bx *= -1
if ball.rect.y <= 0:
by *= -1
if platform.colliderect(ball.rect):
by *= -1