0

I started making a pygame prototype. Every 30 frames should be spawned squares on random position. Then, after clicking the square with your cursor, the square should disappear and you will get one point. I was able to do the generator of squares, but I am stuck with the clicking-and disappearing. I tried using self.kill() method in update() method, but for some reason it didn't work with my cursor collision detection. Can you please help? If you can, please send full code, it is possible that I have some stupid errors in my project that I didn't notice. Thanks! Code:

import pygame
pygame.init()
screen=pygame.display.set_mode((800,600))
class Enemy(pygame.sprite.Sprite):
    def __init__(self,x,y):
        super().__init__()
        self.image=pygame.Surface((10,10))
        self.image.fill('Yellow')
        self.rect=self.image.get_rect(topleft=(x,y))
    def update(self):
        self.remove(enemy)
        return 0
enemy=pygame.sprite.Group()
enemy.add(Enemy(1,1))
pygame.display.update()
enemy.draw(screen)
while True:
    pygame.display.update()
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
            exit()

    enemy.update()
lasermtv
  • 1
  • 2

1 Answers1

0

I have an idea. You just move the sprite out the screen like pygame.draw.rect(9999,9999,width,height) Or you can fill screen? I have not yet.

Newbie
  • 23
  • 4