pumpkin in the working
This commit is contained in:
1 parent
d9856bea34
commit
2be4e5b7fd
6 files changed
+52
-15
No files matched your search
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
@@ -14,16 +14,17 @@ GREEN = (0, 255, 0)
|
|||||||
BLACK = (0, 0, 0)
|
BLACK = (0, 0, 0)
|
||||||
WHITE = (255, 255, 255)
|
WHITE = (255, 255, 255)
|
||||||
|
|
||||||
DISPLAYSURF = pygame.display.set_mode((400,600))
|
DISPLAYSURF = pygame.display.set_mode((600,600))
|
||||||
DISPLAYSURF.fill(WHITE)
|
DISPLAYSURF.fill(WHITE)
|
||||||
pygame.display.set_caption("Game")
|
pygame.display.set_caption("Game")
|
||||||
|
|
||||||
class Enemy(pygame.sprite.Sprite):
|
class Pumpkin(pygame.sprite.Sprite):
|
||||||
def __init__(self):
|
def __init__(self, x, y):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.image = pygame.image.load("Enemy.png")
|
self.image = pygame.image.load("pumpkin.png")
|
||||||
self.rect = self.image.get_rect()
|
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):
|
def move(self, player):
|
||||||
self.rect.move_ip(0,10)
|
self.rect.move_ip(0,10)
|
||||||
@@ -39,11 +40,11 @@ class Enemy(pygame.sprite.Sprite):
|
|||||||
|
|
||||||
|
|
||||||
class Player(pygame.sprite.Sprite):
|
class Player(pygame.sprite.Sprite):
|
||||||
def __init__(self):
|
def __init__(self, x, y):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.image = pygame.image.load("Player.png")
|
self.image = pygame.image.load("ghost.png")
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.rect.center = (160, 520)
|
self.rect.center = (x, y)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
pressed_keys = pygame.key.get_pressed()
|
pressed_keys = pygame.key.get_pressed()
|
||||||
@@ -66,20 +67,56 @@ class Player(pygame.sprite.Sprite):
|
|||||||
return self.rect.pos
|
return self.rect.pos
|
||||||
|
|
||||||
|
|
||||||
P1 = Player()
|
P1 = Player(185, 290)
|
||||||
E1 = Enemy()
|
|
||||||
|
|
||||||
|
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:
|
while True:
|
||||||
|
if random.randint(1, 100) == 50:
|
||||||
|
for pumpkin in list_pumpkins:
|
||||||
|
pumpkin.liv = 1
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == QUIT:
|
if event.type == QUIT:
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
P1.update()
|
P1.update()
|
||||||
E1.move(P1)
|
#E1.move(P1)
|
||||||
|
|
||||||
DISPLAYSURF.fill(WHITE)
|
#DISPLAYSURF.fill(WHITE)
|
||||||
|
DISPLAYSURF.blit(bg, (0, 0))
|
||||||
P1.draw(DISPLAYSURF)
|
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()
|
pygame.display.update()
|
||||||
FramePerSec.tick(FPS)
|
FramePerSec.tick(FPS)
|
||||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Reference in new issue
Block a user