[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] update() weirdness



oh, and "if isinstance(item, Player):" might save you two lines, alternative use "if (isinstance(item, Player) or isinstance(item, Bullet)):" to let bullets kill each other.

Lizard

Rolf Sievers schrieb:
for item in obs: #go through all of the items in the supplied objects if (isinstance(item, Enemy) or isinstance(item, EnemyBullet)): # <- changed
           # if isinstance(item, Enemy):
               pass #don't do anything if it's an enemy
           else:
if item.rect.colliderect(self.rect): #has the item collided
               ######################################with the bullet's
               ######################################rect?
                   self.kill()
                   item.kill()

well, s.th. has collided with the bullets rect, what about ... the bullet itself? I changed it to check if it is colliding with an bullet, and that works a bit better ^_^.

You still have to do s.th. so that there won't be one bullet per frame, but you didn't asked about that bug too. Also: 30px per frame is a bit to fast.

Lizard

Yanom Mobis schrieb:
in the code i have attached, there seems to be some problem with the EnemyBullet.update() fuction, when you run the code you will get what i mean, hard to explain. i have attached my code.