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

Re: [pygame] update() weirdness



makes sense now



From: Rolf Sievers <rolf.sievers@xxxxxxxx>
To: pygame-users@xxxxxxxx
Sent: Wednesday, June 17, 2009 2:18:47 PM
Subject: Re: [pygame] update() weirdness

Sorry for spamming the mailing list, maybe i should thing a bit longer before posting...

1) I forgot to describe the actually problem to you, just in case you didn't yet figured that out by my previous posts:
whenever a bullet is created, it immediately kills itself the next frame, because you check against everything on the screen, including the bullet itself which will always collide with itself.
Every frame a new bullet is created at the same position as the ship, which creates the impression of the bullet traveling with the same speed as the spaceship - which isn't the case.

2) you might want to use a debugger to figure out such problems yourself or, for trivial problems like this one, use "print 'Bullet got destroyed'"-like debug output. Adding that line into your code made me figure out the problem without problems.

Lizard
(fucking "itself" repetition, my limited vocabulary sounds so weired)

Rolf Sievers schrieb:
> 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.
>>>