|
|
@ -14,16 +14,17 @@ GREEN = (0, 255, 0) |
|
|
|
BLACK = (0, 0, 0) |
|
|
|
WHITE = (255, 255, 255) |
|
|
|
|
|
|
|
DISPLAYSURF = pygame.display.set_mode((400,600)) |
|
|
|
DISPLAYSURF = pygame.display.set_mode((600,600)) |
|
|
|
DISPLAYSURF.fill(WHITE) |
|
|
|
pygame.display.set_caption("Game") |
|
|
|
|
|
|
|
class Enemy(pygame.sprite.Sprite): |
|
|
|
def __init__(self): |
|
|
|
class Pumpkin(pygame.sprite.Sprite): |
|
|
|
def __init__(self, x, y): |
|
|
|
super().__init__() |
|
|
|
self.image = pygame.image.load("Enemy.png") |
|
|
|
self.image = pygame.image.load("pumpkin.png") |
|
|
|
self.rect = self.image.get_rect() |
|
|
|
self.rect.center=(random.randint(40,SCREEN_WIDTH-40),0) |
|
|
|
self.rect.center=(x,y) |
|
|
|
self.liv = 1 |
|
|
|
|
|
|
|
def move(self, player): |
|
|
|
self.rect.move_ip(0,10) |
|
|
@ -39,11 +40,11 @@ class Enemy(pygame.sprite.Sprite): |
|
|
|
|
|
|
|
|
|
|
|
class Player(pygame.sprite.Sprite): |
|
|
|
def __init__(self): |
|
|
|
def __init__(self, x, y): |
|
|
|
super().__init__() |
|
|
|
self.image = pygame.image.load("Player.png") |
|
|
|
self.image = pygame.image.load("ghost.png") |
|
|
|
self.rect = self.image.get_rect() |
|
|
|
self.rect.center = (160, 520) |
|
|
|
self.rect.center = (x, y) |
|
|
|
|
|
|
|
def update(self): |
|
|
|
pressed_keys = pygame.key.get_pressed() |
|
|
@ -66,20 +67,56 @@ class Player(pygame.sprite.Sprite): |
|
|
|
return self.rect.pos |
|
|
|
|
|
|
|
|
|
|
|
P1 = Player() |
|
|
|
E1 = Enemy() |
|
|
|
P1 = Player(185, 290) |
|
|
|
|
|
|
|
|
|
|
|
list_pumpkins = [Pumpkin(185, 290), Pumpkin(330, 290)] |
|
|
|
|
|
|
|
clicks = 0 |
|
|
|
|
|
|
|
mus_nede = 0 |
|
|
|
|
|
|
|
pygame.font.init() |
|
|
|
my_font = pygame.font.SysFont('Comic Sans MS', 30) |
|
|
|
text_surface = my_font.render('Clicks: ' + str(clicks), False, (255, 255, 255)) |
|
|
|
|
|
|
|
|
|
|
|
bg = pygame.image.load("bg.png") |
|
|
|
|
|
|
|
while True: |
|
|
|
if random.randint(1, 100) == 50: |
|
|
|
for pumpkin in list_pumpkins: |
|
|
|
pumpkin.liv = 1 |
|
|
|
for event in pygame.event.get(): |
|
|
|
if event.type == QUIT: |
|
|
|
pygame.quit() |
|
|
|
sys.exit() |
|
|
|
P1.update() |
|
|
|
E1.move(P1) |
|
|
|
#E1.move(P1) |
|
|
|
|
|
|
|
DISPLAYSURF.fill(WHITE) |
|
|
|
#DISPLAYSURF.fill(WHITE) |
|
|
|
DISPLAYSURF.blit(bg, (0, 0)) |
|
|
|
P1.draw(DISPLAYSURF) |
|
|
|
E1.draw(DISPLAYSURF) |
|
|
|
for pumpkin in list_pumpkins: |
|
|
|
if pumpkin.liv == 1: |
|
|
|
pumpkin.draw(DISPLAYSURF) |
|
|
|
|
|
|
|
DISPLAYSURF.blit(text_surface, (0,0)) |
|
|
|
|
|
|
|
if event.type == MOUSEBUTTONDOWN: |
|
|
|
mouse_pos = event.pos # Now it will have the coordinates of click point. |
|
|
|
print('Click') |
|
|
|
for pumpkin in list_pumpkins: |
|
|
|
if pumpkin.rect.collidepoint(mouse_pos): |
|
|
|
if pumpkin.liv == 1: |
|
|
|
pumpkin.liv = 0 |
|
|
|
if mus_nede == 0: |
|
|
|
mus_nede = 1 |
|
|
|
print('Touched') |
|
|
|
clicks = clicks + 1 |
|
|
|
text_surface = my_font.render('Clicks: ' + str(clicks), False, (255, 255, 255)) |
|
|
|
elif event.type == MOUSEBUTTONUP: |
|
|
|
mus_nede = 0 |
|
|
|
|
|
|
|
pygame.display.update() |
|
|
|
FramePerSec.tick(FPS) |