diff --git a/Enemy.png b/Enemy.png new file mode 100644 index 0000000..e1198ed Binary files /dev/null and b/Enemy.png differ diff --git a/Player.png b/Player.png new file mode 100644 index 0000000..6901e4b Binary files /dev/null and b/Player.png differ diff --git a/bg.png b/bg.png new file mode 100644 index 0000000..7a7edf8 Binary files /dev/null and b/bg.png differ diff --git a/game.py b/game.py index ffa6d31..0b5a67e 100644 --- a/game.py +++ b/game.py @@ -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) - - DISPLAYSURF.fill(WHITE) + #E1.move(P1) + + #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) \ No newline at end of file diff --git a/ghost.png b/ghost.png new file mode 100644 index 0000000..2b703ee Binary files /dev/null and b/ghost.png differ diff --git a/pumpkin.png b/pumpkin.png new file mode 100644 index 0000000..f4296cb Binary files /dev/null and b/pumpkin.png differ